forked from OSS/graphql
		
	Tokenize number parser
The essential change hidden behind the code golfing is using the `tok` combinator. This was making fail the Kitchen Sink test.
This commit is contained in:
		| @@ -148,7 +148,8 @@ typeCondition = namedType | |||||||
| -- explicit types use the `typedValue` parser. | -- explicit types use the `typedValue` parser. | ||||||
| value :: Parser Value | value :: Parser Value | ||||||
| value = ValueVariable <$> variable | value = ValueVariable <$> variable | ||||||
|     <|> number |     -- TODO: Handle maxBound, Int32 in spec. | ||||||
|  |     <|> tok (either ValueFloat ValueInt . floatingOrInteger <$> scientific) | ||||||
|     <|> ValueBoolean  <$> booleanValue |     <|> ValueBoolean  <$> booleanValue | ||||||
|     <|> ValueString   <$> stringValue |     <|> ValueString   <$> stringValue | ||||||
|     -- `true` and `false` have been tried before |     -- `true` and `false` have been tried before | ||||||
| @@ -156,13 +157,6 @@ value = ValueVariable <$> variable | |||||||
|     <|> ValueList     <$> listValue |     <|> ValueList     <$> listValue | ||||||
|     <|> ValueObject   <$> objectValue |     <|> ValueObject   <$> objectValue | ||||||
|     <?> "value error!" |     <?> "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 :: Parser Bool | ||||||
| booleanValue = True  <$ tok "true" | booleanValue = True  <$ tok "true" | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ main = defaultMain . testGroup "Tests" . (: [SW.test]) =<< ksTest | |||||||
|  |  | ||||||
| ksTest :: IO TestTree | ksTest :: IO TestTree | ||||||
| ksTest = testCase "Kitchen Sink" | ksTest = testCase "Kitchen Sink" | ||||||
|                    <$> (assertEqual "Encode" <$> expected <*> actual) |      <$> (assertEqual "Encode" <$> expected <*> actual) | ||||||
|   where |   where | ||||||
|     expected = Text.readFile |     expected = Text.readFile | ||||||
|            =<< getDataFileName "tests/data/kitchen-sink.min.graphql" |            =<< getDataFileName "tests/data/kitchen-sink.min.graphql" | ||||||
| @@ -30,4 +30,3 @@ ksTest = testCase "Kitchen Sink" | |||||||
|     actual = either (error "Parsing error!") Encoder.document |     actual = either (error "Parsing error!") Encoder.document | ||||||
|           .  parseOnly Parser.document |           .  parseOnly Parser.document | ||||||
|          <$> expected |          <$> expected | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user