From 34f25b70674e05b5618209aed3955ea16a6f059c Mon Sep 17 00:00:00 2001 From: u9g Date: Wed, 26 Jul 2023 23:59:02 -0400 Subject: [PATCH] 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 --- crates/oxc_query/src/tests.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/oxc_query/src/tests.rs b/crates/oxc_query/src/tests.rs index 3012ebd89..fde5ca742 100644 --- a/crates/oxc_query/src/tests.rs +++ b/crates/oxc_query/src/tests.rs @@ -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); +}