Skip to content

Commit 9a0509f

Browse files
committed
Add query error test
1 parent 89a260c commit 9a0509f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/query_errors.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
extern crate graphql_parser;
2+
#[cfg(test)] #[macro_use] extern crate pretty_assertions;
3+
4+
use std::io::Read;
5+
use std::fs::File;
6+
7+
use graphql_parser::parse_query;
8+
9+
fn test_error(filename: &str) {
10+
let mut buf = String::with_capacity(1024);
11+
let path = format!("tests/query_errors/{}.txt", filename);
12+
let mut f = File::open(&path).unwrap();
13+
f.read_to_string(&mut buf).unwrap();
14+
let mut iter = buf.splitn(2, "\n---\n");
15+
let graphql = iter.next().unwrap();
16+
let expected = iter.next().expect("file should contain error message");
17+
let err = parse_query(&graphql).unwrap_err();
18+
assert_eq!(err.to_string(), expected);
19+
}
20+
21+
#[test] fn invalid_curly_brace() { test_error("invalid_curly_brace"); }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
querry MyQuery {
2+
field1
3+
}
4+
---
5+
query parse error: Parse error at 1:1
6+
Unexpected `querry[Name]`
7+
Expected `{`, `query`, `mutation`, `subscription` or `fragment`

0 commit comments

Comments
 (0)