-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathschema_roundtrips.rs
More file actions
54 lines (48 loc) · 2.31 KB
/
schema_roundtrips.rs
File metadata and controls
54 lines (48 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
extern crate graphql_parser;
#[cfg(test)] #[macro_use] extern crate pretty_assertions;
use std::io::Read;
use std::fs::File;
use graphql_parser::parse_schema;
fn roundtrip(filename: &str) {
let mut buf = String::with_capacity(1024);
let path = format!("tests/schemas/{}.graphql", filename);
let mut f = File::open(&path).unwrap();
f.read_to_string(&mut buf).unwrap();
let ast = parse_schema::<String>(&buf).unwrap().to_owned();
assert_eq!(ast.to_string(), buf);
}
fn roundtrip2(filename: &str) {
let mut buf = String::with_capacity(1024);
let source = format!("tests/schemas/{}.graphql", filename);
let target = format!("tests/schemas/{}_canonical.graphql", filename);
let mut f = File::open(&source).unwrap();
f.read_to_string(&mut buf).unwrap();
let ast = parse_schema::<String>(&buf).unwrap();
let mut buf = String::with_capacity(1024);
let mut f = File::open(&target).unwrap();
f.read_to_string(&mut buf).unwrap();
assert_eq!(ast.to_string(), buf);
}
#[test] fn minimal() { roundtrip("minimal"); }
#[test] fn scalar_type() { roundtrip("scalar_type"); }
#[test] fn extend_scalar() { roundtrip("extend_scalar"); }
#[test] fn minimal_type() { roundtrip("minimal_type"); }
#[test] fn implements() { roundtrip("implements"); }
#[test] fn implements_amp() { roundtrip2("implements_amp"); }
#[test] fn implements_interface() { roundtrip("implements_interface"); }
#[test] fn simple_object() { roundtrip("simple_object"); }
#[test] fn extend_object() { roundtrip("extend_object"); }
#[test] fn interface() { roundtrip("interface"); }
#[test] fn extend_interface() { roundtrip("extend_interface"); }
#[test] fn union() { roundtrip("union"); }
#[test] fn empty_union() { roundtrip("empty_union"); }
#[test] fn union_extension() { roundtrip("union_extension"); }
#[test] fn enum_type() { roundtrip("enum"); }
#[test] fn extend_enum() { roundtrip("extend_enum"); }
#[test] fn input_type() { roundtrip("input_type"); }
#[test] fn extend_input() { roundtrip2("extend_input"); }
#[test] fn directive() { roundtrip("directive"); }
#[test] fn kitchen_sink() { roundtrip2("kitchen-sink"); }
#[test] fn directive_descriptions() { roundtrip2("directive_descriptions"); }
#[test] fn directive_variable_definition() { roundtrip("directive_variable_definition"); }
#[test] fn repeatable() {roundtrip("repeatable")}