-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpec.hs
35 lines (32 loc) · 1.06 KB
/
Spec.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{-# LANGUAGE QuasiQuotes #-}
import Brainfuck (bf)
import Data.ByteString.Internal (c2w)
import Data.Word (Word8)
import Test.Hspec
main :: IO ()
main = hspec $ do
it "interprets a `hello world` brainfuck program, no matter what indentation style is used" $
let helloWorld =
[bf|
anything that is not brainfuck should be ignored
>++++++++
[<+++++++++>-]
<.>++++[<+++++++>-]
<+.+++++++..+++.>>++++++[
<+++++++>- # this comment should be ignored too during parsing
]
<++.------------.>++++++
[<+++++++++>-]
<+.<.+++.------.--------.>>>++++
[<++++++++>-]
<+.
|]
in helloWorld (fromString "") `shouldBe` fromString "Hello, World!"
it "reads input and does things with it" $
let doubleFirstThreeNumbers =
[bf|
+++[>,>[-]<[>++<-]>.<<-]
|]
in doubleFirstThreeNumbers [0, 10, 35, 100] `shouldBe` [0, 20, 70]
fromString :: String -> [Word8]
fromString = fmap c2w