feat(query): adapter invariant test (#644)

Checks for invariants in the adapter that would certainly error out real
usage, doesn't actually use the data provided to the adapter
This commit is contained in:
u9g 2023-07-26 23:59:02 -04:00 committed by GitHub
parent 5b0449507e
commit 34f25b7067
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,7 +4,7 @@ use oxc_allocator::Allocator;
use oxc_parser::Parser;
use oxc_semantic::SemanticBuilder;
use oxc_span::SourceType;
use trustfall::{execute_query, FieldValue, TryIntoStruct};
use trustfall::{execute_query, provider::check_adapter_invariants, FieldValue, TryIntoStruct};
use crate::{adapter::schema, Adapter};
@ -205,3 +205,19 @@ query {
results
);
}
#[test]
fn test_invariants() {
let file_path = "/apple/orange.tsx";
let source_text = "const apple = 1;";
let allocator = Allocator::default();
let source_type = SourceType::from_path(file_path).unwrap();
let ret = Parser::new(&allocator, source_text, source_type).parse();
let program = allocator.alloc(ret.program);
let semantic_ret =
SemanticBuilder::new(source_text, source_type).with_trivias(&ret.trivias).build(program);
let adapter = Adapter { path_components: vec![], semantic: Rc::new(semantic_ret.semantic) };
check_adapter_invariants(schema(), &adapter);
}