From eb04dcdf786063085e7754cbe00b538521148c29 Mon Sep 17 00:00:00 2001 From: Nicolai Unrein Date: Wed, 22 Jul 2020 14:24:09 +0200 Subject: [PATCH] add tests for overflowing int and float --- async-graphql-parser/src/query_parser.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/async-graphql-parser/src/query_parser.rs b/async-graphql-parser/src/query_parser.rs index a184fb6a..4520252e 100644 --- a/async-graphql-parser/src/query_parser.rs +++ b/async-graphql-parser/src/query_parser.rs @@ -527,4 +527,22 @@ mod tests { } } } + + #[test] + fn test_parse_overflowing_int() { + let query_ok = format!("mutation {{ add(big: {}) }} ", std::i32::MAX); + let query_overflow = format!("mutation {{ add(big: {}0) }} ", std::i32::MAX); + assert!(parse_query(query_ok).is_ok()); + assert!(parse_query(query_overflow).is_err()); + } + + #[test] + fn test_parse_overflowing_float() { + let query_ok = format!("mutation {{ add(big: {:.1}) }} ", std::f64::MAX); + let query_overflow = format!("mutation {{ add(big: 1{:.1}) }} ", std::f64::MAX); + assert!(parse_query(query_ok).is_ok()); + + // NOTE: This is also ok since overflow gets parsed to infinity. + assert!(parse_query(query_overflow).is_ok()); + } }