Additional tests

This commit is contained in:
James Eversole 2024-12-29 12:22:24 -06:00
parent a7674d4635
commit b86ff6e9b8
4 changed files with 17 additions and 7 deletions

View File

@ -19,7 +19,7 @@ tricu is the word for "tree" in Lojban: `(x1) is a tree of species/cultivar (x2)
## What does it look like?
```
-- Anything after `--` on a line is a comment
-- Anything after `--` on a single line is a comment
-- We can define functions or "variables" as Tree Calculus values
false = t
_ = t

View File

@ -79,10 +79,8 @@ comment :: Lexer LToken
comment = do
string "--"
content <- many (satisfy (/= '\n'))
optional (char '\n')
pure (LComment content)
sc :: Lexer ()
sc = skipMany (void (char ' ') <|> void (char '\t') <|> void comment)

View File

@ -33,12 +33,9 @@ parseTricu input =
parseSingle :: String -> TricuAST
parseSingle input = case runParser parseExpression "" (lexTricu input) of
Left err -> error $ handleParseError err
Left err -> error $ handleParseError err
Right ast -> ast
scnParser :: Parser ()
scnParser = skipMany (satisfy isNewline)
parseExpression :: Parser TricuAST
parseExpression = choice
[ try parseFunction
@ -50,6 +47,9 @@ parseExpression = choice
, parseLiteral
]
scnParser :: Parser ()
scnParser = skipMany (satisfy isNewline)
parseFunction :: Parser TricuAST
parseFunction = do
LIdentifier name <- satisfy isIdentifier

View File

@ -145,6 +145,18 @@ parserTests = testGroup "Parser Tests"
let input = "x = (\\a : a)\nx (t)"
expect = [SFunc "x" [] (SLambda ["a"] (SVar "a")),SApp (SVar "x") TLeaf]
parseTricu input @?= expect
, testCase "Comments 1" $ do
let input = "(t) (t) -- (t)"
expect = [SApp TLeaf TLeaf]
parseTricu input @?= expect
, testCase "Comments 2" $ do
let input = "(t) -- (t) -- (t)"
expect = [TLeaf]
parseTricu input @?= expect
-- , testCase "Comments with no terms" $ do
-- let input = unlines ["-- (t)", "(t t)"]
-- expect = []
-- parseTricu input @?= expect
]
integrationTests :: TestTree