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