@@ -24,23 +24,12 @@ javaScriptSyntaxSpecs :: SpecWith ()
24
24
javaScriptSyntaxSpecs =
25
25
describe " Forest JavaScript syntax" $ do
26
26
it " prints a simple program" $ do
27
+ expected <- readFixture " js/simple"
27
28
let code =
28
29
Module [Function $ Declaration Nothing (ne " test" ) [] (Number 1 )]
29
- expected = " function test() { return 1 }"
30
- in printModule code `shouldBe` expected
31
- it " prints a function with an argument" $ do
32
- let code =
33
- Module
34
- [ Function $
35
- Declaration
36
- Nothing
37
- (ne " test" )
38
- [ne " num" ]
39
- (Identifier (ne " num" ))
40
- ]
41
- expected = " function test(num) { return num }"
42
30
in printModule code `shouldBe` expected
43
31
it " prints a function with many arguments" $ do
32
+ expected <- readFixture " js/arguments"
44
33
let code =
45
34
Module
46
35
[ Function $
@@ -50,15 +39,15 @@ javaScriptSyntaxSpecs =
50
39
[ne " a" , ne " b" ]
51
40
(Infix Add (Identifier (ne " a" )) (Identifier (ne " b" )))
52
41
]
53
- expected = " function test(a, b) { return a + b }"
54
42
in printModule code `shouldBe` expected
55
43
it " prints a function that returns a string" $ do
44
+ expected <- readFixture " js/string"
56
45
let code =
57
46
Module
58
47
[Function $ Declaration Nothing (ne " test" ) [] (String' " hey" )]
59
- expected = " function test() { return \" hey\" }"
60
48
in printModule code `shouldBe` expected
61
49
it " prints a function call with arguments" $ do
50
+ expected <- readFixture " js/call-with-arguments"
62
51
let code =
63
52
Module
64
53
[ Function $
@@ -70,7 +59,30 @@ javaScriptSyntaxSpecs =
70
59
(ne " func" )
71
60
[(Identifier (ne " a" )), (Identifier (ne " b" ))])
72
61
]
73
- expected = " function test(a, b) { return func(a, b) }"
62
+ in printModule code `shouldBe` expected
63
+ it " prints a function with an expression inside of parens" $ do
64
+ expected <- readFixture " js/parens"
65
+ let code =
66
+ Module
67
+ [ Function $
68
+ Declaration Nothing (ne " test" ) [] (BetweenParens (Number 1 ))
69
+ ]
70
+ in printModule code `shouldBe` expected
71
+ it " prints a function with a case" $ do
72
+ expected <- readFixture " js/case"
73
+ let code =
74
+ Module
75
+ [ Function $
76
+ Declaration
77
+ Nothing
78
+ (ne " test" )
79
+ [ne " a" ]
80
+ (Case
81
+ (Identifier (ne " a" ))
82
+ [ (String' " Foo" , String' " Bar" )
83
+ , (String' " Ahh" , String' " Woo" )
84
+ ])
85
+ ]
74
86
in printModule code `shouldBe` expected
75
87
76
88
ne :: String -> Ident
0 commit comments