-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix variable and assigment not working together
- Loading branch information
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
module Unit.Parser.Program (allTests) where | ||
|
||
import AST | ||
import Data.Either (fromRight, isRight) | ||
import Parser.Program | ||
import Test.HUnit | ||
import Text.Parsec (parse) | ||
|
||
allTests :: [Test] | ||
allTests = | ||
[ TestLabel "simple" testSimple | ||
] | ||
|
||
emptyProgram :: Program | ||
emptyProgram = Program [] | ||
|
||
testSimple :: Test | ||
testSimple = TestCase $ do | ||
assertEqual | ||
"empty" | ||
True | ||
(isRight (parse parseProgram "" "")) | ||
assertEqual | ||
"Single variable statement" | ||
( Program | ||
[ VariableStatement | ||
( Variable | ||
"k" | ||
IntType | ||
( AtomicExpression (LiteralAtomic (IntLiteral 1)) | ||
) | ||
) | ||
] | ||
) | ||
(fromRight emptyProgram (parse parseProgram "" "int k = 1;")) | ||
assertEqual | ||
"Multiple variable statements" | ||
( Program | ||
[ VariableStatement | ||
( Variable | ||
"k" | ||
IntType | ||
( AtomicExpression (LiteralAtomic (IntLiteral 1)) | ||
) | ||
), | ||
VariableStatement | ||
( Variable | ||
"j" | ||
IntType | ||
( AtomicExpression (LiteralAtomic (IntLiteral 2)) | ||
) | ||
) | ||
] | ||
) | ||
(fromRight emptyProgram (parse parseProgram "" "int k = 1; int j = 2;")) | ||
assertEqual | ||
"Single assignment statement" | ||
( Program | ||
[ AssignmentStatement | ||
( Assignment | ||
"k" | ||
( AtomicExpression (LiteralAtomic (IntLiteral 1)) | ||
) | ||
) | ||
] | ||
) | ||
(fromRight emptyProgram (parse parseProgram "" "k = 1;")) | ||
assertEqual | ||
"variable statement and assignment statement" | ||
( Program | ||
[ VariableStatement | ||
( Variable | ||
"k" | ||
IntType | ||
( AtomicExpression (LiteralAtomic (IntLiteral 1)) | ||
) | ||
), | ||
AssignmentStatement | ||
( Assignment | ||
"j" | ||
( AtomicExpression (LiteralAtomic (IntLiteral 2)) | ||
) | ||
) | ||
] | ||
) | ||
(fromRight emptyProgram (parse parseProgram "" "int k = 1; j = 2;")) |