use proptest::prelude::*;
use crate::ast::AstNode;
use crate::tests::property_tests::generators::documents::arb_executable_document;
use crate::tests::property_tests::generators::documents::arb_schema_document;
use crate::tests::property_tests::proptest_config;
use crate::GraphQLParser;
proptest! {
#![proptest_config(proptest_config())]
#[test]
fn schema_source_slice_round_trip(source in arb_schema_document(4)) {
let result = GraphQLParser::new(&source).parse_schema_document();
prop_assert!(
!result.has_errors(),
"Generated schema document should parse without errors.\n\
Source:\n{}",
source,
);
let doc = result.into_ast();
let reconstructed = doc.to_source(Some(&source));
prop_assert_eq!(
&reconstructed,
&source,
"Source-slice round trip failed for schema document.",
);
}
#[test]
fn executable_source_slice_round_trip(
source in arb_executable_document(4)
) {
let result = GraphQLParser::new(&source).parse_executable_document();
prop_assert!(
!result.has_errors(),
"Generated executable document should parse without errors.\n\
Source:\n{}",
source,
);
let doc = result.into_ast();
let reconstructed = doc.to_source(Some(&source));
prop_assert_eq!(
&reconstructed,
&source,
"Source-slice round trip failed for executable document.",
);
}
#[test]
fn schema_reparse_stability(source in arb_schema_document(4)) {
let result = GraphQLParser::new(&source).parse_schema_document();
prop_assert!(
!result.has_errors(),
"Generated schema document should parse without errors.\n\
Source:\n{}",
source,
);
let doc = result.into_ast();
let reconstructed = doc.to_source(Some(&source));
let reparse_result = GraphQLParser::new(&reconstructed)
.parse_schema_document();
prop_assert!(
!reparse_result.has_errors(),
"Re-parse of reconstructed schema document failed.\n\
Original:\n{}\n\n\
Reconstructed:\n{}\n\n\
Errors:\n{}",
source,
reconstructed,
reparse_result.formatted_errors(),
);
}
#[test]
fn executable_reparse_stability(
source in arb_executable_document(4)
) {
let result = GraphQLParser::new(&source).parse_executable_document();
prop_assert!(
!result.has_errors(),
"Generated executable document should parse without errors.\n\
Source:\n{}",
source,
);
let doc = result.into_ast();
let reconstructed = doc.to_source(Some(&source));
let reparse_result = GraphQLParser::new(&reconstructed)
.parse_executable_document();
prop_assert!(
!reparse_result.has_errors(),
"Re-parse of reconstructed executable document failed.\n\
Original:\n{}\n\n\
Reconstructed:\n{}\n\n\
Errors:\n{}",
source,
reconstructed,
reparse_result.formatted_errors(),
);
}
}