Add tests for secure list parsing

next
Sayan Nandan 2 years ago
parent 16fb7a7d1b
commit 255d058793
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -293,9 +293,12 @@ pub(super) fn parse_list<'a, Qd: QueryData<'a>>(
}
#[cfg(test)]
pub(super) fn parse_list_full(tok: &[Token]) -> Option<Vec<DataType>> {
pub(super) fn parse_list_full<'a>(
tok: &'a [Token],
qd: &mut impl QueryData<'a>,
) -> Option<Vec<DataType>> {
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

@ -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<Vec<Token>> {
InsecureLexer::lex(src)
}
#[inline(always)]
/// Uses the [`SafeLexer`] to lex the given input
pub(super) fn lex_secure(src: &[u8]) -> LangResult<Vec<Token>> {
SafeLexer::lex(src)
}
pub trait NullableData<T> {
fn data(self) -> Option<T>;

@ -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;

Loading…
Cancel
Save