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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
extern crate graphql_parser;
#[cfg(test)]
#[macro_use]
extern crate pretty_assertions;
use std::fs::File;
use std::io::Read;
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")
}
|