diff options
| author | Danny Navarro <j@dannynavarro.net> | 2016-12-18 12:19:59 -0300 |
|---|---|---|
| committer | Danny Navarro <j@dannynavarro.net> | 2016-12-18 12:19:59 -0300 |
| commit | 933cfd2852d4f4321c03564a9cc351e3508ba73c (patch) | |
| tree | ec4610b87215de139f673993ed34b60604c04cf4 | |
| parent | aa66236081bff41ff7cea6cceac8d19095020763 (diff) | |
| download | graphql-933cfd2852d4f4321c03564a9cc351e3508ba73c.tar.gz | |
Tokenize number parser
The essential change hidden behind the code golfing is using the `tok`
combinator. This was making fail the Kitchen Sink test.
| -rw-r--r-- | Data/GraphQL/Parser.hs | 10 | ||||
| -rw-r--r-- | tests/tasty.hs | 3 |
2 files changed, 3 insertions, 10 deletions
diff --git a/Data/GraphQL/Parser.hs b/Data/GraphQL/Parser.hs index 26902d4..160efad 100644 --- a/Data/GraphQL/Parser.hs +++ b/Data/GraphQL/Parser.hs @@ -148,7 +148,8 @@ typeCondition = namedType -- explicit types use the `typedValue` parser. value :: Parser Value value = ValueVariable <$> variable - <|> number + -- TODO: Handle maxBound, Int32 in spec. + <|> tok (either ValueFloat ValueInt . floatingOrInteger <$> scientific) <|> ValueBoolean <$> booleanValue <|> ValueString <$> stringValue -- `true` and `false` have been tried before @@ -156,13 +157,6 @@ value = ValueVariable <$> variable <|> ValueList <$> listValue <|> ValueObject <$> objectValue <?> "value error!" - where - number = do - v <- scientific - case floatingOrInteger v of - Left r -> pure (ValueFloat r) - -- TODO: Handle maxBound, Int32 in spec. - Right i -> pure (ValueInt i) booleanValue :: Parser Bool booleanValue = True <$ tok "true" diff --git a/tests/tasty.hs b/tests/tasty.hs index 791bfbb..fa9bedf 100644 --- a/tests/tasty.hs +++ b/tests/tasty.hs @@ -22,7 +22,7 @@ main = defaultMain . testGroup "Tests" . (: [SW.test]) =<< ksTest ksTest :: IO TestTree ksTest = testCase "Kitchen Sink" - <$> (assertEqual "Encode" <$> expected <*> actual) + <$> (assertEqual "Encode" <$> expected <*> actual) where expected = Text.readFile =<< getDataFileName "tests/data/kitchen-sink.min.graphql" @@ -30,4 +30,3 @@ ksTest = testCase "Kitchen Sink" actual = either (error "Parsing error!") Encoder.document . parseOnly Parser.document <$> expected - |
