Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions exercises/practice/forth/test/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ specs = do
it "errors if executing a non-existent word" $
runTexts ["1 foo"] `shouldBe` Left (UnknownWord "foo")

it "redefines an existing word with another existing word" $
runTexts [ ": foo 5 ;"
, ": bar foo ;"
, ": foo 6 ;"
, ": bar foo ;"
, "bar foo" ] `shouldBe` Right [6, 6]

describe "case-insensitivity" $ do
it "DUP is case-insensitive" $
runTexts ["1 DUP Dup dup" ] `shouldBe` Right [1, 1, 1, 1]
Expand All @@ -153,3 +160,17 @@ specs = do
it "definitions are case-insensitive" $
runTexts [ ": SWAP DUP Dup dup ;"
, "1 swap" ] `shouldBe` Right [1, 1, 1, 1]

describe "malformed word definitions" $ do
it "empty definition and no end" $
runTexts [":"] `shouldBe` Left InvalidWord
it "no end" $
runTexts [": foo"] `shouldBe` Left InvalidWord
it "no definition" $
runTexts [": ;"] `shouldBe` Left InvalidWord

describe "multiple definitions" $ do
it "on a line" $
runTexts [": one 1 ; : two 2 ; one two +"] `shouldBe` Right [3]
it "after ops" $
runTexts ["1 2 + : addone 1 + ; addone"] `shouldBe` Right [4]