Unit.hs (3098B)
1 {-# LANGUAGE OverloadedStrings #-} 2 3 module Co.Tests.Unit ( 4 tests 5 ) where 6 7 import Data.Word (Word32) 8 import Test.Hspec 9 import qualified Urbit.Ob.Co as Co 10 11 tests :: Spec 12 tests = do 13 describe "renderPatp" $ do 14 it "matches 32-bit reference values" $ do 15 Co.renderPatp (Co.patp 0) `shouldBe` "~zod" 16 Co.renderPatp (Co.patp 255) `shouldBe` "~fes" 17 Co.renderPatp (Co.patp 256) `shouldBe` "~marzod" 18 Co.renderPatp (Co.patp 65535) `shouldBe` "~fipfes" 19 Co.renderPatp (Co.patp 65536) `shouldBe` "~dapnep-ronmyl" 20 Co.renderPatp (Co.patp 15663360) `shouldBe` "~nidsut-tomdun" 21 Co.renderPatp (Co.patp 0xFFFFFFFF) `shouldBe` "~dostec-risfen" 22 23 it "matches 64-bit reference values" $ do 24 let big_64_01 = 0x0000000100000000 25 Co.renderPatp (Co.patp big_64_01) `shouldBe` "~doznec-dozzod-dozzod" 26 27 let big_64_02 = 0xFFFFFFFFFFFFFFFF 28 Co.renderPatp (Co.patp big_64_02) `shouldBe` "~fipfes-fipfes-dostec-risfen" 29 30 it "matches 128-bit reference values" $ do 31 let big_128_01 = 0x00000000000000010000000000000000 32 patp_128_01 = "~doznec--dozzod-dozzod-dozzod-dozzod" 33 Co.renderPatp (Co.patp big_128_01) `shouldBe` patp_128_01 34 35 let big_128_02 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 36 patp_128_02 = 37 "~fipfes-fipfes-fipfes-fipfes--fipfes-fipfes-fipfes-fipfes" 38 39 Co.renderPatp (Co.patp big_128_02) `shouldBe` patp_128_02 40 41 describe "renderPatq" $ do 42 it "matches 32-bit reference values" $ do 43 Co.renderPatq (Co.patq 0) `shouldBe` "~zod" 44 Co.renderPatq (Co.patq 255) `shouldBe` "~fes" 45 Co.renderPatq (Co.patq 256) `shouldBe` "~marzod" 46 Co.renderPatq (Co.patq 65535) `shouldBe` "~fipfes" 47 Co.renderPatq (Co.patq 65536) `shouldBe` "~nec-dozzod" 48 Co.renderPatq (Co.patq 15663360) `shouldBe` "~mun-marzod" 49 Co.renderPatq (Co.patq 0xFFFFFFFF) `shouldBe` "~fipfes-fipfes" 50 51 it "matches 64-bit reference values" $ do 52 let big_64_01 = 0x0000000100000000 53 Co.renderPatq (Co.patq big_64_01) `shouldBe` "~nec-dozzod-dozzod" 54 55 let big_64_02 = 0xFFFFFFFFFFFFFFFF 56 patq_64_02 = "~fipfes-fipfes-fipfes-fipfes" 57 Co.renderPatq (Co.patq big_64_02) `shouldBe` patq_64_02 58 59 it "matches 128-bit reference values" $ do 60 let big_128_01 = 0x00000000000000010000000000000000 61 patq_128_01 = "~nec-dozzod-dozzod-dozzod-dozzod" 62 Co.renderPatq (Co.patq big_128_01) `shouldBe` patq_128_01 63 64 let big_128_02 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 65 patq_128_02 = 66 "~fipfes-fipfes-fipfes-fipfes-fipfes-fipfes-fipfes-fipfes" 67 68 Co.renderPatq (Co.patq big_128_02) `shouldBe` patq_128_02 69 70 describe "parsePatp" $ 71 it "yields an equivalent internal representation with patp for ~zod" $ do 72 let pzod = Co.parsePatp "~zod" 73 ezod = Co.patp 0 74 fmap (== ezod) pzod `shouldBe` Right True 75 76 describe "parsePatq" $ 77 it "yields an equivalent internal representation with patq for ~zod" $ do 78 let pzod = Co.parsePatq "~zod" 79 ezod = Co.patq 0 80 fmap (== ezod) pzod `shouldBe` Right True