-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8b3f13
commit 2c497be
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
module Test.Eclair.JSONSpec | ||
( module Test.Eclair.JSONSpec | ||
) where | ||
|
||
import Eclair.JSON | ||
import Test.Hspec | ||
import NeatInterpolation | ||
|
||
spec :: Spec | ||
spec = describe "JSON encoding" $ parallel $ do | ||
it "can encode null" $ do | ||
encodeJSON Null `shouldBe` "null" | ||
|
||
it "can encode booleans" $ do | ||
encodeJSON (Boolean True) `shouldBe` "true" | ||
encodeJSON (Boolean False) `shouldBe` "false" | ||
|
||
it "can encode strings" $ do | ||
encodeJSON (String "abcdef") `shouldBe` [text|"abcdef"|] | ||
encodeJSON (String "123") `shouldBe` [text|"123"|] | ||
|
||
it "can encode integers" $ do | ||
encodeJSON (Number 42) `shouldBe` "42" | ||
encodeJSON (Number 123) `shouldBe` "123" | ||
|
||
it "can encode objects" $ do | ||
encodeJSON (Object [("line", Number 10), ("column", Number 33)]) `shouldBe` [text| | ||
{"line":10,"column":33} | ||
|] | ||
encodeJSON (Object [("a", Null), ("b", Boolean True)]) `shouldBe` [text| | ||
{"a":null,"b":true} | ||
|] | ||
|
||
it "can encode arrays" $ do | ||
encodeJSON (Array []) `shouldBe` "[]" | ||
encodeJSON (Array [Number 123, String "abc", Null]) `shouldBe` [text| | ||
[123,"abc",null] | ||
|] |