Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests of actual schemas to cynic-parser #829

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cynic-parser/src/errors/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Error {
expected,
} => (
format!("unexpected {}", token),
Label::new(*start..*end).with_message("didn't expect to see this"),
Label::new(*dbg!(start)..*dbg!(end)).with_message("didn't expect to see this"),
Some(format!("expected one of {}", expected.join(", "))),
),
Error::ExtraToken {
Expand Down
5 changes: 3 additions & 2 deletions cynic-parser/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,17 @@ impl<'a> Pretty<'a, BoxAllocator> for NodeDisplay<DirectiveDefinition<'a>> {
.parens()
.flat_alt(arguments.parens());

builder = builder.append(arguments).append(allocator.space())
builder = builder.append(arguments)
}

if self.0.is_repeatable() {
builder = builder
.append(allocator.text("repeatable"))
.append(allocator.space())
.append(allocator.text("repeatable"))
}

builder
.append(allocator.space())
.append(allocator.text("on"))
.append(allocator.space())
.append(allocator.intersperse(
Expand Down
46 changes: 46 additions & 0 deletions cynic-parser/tests/actual_schemas.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
macro_rules! schema_tests {
($name: ident, $path: literal) => {
mod $name {
use similar_asserts::assert_eq;

#[allow(non_upper_case_globals)]
const SCHEMA: &str = include_str!($path);

#[test]
fn snapshot() {
let parsed = cynic_parser::parse_type_system_document(SCHEMA)
.map_err(|error| error.to_report(SCHEMA))
.unwrap();
insta::assert_snapshot!(parsed.to_sdl());
}

#[test]
fn double_roundtrip() {
let parsed = cynic_parser::parse_type_system_document(SCHEMA)
.map_err(|error| error.to_report(SCHEMA))
.unwrap();
let sdl = parsed.to_sdl();

let reparsed = cynic_parser::parse_type_system_document(&sdl)
.map_err(|error| error.to_report(&sdl))
.unwrap();

assert_eq!(sdl, reparsed.to_sdl());
}
}
};
}

schema_tests!(github, "../../schemas/github.graphql");

schema_tests!(books, "../../schemas/books.graphql");

schema_tests!(graphql_jobs, "../../schemas/graphql.jobs.graphql");

schema_tests!(raindancer, "../../schemas/raindancer.graphql");

schema_tests!(simple, "../../schemas/simple.graphql");

schema_tests!(starwars, "../../schemas/starwars.schema.graphql");

schema_tests!(test_cases, "../../schemas/test_cases.graphql");
7 changes: 0 additions & 7 deletions cynic-parser/tests/github.rs

This file was deleted.

43 changes: 43 additions & 0 deletions cynic-parser/tests/snapshots/actual_schemas__books__snapshot.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
source: cynic-parser/tests/actual_schemas.rs
expression: parsed.to_sdl()
---
schema {
query: QueryRoot
mutation: MutationRoot
subscription: SubscriptionRoot
}

directive @ifdef on FIELD

type Book {
id: String!
name: String!
author: String!
}

type BookChanged {
mutationType: MutationType!
id: ID!
book: Book
}

type MutationRoot {
createBook(name: String!, author: String!): ID!
deleteBook(id: ID!): Boolean!
}

enum MutationType {
CREATED
DELETED
}

type QueryRoot {
books: [Book!]!
}

type SubscriptionRoot {
interval(n: Int! = 1): Int!
books(mutationType: MutationType): BookChanged!
}

Loading
Loading