@@ -4,7 +4,7 @@ import Control.Monad (foldM)
4
4
import Test.Hspec (Spec , describe , it , shouldBe )
5
5
import Test.Hspec.Runner (configFastFail , defaultConfig , hspecWith )
6
6
7
- import Forth (ForthError (.. ), empty , evalText , formatStack )
7
+ import Forth (ForthError (.. ), empty , evalText , toList )
8
8
9
9
main :: IO ()
10
10
main = hspecWith defaultConfig {configFastFail = True } specs
@@ -15,61 +15,61 @@ specs = describe "forth" $ do
15
15
-- As of 2016-10-02, there was no reference file
16
16
-- for the test cases in `exercism/x-common`.
17
17
18
- let runTexts = fmap formatStack . foldM (flip evalText) empty
18
+ let runTexts = fmap toList . foldM (flip evalText) empty
19
19
20
20
it " no input, no stack" $
21
- formatStack empty `shouldBe` " "
21
+ toList empty `shouldBe` []
22
22
23
23
it " numbers just get pushed onto the stack" $
24
- runTexts [" 1 2 3 4 5" ] `shouldBe` Right " 1 2 3 4 5 "
24
+ runTexts [" 1 2 3 4 5" ] `shouldBe` Right [ 1 , 2 , 3 , 4 , 5 ]
25
25
26
26
it " non-word characters are separators" $
27
- runTexts [" 1\NUL 2\SOH 3\n 4\r 5 6\t 7" ] `shouldBe` Right " 1 2 3 4 5 6 7 "
27
+ runTexts [" 1\NUL 2\SOH 3\n 4\r 5 6\t 7" ] `shouldBe` Right [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ]
28
28
29
29
it " basic arithmetic" $ do
30
- runTexts [" 1 2 + 4 -" ] `shouldBe` Right " -1 "
31
- runTexts [" 2 4 * 3 /" ] `shouldBe` Right " 2 "
30
+ runTexts [" 1 2 + 4 -" ] `shouldBe` Right [ - 1 ]
31
+ runTexts [" 2 4 * 3 /" ] `shouldBe` Right [ 2 ]
32
32
33
33
it " division by zero" $
34
34
runTexts [" 4 2 2 - /" ] `shouldBe` Left DivisionByZero
35
35
36
36
it " dup" $ do
37
- runTexts [" 1 DUP" ] `shouldBe` Right " 1 1 "
38
- runTexts [" 1 2 Dup" ] `shouldBe` Right " 1 2 2 "
37
+ runTexts [" 1 DUP" ] `shouldBe` Right [ 1 , 1 ]
38
+ runTexts [" 1 2 Dup" ] `shouldBe` Right [ 1 , 2 , 2 ]
39
39
runTexts [" dup" ] `shouldBe` Left StackUnderflow
40
40
41
41
it " drop" $ do
42
- runTexts [" 1 drop" ] `shouldBe` Right " "
43
- runTexts [" 1 2 drop" ] `shouldBe` Right " 1 "
42
+ runTexts [" 1 drop" ] `shouldBe` Right []
43
+ runTexts [" 1 2 drop" ] `shouldBe` Right [ 1 ]
44
44
runTexts [" drop" ] `shouldBe` Left StackUnderflow
45
45
46
46
it " swap" $ do
47
- runTexts [" 1 2 swap" ] `shouldBe` Right " 2 1 "
48
- runTexts [" 1 2 3 swap" ] `shouldBe` Right " 1 3 2 "
47
+ runTexts [" 1 2 swap" ] `shouldBe` Right [ 2 , 1 ]
48
+ runTexts [" 1 2 3 swap" ] `shouldBe` Right [ 1 , 3 , 2 ]
49
49
runTexts [" 1 swap" ] `shouldBe` Left StackUnderflow
50
50
runTexts [" swap" ] `shouldBe` Left StackUnderflow
51
51
52
52
it " over" $ do
53
- runTexts [" 1 2 over" ] `shouldBe` Right " 1 2 1 "
54
- runTexts [" 1 2 3 over" ] `shouldBe` Right " 1 2 3 2 "
53
+ runTexts [" 1 2 over" ] `shouldBe` Right [ 1 , 2 , 1 ]
54
+ runTexts [" 1 2 3 over" ] `shouldBe` Right [ 1 , 2 , 3 , 2 ]
55
55
runTexts [" 1 over" ] `shouldBe` Left StackUnderflow
56
56
runTexts [" over" ] `shouldBe` Left StackUnderflow
57
57
58
58
it " defining a new word" $
59
59
runTexts [ " : dup-twice dup dup ;"
60
- , " 1 dup-twice" ] `shouldBe` Right " 1 1 1 "
60
+ , " 1 dup-twice" ] `shouldBe` Right [ 1 , 1 , 1 ]
61
61
62
62
it " redefining an existing word" $
63
63
runTexts [ " : foo dup ;"
64
64
, " : foo dup dup ;"
65
- , " 1 foo" ] `shouldBe` Right " 1 1 1 "
65
+ , " 1 foo" ] `shouldBe` Right [ 1 , 1 , 1 ]
66
66
67
67
it " redefining an existing built-in word" $
68
68
runTexts [ " : swap dup ;"
69
- , " 1 swap" ] `shouldBe` Right " 1 1 "
69
+ , " 1 swap" ] `shouldBe` Right [ 1 , 1 ]
70
70
71
71
it " defining words with odd characters" $
72
- runTexts [" : € 220371 ; €" ] `shouldBe` Right " 220371"
72
+ runTexts [" : € 220371 ; €" ] `shouldBe` Right [ 220371 ]
73
73
74
74
it " defining a number" $
75
75
runTexts [" : 1 2 ;" ] `shouldBe` Left InvalidWord
0 commit comments