-
Notifications
You must be signed in to change notification settings - Fork 1.1k
parseValue coercion alignment for Boolean, Float, and Int #3042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03e10fb
Align Boolean parseValue with JS implementation
dondonz e042b8e
Align Float parseValue with JS implementation
dondonz 2c514ca
Align integer parseValue coercion with JS implementation
dondonz 64934d6
Add separate exception message for values outside integer range
dondonz 954ec14
Tidy
dondonz fd23fc8
Fix up tests
dondonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -53,7 +53,6 @@ class ScalarsBooleanTest extends Specification { | |
def "Boolean serialize #value into #result (#result.class)"() { | ||
expect: | ||
Scalars.GraphQLBoolean.getCoercing().serialize(value, GraphQLContext.default, Locale.default) == result | ||
Scalars.GraphQLBoolean.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved into separate test below |
||
|
||
where: | ||
value | result | ||
|
@@ -75,7 +74,6 @@ class ScalarsBooleanTest extends Specification { | |
def "Boolean serialize #value into #result (#result.class) with deprecated methods"() { | ||
expect: | ||
Scalars.GraphQLBoolean.getCoercing().serialize(value) == result // Retain deprecated method for test coverage | ||
Scalars.GraphQLBoolean.getCoercing().parseValue(value) == result // Retain deprecated method for test coverage | ||
|
||
where: | ||
value | result | ||
|
@@ -111,6 +109,28 @@ class ScalarsBooleanTest extends Specification { | |
"f" | _ | ||
} | ||
|
||
@Unroll | ||
def "Boolean parseValue #value into #result (#result.class)"() { | ||
expect: | ||
Scalars.GraphQLBoolean.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result | ||
|
||
where: | ||
value | result | ||
true | true | ||
false | false | ||
} | ||
|
||
@Unroll | ||
def "Boolean parseValue #value into #result (#result.class) with deprecated methods"() { | ||
expect: | ||
Scalars.GraphQLBoolean.getCoercing().parseValue(value) == result // Retain deprecated method for test coverage | ||
|
||
where: | ||
value | result | ||
true | true | ||
false | false | ||
} | ||
|
||
@Unroll | ||
def "parseValue throws exception for invalid input #value"() { | ||
when: | ||
|
@@ -119,8 +139,19 @@ class ScalarsBooleanTest extends Specification { | |
thrown(CoercingParseValueException) | ||
|
||
where: | ||
value | _ | ||
new Object() | _ | ||
value | _ | ||
new Object() | _ | ||
"false" | _ | ||
"true" | _ | ||
"True" | _ | ||
0 | _ | ||
1 | _ | ||
-1 | _ | ||
new Long(42345784398534785l) | _ | ||
new Double(42.3) | _ | ||
new Float(42.3) | _ | ||
Integer.MAX_VALUE + 1l | _ | ||
Integer.MIN_VALUE - 1l | _ | ||
} | ||
|
||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -58,7 +58,6 @@ class ScalarsFloatTest extends Specification { | |
def "Float serialize #value into #result (#result.class)"() { | ||
expect: | ||
Scalars.GraphQLFloat.getCoercing().serialize(value, GraphQLContext.default, Locale.default) == result | ||
Scalars.GraphQLFloat.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved into separate test below |
||
|
||
where: | ||
value | result | ||
|
@@ -84,7 +83,6 @@ class ScalarsFloatTest extends Specification { | |
def "Float serialize #value into #result (#result.class) with deprecated methods"() { | ||
expect: | ||
Scalars.GraphQLFloat.getCoercing().serialize(value) == result // Retain deprecated method for coverage | ||
Scalars.GraphQLFloat.getCoercing().parseValue(value) == result // Retain deprecated method for coverage | ||
|
||
where: | ||
value | result | ||
|
@@ -131,6 +129,51 @@ class ScalarsFloatTest extends Specification { | |
Float.NEGATIVE_INFINITY.toString() | _ | ||
} | ||
|
||
@Unroll | ||
def "Float parseValue #value into #result (#result.class)"() { | ||
expect: | ||
Scalars.GraphQLFloat.getCoercing().parseValue(value, GraphQLContext.default, Locale.default) == result | ||
|
||
where: | ||
value | result | ||
42.0000d | 42 | ||
new Integer(42) | 42 | ||
new BigInteger("42") | 42 | ||
new BigDecimal("42") | 42 | ||
new BigDecimal("4.2") | 4.2d | ||
42.3f | 42.3d | ||
42.0d | 42d | ||
new Byte("42") | 42 | ||
new Short("42") | 42 | ||
1234567l | 1234567d | ||
new AtomicInteger(42) | 42 | ||
Double.MAX_VALUE | Double.MAX_VALUE | ||
Double.MIN_VALUE | Double.MIN_VALUE | ||
} | ||
|
||
@Unroll | ||
def "Float parseValue #value into #result (#result.class) with deprecated methods"() { | ||
expect: | ||
Scalars.GraphQLFloat.getCoercing().parseValue(value) == result // Retain deprecated method for coverage | ||
|
||
where: | ||
value | result | ||
42.0000d | 42 | ||
new Integer(42) | 42 | ||
new BigInteger("42") | 42 | ||
new BigDecimal("42") | 42 | ||
new BigDecimal("4.2") | 4.2d | ||
42.3f | 42.3d | ||
42.0d | 42d | ||
new Byte("42") | 42 | ||
new Short("42") | 42 | ||
1234567l | 1234567d | ||
new AtomicInteger(42) | 42 | ||
Double.MAX_VALUE | Double.MAX_VALUE | ||
Double.MIN_VALUE | Double.MIN_VALUE | ||
} | ||
|
||
|
||
@Unroll | ||
def "parseValue throws exception for invalid input #value"() { | ||
when: | ||
|
@@ -154,6 +197,9 @@ class ScalarsFloatTest extends Specification { | |
Float.POSITIVE_INFINITY.toString() | _ | ||
Float.NEGATIVE_INFINITY | _ | ||
Float.NEGATIVE_INFINITY.toString() | _ | ||
"42" | _ | ||
"42.123" | _ | ||
"-1" | _ | ||
} | ||
|
||
} |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For values outside of the integer range, we previously threw an exception with the same
Int.notInt
message. We ought to useInt.outsideRange
for this case, as we do inparseLiteral