Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81248 / clex / test / Clex
diff options
context:
space:
mode:
Commitaeb0d4f887a0c18c36b59acc7b5df08e62020c50 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:32:48 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2020-10-11 21:33:38 +0300
Filesb6abdc6e1810326b587f2a160f39570f1f568f27 /homework/81248/clex/test/Clex
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar.gz
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.zip
Parent154b7cd30f21af1554ca26986ff1643e28857727 (diff)
Removed old homeworks
2 files changed, 0 insertions, 235 deletions
-rw-r--r--homework/81248/clex/test/Clex/LexSpec.hs58
-rw-r--r--homework/81248/clex/test/Clex/TypesSpec.hs177
diff --git a/homework/81248/clex/test/Clex/LexSpec.hs b/homework/81248/clex/test/Clex/LexSpec.hs
deleted file mode 100644
index c5fec81..0000000
--- a/homework/81248/clex/test/Clex/LexSpec.hs
+++ /dev/null
@@ -1,58 +0,0 @@
-module Clex.LexSpec
- ( spec
- ) where
-
-import qualified Data.ByteString as BS
-import Data.ByteString (ByteString)
-import Data.ByteString.Char8 (pack)
-
-import Clex.Types
-import Clex.Lex (lexC)
-
-import Test.QuickCheck
-import Test.Hspec
-import Test.Hspec.QuickCheck
-import Clex.TypesSpec ()
-
-spec :: Spec
-spec = describe "lexing" $ do
- prop "tokensToBS after lexC is id" $
- \x -> let x' = unValidC x in
- case lexC x' of
- (Left _) -> False
- (Right x'') -> x' == tokensToBS x''
- prop "lexing after tokensToBS is id" $
- \x -> let x' = unTokenC x in
- case lexC $ tokensToBS x' of
- (Left _) -> False
- (Right x'') -> x' == x''
-
-newtype TokenC = TokenC {unTokenC :: [Token]}
- deriving (Eq, Show)
-
-newtype ValidC = ValidC {unValidC :: ByteString}
- deriving (Eq, Show)
-
-instance Arbitrary TokenC where
- arbitrary = TokenC . packWhitespaceTokens . concat <$>
- listOf1 (do
- x <- arbitrary
- whitespace <- whitespaceGen
- pure [x, whitespace])
- where
- whitespaceGen = Whitespace . pack <$> do listOf1 $ elements ['\t', ' ', '\n']
-
-instance Arbitrary ValidC where
- arbitrary = ValidC . BS.concat . map tokenToBS <$> listOf1 (frequency
- [ (30, arbitrary)
- , (60, whitespaceGen)
- ])
- where
- whitespaceGen = Whitespace . pack <$> do listOf1 $ elements ['\t', ' ', '\n']
-
-packWhitespaceTokens :: [Token] -> [Token]
-packWhitespaceTokens [] = []
-packWhitespaceTokens [x] = [x]
-packWhitespaceTokens (Whitespace x : Whitespace y : xs)
- = packWhitespaceTokens $ Whitespace (x <> y) : xs
-packWhitespaceTokens (x:xs) = x : packWhitespaceTokens xs
diff --git a/homework/81248/clex/test/Clex/TypesSpec.hs b/homework/81248/clex/test/Clex/TypesSpec.hs
deleted file mode 100644
index 805affc..0000000
--- a/homework/81248/clex/test/Clex/TypesSpec.hs
+++ /dev/null
@@ -1,177 +0,0 @@
-{-# LANGUAGE OverloadedStrings #-}
-{-# OPTIONS -fno-warn-orphans #-}
-
-module Clex.TypesSpec
- ( spec
- ) where
-
-import Data.ByteString.Char8 (pack)
-
-import Clex.Types
-
-import Test.QuickCheck
-import Test.Hspec
-import Test.Hspec.QuickCheck
-import Data.ByteString.Arbitrary
-
-spec :: Spec
-spec = describe "types"
- conversionSpec
-
-conversionSpec :: Spec
-conversionSpec = describe "ByteString conversions" $ do
- prop "recognize is inverse to tokenToBS" $
- \x -> (not . isLiteral) x ==> x == recognize (tokenToBS x)
- prop "tokenToBS is inverse to recognize" $
- \x -> let x' = fromABS x in x' == tokenToBS (recognize x')
-
-isLiteral :: Token -> Bool
-isLiteral (HexNumber _) = True
-isLiteral (OctNumber _) = True
-isLiteral (Number _) = True
-isLiteral (CharLit _) = True
-isLiteral (Scientific _) = True
-isLiteral (DotFloat _) = True
-isLiteral (LeadingDot _) = True
-isLiteral (StringLit _) = True
-isLiteral _ = False
-
-instance Arbitrary Token where
- arbitrary = frequency
- [ (30, nullaryGen)
- , (30, identifierGen)
- , (10, literalGen)
- ]
- where
- nullaryGen = elements
- [ Auto
- , Break
- , Case
- , Char
- , Const
- , Continue
- , Default
- , Do
- , Double
- , Else
- , Enum
- , Extern
- , Float
- , For
- , Goto
- , If
- , Int
- , Long
- , Register
- , Return
- , Short
- , Signed
- , Sizeof
- , Static
- , Struct
- , Switch
- , Typedef
- , Union
- , Unsigned
- , Void
- , Volatile
- , While
- , Ellipsis
- , RightShiftAssign
- , LeftShiftAssign
- , AddAssign
- , SubAssign
- , MulAssign
- , DivAssign
- , ModAssign
- , AndAssign
- , XorAssign
- , OrAssign
- , Incr
- , Decr
- , Ptr
- , Dot
- , And
- , Or
- , Not
- , LtEq
- , GtEq
- , Eq
- , NEq
- , Lt
- , Gt
- , Semicolon
- , LeftCurly
- , RightCurly
- , Comma
- , Colon
- , Assign
- , LeftBracket
- , RightBracket
- , LeftSquare
- , RightSquare
- , RightShift
- , LeftShift
- , BitAnd
- , BitOr
- , BitNot
- , Sub
- , Add
- , Mul
- , Div
- , Mod
- , Xor
- , Ternary
- ]
- identifierGen = Identifier <$> (pack <$> do listOf1 $ elements $ '_' : ['a'..'z'] ++ ['A'..'Z'])
- `suchThat` (not . reserved)
- reserved = (`elem` allKeyWords)
- -- don't feel like overdoing this right now
- literalGen = oneof
- [ elements
- [ HexNumber "0xb23abcf4"
- , HexNumber "0x123ab5f4ul"
- , HexNumber "0X123a4cf4"
- , HexNumber "0x1e3ebcf4lull"
-
- , OctNumber "0234"
- , OctNumber "012354ul"
- , OctNumber "012744"
- , OctNumber "0134lull"
-
- , Number "234"
- , Number "12354ul"
- , Number "12744"
- , Number "134lull"
- ]
- , elements
- [ CharLit "'c'"
- , CharLit "L'c'"
- , CharLit "'\n'"
- , CharLit "'\t'"
- , CharLit "'a'"
- ]
- , elements
- [ DotFloat ".213E+10f"
- , DotFloat ".213e-10"
- , DotFloat ".213e-10l"
- , DotFloat ".213e10l"
- , DotFloat ".213l"
- , DotFloat ".213"
- , DotFloat ".213e9L"
-
- , LeadingDot "213.2E+10f"
- , LeadingDot "213.3e-10"
- , LeadingDot "213.e-10l"
- , LeadingDot "213.e10l"
- , LeadingDot "213.e9L"
- , LeadingDot "213.9L"
- , LeadingDot "213.L"
- ]
- , elements
- [ StringLit "\"\""
- , StringLit "L\"asdfwqe\""
- , StringLit "\"asd\nfw\tqe\""
- , StringLit "L\"\""
- ]
- ]