@@ -2051,3 +2051,65 @@ g.test_propagate_defaults_to_callback = function()
2051
2051
t .assert_equals (errors , nil )
2052
2052
t .assert_items_equals (json .decode (data .prefix .test_mutation ), result )
2053
2053
end
2054
+
2055
+ function g .test_float_variables ()
2056
+ local query = [[
2057
+ query ($arg: Float) { test(arg: $arg) }
2058
+ ]]
2059
+
2060
+ local floats_positive = {
2061
+ ' 9007199254740991' ,
2062
+ ' -9007199254740992' ,
2063
+ ' 0' ,
2064
+ ' 9007199254740991.1' ,
2065
+ ' -9007199254740992.1' ,
2066
+ ' 99999999999999' ,
2067
+ ' 100000000000000' ,
2068
+ ' -99999999999999' ,
2069
+ ' -100000000000000' ,
2070
+ ' 1e1' ,
2071
+ ' -1e1' ,
2072
+ ' inf' ,
2073
+ ' -inf' ,
2074
+ }
2075
+
2076
+ local floats_negative = {
2077
+ {' 9007199254740992' , ' Wrong variable \" arg\" for the Scalar \" Float\" ' },
2078
+ {' -9007199254740993' , ' Wrong variable \" arg\" for the Scalar \" Float\" ' },
2079
+ }
2080
+
2081
+ local function callback (_ , args )
2082
+ return args [1 ].value
2083
+ end
2084
+
2085
+ local query_schema = {
2086
+ [' test' ] = {
2087
+ kind = types .float .nonNull ,
2088
+ arguments = {
2089
+ arg = types .float ,
2090
+ },
2091
+ resolve = callback ,
2092
+ }
2093
+ }
2094
+
2095
+ -- Positive tests
2096
+ for _ , value in ipairs (floats_positive ) do
2097
+ t .assert_items_equals (
2098
+ check_request (query , query_schema , nil , nil , {variables = json .decode (' {"arg": ' .. value .. ' }' )}),
2099
+ {test = tonumber (value )}
2100
+ )
2101
+ end
2102
+ t .assert_nan (
2103
+ check_request (query , query_schema , nil , nil , {variables = json .decode (' {"arg": nan}' )}).test
2104
+ )
2105
+
2106
+ -- Negative tests
2107
+ for _ , case in ipairs (floats_negative ) do
2108
+ t .assert_error_msg_equals (
2109
+ case [2 ],
2110
+ function ()
2111
+ check_request (query , query_schema , nil , nil , {variables = json .decode (' {"arg": ' .. case [1 ] .. ' }' )})
2112
+ end
2113
+ )
2114
+ end
2115
+ end
0 commit comments