Additional tests
This commit is contained in:
		| @ -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? | ## 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 | -- We can define functions or "variables" as Tree Calculus values | ||||||
| false = t  | false = t  | ||||||
| _ = t | _ = t | ||||||
|  | |||||||
| @ -79,10 +79,8 @@ comment :: Lexer LToken | |||||||
| comment = do | comment = do | ||||||
|   string "--" |   string "--" | ||||||
|   content <- many (satisfy (/= '\n')) |   content <- many (satisfy (/= '\n')) | ||||||
|   optional (char '\n') |  | ||||||
|   pure (LComment content) |   pure (LComment content) | ||||||
|  |  | ||||||
|  |  | ||||||
| sc :: Lexer () | sc :: Lexer () | ||||||
| sc = skipMany (void (char ' ') <|> void (char '\t') <|> void comment) | sc = skipMany (void (char ' ') <|> void (char '\t') <|> void comment) | ||||||
|  |  | ||||||
|  | |||||||
| @ -33,12 +33,9 @@ parseTricu input = | |||||||
|  |  | ||||||
| parseSingle :: String -> TricuAST | parseSingle :: String -> TricuAST | ||||||
| parseSingle input = case runParser parseExpression "" (lexTricu input) of | parseSingle input = case runParser parseExpression "" (lexTricu input) of | ||||||
|   Left err -> error $ handleParseError err |   Left  err -> error $ handleParseError err | ||||||
|   Right ast -> ast |   Right ast -> ast | ||||||
|  |  | ||||||
| scnParser :: Parser () |  | ||||||
| scnParser = skipMany (satisfy isNewline) |  | ||||||
|  |  | ||||||
| parseExpression :: Parser TricuAST | parseExpression :: Parser TricuAST | ||||||
| parseExpression = choice | parseExpression = choice | ||||||
|   [ try parseFunction |   [ try parseFunction | ||||||
| @ -50,6 +47,9 @@ parseExpression = choice | |||||||
|   , parseLiteral |   , parseLiteral | ||||||
|   ] |   ] | ||||||
|  |  | ||||||
|  | scnParser :: Parser () | ||||||
|  | scnParser = skipMany (satisfy isNewline) | ||||||
|  |  | ||||||
| parseFunction :: Parser TricuAST | parseFunction :: Parser TricuAST | ||||||
| parseFunction = do | parseFunction = do | ||||||
|   LIdentifier name <- satisfy isIdentifier |   LIdentifier name <- satisfy isIdentifier | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								test/Spec.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								test/Spec.hs
									
									
									
									
									
								
							| @ -145,6 +145,18 @@ parserTests = testGroup "Parser Tests" | |||||||
|       let input  = "x = (\\a : a)\nx (t)" |       let input  = "x = (\\a : a)\nx (t)" | ||||||
|           expect = [SFunc "x" [] (SLambda ["a"] (SVar "a")),SApp (SVar "x") TLeaf] |           expect = [SFunc "x" [] (SLambda ["a"] (SVar "a")),SApp (SVar "x") TLeaf] | ||||||
|       parseTricu input @?= expect |       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 | integrationTests :: TestTree | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 James Eversole
					James Eversole