use relate_core::{integer_args, Error};
use super::*;
#[test]
fn float_literals_at_integer_argument_sites_fail_at_plan_time() {
for (src, site) in [
("RETURN range(1.5, 5)", &integer_args::RANGE_START),
("RETURN range(1, 5.9)", &integer_args::RANGE_END),
("RETURN range(1, 10, 2.5)", &integer_args::RANGE_STEP),
("RETURN range(-1.1, 1, 1)", &integer_args::RANGE_START),
(
"RETURN substring('abcdef', 1.5)",
&integer_args::SUBSTRING_START,
),
(
"RETURN substring('abcdef', 1, 2.5)",
&integer_args::SUBSTRING_LENGTH,
),
("RETURN left('abcdef', 2.9)", &integer_args::LEFT_LENGTH),
("RETURN left('abcdef', +2.9)", &integer_args::LEFT_LENGTH),
("RETURN right('abcdef', 2.9)", &integer_args::RIGHT_LENGTH),
("RETURN [1,2,3][1.0]", &integer_args::LIST_INDEX),
("RETURN [1,2,3][1.0..2]", &integer_args::SLICE_START),
("RETURN [1,2,3][1..2.9]", &integer_args::SLICE_END),
] {
let q = parse_and_lower(src)
.unwrap_or_else(|e| panic!("`{src}` must survive the front-end: {e}"));
let error = plan(q, &mut |_| false).expect_err(&format!("`{src}` must fail at plan time"));
assert_eq!(
error,
Error::invalid_argument_type(site.type_error),
"`{src}`"
);
}
}
#[test]
fn non_numeric_literals_at_integer_argument_sites_fail_at_plan_time() {
for (src, site) in [
(
"RETURN substring('abcdef', 'x')",
&integer_args::SUBSTRING_START,
),
(
"RETURN substring('abcdef', 1, 'x')",
&integer_args::SUBSTRING_LENGTH,
),
(
"RETURN substring('abcdef', null, 'x')",
&integer_args::SUBSTRING_LENGTH,
),
(
"RETURN substring('abcdef', true)",
&integer_args::SUBSTRING_START,
),
(
"RETURN substring('abcdef', [1])",
&integer_args::SUBSTRING_START,
),
(
"RETURN substring('abcdef', {a: 1})",
&integer_args::SUBSTRING_START,
),
("RETURN left('abcdef', 'x')", &integer_args::LEFT_LENGTH),
("RETURN right('abcdef', 'x')", &integer_args::RIGHT_LENGTH),
("RETURN range('a', 5)", &integer_args::RANGE_START),
(
"RETURN substring('abcdef', date('2020-01-01'))",
&integer_args::SUBSTRING_START,
),
(
"RETURN range(date('2020-01-01'), 5)",
&integer_args::RANGE_START,
),
] {
let q = parse_and_lower(src)
.unwrap_or_else(|e| panic!("`{src}` must survive the front-end: {e}"));
let error = plan(q, &mut |_| false).expect_err(&format!("`{src}` must fail at plan time"));
assert_eq!(
error,
Error::invalid_argument_type(site.type_error),
"`{src}`"
);
}
for src in [
"RETURN substring('abcdef', null)",
"RETURN substring('abcdef', null, null)",
"RETURN substring('abcdef', 1)",
"RETURN substring('abcdef', -1)",
"RETURN left('abcdef', null)",
] {
let q = parse_and_lower(src)
.unwrap_or_else(|e| panic!("`{src}` must survive the front-end: {e}"));
assert!(plan(q, &mut |_| false).is_ok(), "`{src}` must plan");
}
}
#[test]
fn non_literal_floats_at_integer_argument_sites_plan_fine() {
for src in [
"RETURN range(0.0/0.0, 5)",
"RETURN range(head([1.5, 'x']), 5)",
"RETURN substring('abcdef', head([1.5, 'x']))",
"RETURN left('abcdef', $n)",
"RETURN [1,2,3][head([1.0, 'x'])]",
"RETURN [1,2,3][head([1.5, 'x'])..2]",
"UNWIND [1.5] AS n RETURN range(n, 5)",
] {
let q = parse_and_lower(src)
.unwrap_or_else(|e| panic!("`{src}` must survive the front-end: {e}"));
assert!(plan(q, &mut |_| false).is_ok(), "`{src}` must plan");
}
}