diff options
Предаване на първо домашно ("XXX2html") (#12)
* Initial commit of clex
new file: .gitignore
new file: Setup.hs
new file: app/Main.hs
new file: keyword-strings.txt
new file: package.yaml
new file: sample.c
new file: src/Boilerplate.hs
new file: src/Lex.hs
new file: src/Lib.hs
new file: stack.yaml
new file: test/Spec.hs
Need to implement ctohtml functionality now.
And maybe tests for the lexer.
* Clean-up
modified: app/Main.hs
modified: package.yaml
modified: src/Boilerplate.hs
modified: src/Lex.hs
deleted: src/Lib.hs
Clean-up warnings (unused stuff). Remove unused Lib.hs
* Add swap files to gitignore
modified: .gitignore
* Add comments, fix keyword parsing
modified: src/Lex.hs
Previously keyword parsing would only work if you followed the keyword
with a whitespace. Now we just include all non-alphanumerir characters
as ends of a keyword.
* Fix escaped character parsing in strings
modified: src/Lex.hs
Had previously only fixed it for characters.
* Add explicit exports and comments to Boilerplate.hs
modified: src/Boilerplate.hs
* Remove chars written as numbers
modified: src/Lex.hs
* Rename Boilerplate to Types
modified: Lex.hs
renamed: Boilerplate.hs -> Types.hs
* Fix forgotten shift assigns, implement tokenToBS
modified: src/Types.hs
* Add generic tests, fix a couple of bugs
modified: package.yaml
renamed: src/Lex.hs -> src/Clex/Lex.hs
renamed: src/Types.hs -> src/Clex/Types.hs
modified: stack.yaml
new file: test/Clex/LexSpec.hs
new file: test/Clex/TypesSpec.hs
modified: test/Spec.hs
Added pretty basic tests that generate tokens and then lex to and from
bytestrings.
Fixed a bug where I didn't realise unsigned could be 0 or more
instances, and not a single char.
Fixed a bug where (tokenToBS Not) == "!=", instead of "!".
Fixed a bug where I was parsing Numbers before Floating numbers,
and as a result "0.123" would show up as [Number _, DotFloat _]
instead of [LeadingDot _].
* Remove executable info from clex lib
deleted: app/Main.hs
modified: package.yaml
* Add cToHtml tool
new file: .gitignore
new file: Setup.hs
new file: app/Main.hs
new file: package.yaml
new file: sample.c
new file: src/Html.hs
new file: stack.yaml
* Add instructions and global stack.yaml for ease of use
new file: .gitignore
new file: README.md
new file: stack.yaml
* Add a bit of docs to cToHtml
new file: README.md
modified: package.yaml
* Add comment on comments and the CPP
modified: README.md
* Apply hlint, remove ChangeLog.md, add *.swp
modified: .gitignore
new file: cToHtml/app/.Main.hs.swp
modified: cToHtml/app/Main.hs
modified: cToHtml/package.yaml
modified: clex/src/Clex/Lex.hs
modified: clex/test/Clex/LexSpec.hs
modified: clex/test/Clex/TypesSpec.hs
* Don't need Lucid for lexer
modified: clex/package.yaml
* Fix comma typo
modified: README.md
* Fix typo and misinformation
modified: cToHtml/package.yaml
modified: clex/package.yaml
1 files changed, 58 insertions, 0 deletions
| -rw-r--r-- | homework/81248/clex/test/Clex/LexSpec.hs | 58 |
diff --git a/homework/81248/clex/test/Clex/LexSpec.hs b/homework/81248/clex/test/Clex/LexSpec.hs new file mode 100644 index 0000000..c5fec81 --- /dev/null +++ b/homework/81248/clex/test/Clex/LexSpec.hs @@ -0,0 +1,58 @@ +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 |
