diff --git a/server/src/engine/ql/dml.rs b/server/src/engine/ql/dml.rs index d12f961d..ea7cdd88 100644 --- a/server/src/engine/ql/dml.rs +++ b/server/src/engine/ql/dml.rs @@ -293,9 +293,12 @@ pub(super) fn parse_list<'a, Qd: QueryData<'a>>( } #[cfg(test)] -pub(super) fn parse_list_full(tok: &[Token]) -> Option> { +pub(super) fn parse_list_full<'a>( + tok: &'a [Token], + qd: &mut impl QueryData<'a>, +) -> Option> { let mut l = Vec::new(); - if matches!(parse_list(tok, &mut InplaceData::new(), &mut l), (_, i, true) if i == tok.len()) { + if matches!(parse_list(tok, qd, &mut l), (_, i, true) if i == tok.len()) { Some(l) } else { None diff --git a/server/src/engine/ql/tests.rs b/server/src/engine/ql/tests.rs index 10e14350..398909ab 100644 --- a/server/src/engine/ql/tests.rs +++ b/server/src/engine/ql/tests.rs @@ -26,7 +26,7 @@ use { super::{ - lexer::{InsecureLexer, Symbol, Token}, + lexer::{InsecureLexer, SafeLexer, Symbol, Token}, LangResult, }, crate::{engine::memory::DataType, util::test_utils}, @@ -45,11 +45,16 @@ mod lexer_tests; mod schema_tests; mod structure_syn; -/// Uses the [`InsecureLexer`] to lex the given input #[inline(always)] +/// Uses the [`InsecureLexer`] to lex the given input pub(super) fn lex_insecure(src: &[u8]) -> LangResult> { InsecureLexer::lex(src) } +#[inline(always)] +/// Uses the [`SafeLexer`] to lex the given input +pub(super) fn lex_secure(src: &[u8]) -> LangResult> { + SafeLexer::lex(src) +} pub trait NullableData { fn data(self) -> Option; diff --git a/server/src/engine/ql/tests/dml_tests.rs b/server/src/engine/ql/tests/dml_tests.rs index 7684d0e0..7707fd4d 100644 --- a/server/src/engine/ql/tests/dml_tests.rs +++ b/server/src/engine/ql/tests/dml_tests.rs @@ -27,7 +27,11 @@ use super::*; mod list_parse { use super::*; - use crate::engine::ql::dml::parse_list_full; + use crate::engine::ql::{ + ast::{InplaceData, SubstitutedData}, + dml::parse_list_full, + lexer::LitIR, + }; #[test] fn list_mini() { @@ -37,10 +41,9 @@ mod list_parse { ", ) .unwrap(); - let r = parse_list_full(&tok[1..]).unwrap(); + let r = parse_list_full(&tok[1..], &mut InplaceData::new()).unwrap(); assert_eq!(r, vec![]) } - #[test] fn list() { let tok = lex_insecure( @@ -49,10 +52,27 @@ mod list_parse { ", ) .unwrap(); - let r = parse_list_full(&tok[1..]).unwrap(); + let r = parse_list_full(&tok[1..], &mut InplaceData::new()).unwrap(); + assert_eq!(r.as_slice(), into_array![1, 2, 3, 4]) + } + #[test] + fn list_param() { + let tok = lex_secure( + b" + [?, ?, ?, ?] + ", + ) + .unwrap(); + let data = [ + LitIR::UInt(1), + LitIR::UInt(2), + LitIR::UInt(3), + LitIR::UInt(4), + ]; + let mut param = SubstitutedData::new(&data); + let r = parse_list_full(&tok[1..], &mut param).unwrap(); assert_eq!(r.as_slice(), into_array![1, 2, 3, 4]) } - #[test] fn list_pro() { let tok = lex_insecure( @@ -66,7 +86,40 @@ mod list_parse { ", ) .unwrap(); - let r = parse_list_full(&tok[1..]).unwrap(); + let r = parse_list_full(&tok[1..], &mut InplaceData::new()).unwrap(); + assert_eq!( + r.as_slice(), + into_array![ + into_array![1, 2], + into_array![3, 4], + into_array![5, 6], + into_array![] + ] + ) + } + #[test] + fn list_pro_param() { + let tok = lex_secure( + b" + [ + [?, ?], + [?, ?], + [?, ?], + [] + ] + ", + ) + .unwrap(); + let data = [ + LitIR::UInt(1), + LitIR::UInt(2), + LitIR::UInt(3), + LitIR::UInt(4), + LitIR::UInt(5), + LitIR::UInt(6), + ]; + let mut param = SubstitutedData::new(&data); + let r = parse_list_full(&tok[1..], &mut param).unwrap(); assert_eq!( r.as_slice(), into_array![ @@ -77,7 +130,6 @@ mod list_parse { ] ) } - #[test] fn list_pro_max() { let tok = lex_insecure( @@ -91,7 +143,46 @@ mod list_parse { ", ) .unwrap(); - let r = parse_list_full(&tok[1..]).unwrap(); + let r = parse_list_full(&tok[1..], &mut InplaceData::new()).unwrap(); + assert_eq!( + r.as_slice(), + into_array![ + into_array![into_array![1, 1], into_array![2, 2]], + into_array![into_array![], into_array![4, 4]], + into_array![into_array![5, 5], into_array![6, 6]], + into_array![into_array![7, 7], into_array![]], + ] + ) + } + #[test] + fn list_pro_max_param() { + let tok = lex_secure( + b" + [ + [[?, ?], [?, ?]], + [[], [?, ?]], + [[?, ?], [?, ?]], + [[?, ?], []] + ] + ", + ) + .unwrap(); + let data = [ + LitIR::UInt(1), + LitIR::UInt(1), + LitIR::UInt(2), + LitIR::UInt(2), + LitIR::UInt(4), + LitIR::UInt(4), + LitIR::UInt(5), + LitIR::UInt(5), + LitIR::UInt(6), + LitIR::UInt(6), + LitIR::UInt(7), + LitIR::UInt(7), + ]; + let mut param = SubstitutedData::new(&data); + let r = parse_list_full(&tok[1..], &mut param).unwrap(); assert_eq!( r.as_slice(), into_array![ @@ -103,6 +194,7 @@ mod list_parse { ) } } + mod tuple_syntax { use super::*; use crate::engine::ql::dml::parse_data_tuple_syntax_full;