Website Summary Files Commits Branches @commit @diff @stats
path: root / homework / 81248 / clex / test / Clex / LexSpec.hs
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/LexSpec.hs
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.tar.gz
IPL-aeb0d4f887a0c18c36b59acc7b5df08e62020c50.zip
Parent154b7cd30f21af1554ca26986ff1643e28857727 (diff)
Removed old homeworks
1 files changed, 0 insertions, 58 deletions
-rw-r--r--homework/81248/clex/test/Clex/LexSpec.hs58
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