use super::framework::*;
use super::helpers::*;
fn runner() -> ConformanceTestRunner {
ConformanceTestRunner::new()
}
#[test]
fn test_str_fn_01_str_of_iri() {
let ds = InMemoryDataset::new();
let algebra = project(
extend(
bgp(vec![]),
variable("result"),
expr_fn("str", vec![expr_iri("http://example.org/alice")]),
),
vec![variable("result")],
);
let test = ConformanceTest::new(
"str-fn-01",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(0), );
runner().run_test(&test).expect("str-fn-01 failed");
}
#[test]
fn test_str_fn_02_str_filter() {
let ds = person_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), foaf("name"), var("name"))]),
expr_eq(
expr_fn("str", vec![expr_var("s")]),
expr_lit(lit_str("http://example.org/alice")),
),
),
vec![variable("name")],
);
let test = ConformanceTest::new(
"str-fn-02",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::SelectResults(vec![row(&[("name", "Alice")])]),
);
runner().run_test(&test).expect("str-fn-02 failed");
}
#[test]
fn test_str_fn_03_lang_filter() {
let mut ds = InMemoryDataset::new();
ds.add_triple(ex("r1"), ex("label"), lang_lit("Hello", "en"));
ds.add_triple(ex("r2"), ex("label"), lang_lit("Bonjour", "fr"));
ds.add_triple(ex("r3"), ex("label"), lang_lit("Hi", "en"));
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("label"), var("label"))]),
expr_eq(
expr_fn("lang", vec![expr_var("label")]),
expr_lit(lit_str("en")),
),
),
vec![variable("s")],
);
let test = ConformanceTest::new(
"str-fn-03",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(2), );
runner().run_test(&test).expect("str-fn-03 failed");
}
#[test]
fn test_str_fn_04_datatype_filter() {
let ds = numeric_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("value"), var("v"))]),
expr_eq(
expr_fn("datatype", vec![expr_var("v")]),
expr_iri("http://www.w3.org/2001/XMLSchema#integer"),
),
),
vec![variable("s"), variable("v")],
);
let test = ConformanceTest::new(
"str-fn-04",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(5), );
runner().run_test(&test).expect("str-fn-04 failed");
}
#[test]
fn test_str_fn_05_isiri_check() {
let ds = person_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), foaf("name"), var("name"))]),
Expression::Unary {
op: crate::algebra::UnaryOperator::IsIri,
operand: Box::new(expr_var("s")),
},
),
vec![variable("s")],
);
let test = ConformanceTest::new(
"str-fn-05",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(3),
);
runner().run_test(&test).expect("str-fn-05 failed");
}
#[test]
fn test_str_fn_06_isliteral_check() {
let ds = person_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), foaf("name"), var("name"))]),
Expression::Unary {
op: crate::algebra::UnaryOperator::IsLiteral,
operand: Box::new(expr_var("name")),
},
),
vec![variable("name")],
);
let test = ConformanceTest::new(
"str-fn-06",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(3),
);
runner().run_test(&test).expect("str-fn-06 failed");
}
#[test]
fn test_str_fn_07_isblank_check() {
let mut ds = InMemoryDataset::new();
ds.add_triple(
crate::algebra::Term::BlankNode("b1".to_string()),
ex("p"),
str_lit("blank subject"),
);
ds.add_triple(ex("iri"), ex("p"), str_lit("iri subject"));
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("p"), var("o"))]),
Expression::Unary {
op: crate::algebra::UnaryOperator::IsBlank,
operand: Box::new(expr_var("s")),
},
),
vec![variable("s")],
);
let test = ConformanceTest::new(
"str-fn-07",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(1),
);
runner().run_test(&test).expect("str-fn-07 failed");
}
#[test]
fn test_str_fn_08_isnumeric_check() {
let mut ds = InMemoryDataset::new();
ds.add_triple(ex("r1"), ex("val"), int_lit(42));
ds.add_triple(ex("r2"), ex("val"), str_lit("hello"));
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("val"), var("v"))]),
Expression::Unary {
op: crate::algebra::UnaryOperator::IsNumeric,
operand: Box::new(expr_var("v")),
},
),
vec![variable("s")],
);
let test = ConformanceTest::new(
"str-fn-08",
ConformanceGroup::StringFunctions,
algebra,
ds,
ConformanceResult::ResultCount(1), );
runner().run_test(&test).expect("str-fn-08 failed");
}
#[test]
fn test_math_fn_01_add() {
let ds = person_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), foaf("name"), var("name"))]),
expr_eq(
Expression::Binary {
op: BinaryOperator::Add,
left: Box::new(expr_lit(lit_int(10))),
right: Box::new(expr_lit(lit_int(5))),
},
expr_lit(lit_int(15)),
),
),
vec![variable("s")],
);
let test = ConformanceTest::new(
"math-fn-01",
ConformanceGroup::MathFunctions,
algebra,
ds,
ConformanceResult::ResultCount(3), );
runner().run_test(&test).expect("math-fn-01 failed");
}
#[test]
fn test_math_fn_02_subtract() {
let ds = person_dataset();
let algebra = project(
filter(
bgp(vec![triple(
var("s"),
iri(&format!("{FOAF}age")),
var("age"),
)]),
expr_gt(
Expression::Binary {
op: BinaryOperator::Subtract,
left: Box::new(expr_var("age")),
right: Box::new(expr_lit(lit_int(5))),
},
expr_lit(lit_int(25)),
),
),
vec![variable("s"), variable("age")],
);
let test = ConformanceTest::new(
"math-fn-02",
ConformanceGroup::MathFunctions,
algebra,
ds,
ConformanceResult::ResultCount(1), );
runner().run_test(&test).expect("math-fn-02 failed");
}
#[test]
fn test_math_fn_03_multiply() {
let ds = numeric_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("value"), var("v"))]),
expr_gt(
Expression::Binary {
op: BinaryOperator::Multiply,
left: Box::new(expr_var("v")),
right: Box::new(expr_lit(lit_int(2))),
},
expr_lit(lit_int(30)),
),
),
vec![variable("s"), variable("v")],
);
let test = ConformanceTest::new(
"math-fn-03",
ConformanceGroup::MathFunctions,
algebra,
ds,
ConformanceResult::ResultCount(3), );
runner().run_test(&test).expect("math-fn-03 failed");
}
#[test]
fn test_math_fn_04_divide() {
let ds = numeric_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("value"), var("v"))]),
expr_gt(
Expression::Binary {
op: BinaryOperator::Divide,
left: Box::new(expr_var("v")),
right: Box::new(expr_lit(lit_int(5))),
},
expr_lit(lit_int(3)),
),
),
vec![variable("s"), variable("v")],
);
let test = ConformanceTest::new(
"math-fn-04",
ConformanceGroup::MathFunctions,
algebra,
ds,
ConformanceResult::ResultCount(3),
);
runner().run_test(&test).expect("math-fn-04 failed");
}
#[test]
fn test_math_fn_05_comparison_chain() {
let ds = person_dataset();
let algebra = project(
filter(
bgp(vec![triple(
var("s"),
iri(&format!("{FOAF}age")),
var("age"),
)]),
expr_and(
expr_gt(expr_var("age"), expr_lit(lit_int(20))),
expr_lt(expr_var("age"), expr_lit(lit_int(36))),
),
),
vec![variable("s"), variable("age")],
);
let test = ConformanceTest::new(
"math-fn-05",
ConformanceGroup::MathFunctions,
algebra,
ds,
ConformanceResult::ResultCount(3), );
runner().run_test(&test).expect("math-fn-05 failed");
}
#[test]
fn test_type_01_integer_literal() {
let ds = typed_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("r"), ex("intVal"), var("v"))]),
Expression::Unary {
op: crate::algebra::UnaryOperator::IsNumeric,
operand: Box::new(expr_var("v")),
},
),
vec![variable("r"), variable("v")],
);
let test = ConformanceTest::new(
"type-01",
ConformanceGroup::TypeSystem,
algebra,
ds,
ConformanceResult::ResultCount(2), );
runner().run_test(&test).expect("type-01 failed");
}
#[test]
fn test_type_02_string_literal() {
let ds = typed_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("r"), ex("strVal"), var("v"))]),
Expression::Unary {
op: crate::algebra::UnaryOperator::IsLiteral,
operand: Box::new(expr_var("v")),
},
),
vec![variable("r"), variable("v")],
);
let test = ConformanceTest::new(
"type-02",
ConformanceGroup::TypeSystem,
algebra,
ds,
ConformanceResult::ResultCount(1), );
runner().run_test(&test).expect("type-02 failed");
}
#[test]
fn test_type_03_boolean_literal() {
let ds = typed_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("r"), ex("boolVal"), var("v"))]),
expr_eq(
expr_fn("datatype", vec![expr_var("v")]),
expr_iri("http://www.w3.org/2001/XMLSchema#boolean"),
),
),
vec![variable("r"), variable("v")],
);
let test = ConformanceTest::new(
"type-03",
ConformanceGroup::TypeSystem,
algebra,
ds,
ConformanceResult::ResultCount(1),
);
runner().run_test(&test).expect("type-03 failed");
}
#[test]
fn test_type_04_numeric_comparison() {
let ds = numeric_dataset();
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("value"), var("v"))]),
expr_gt(expr_var("v"), expr_lit(lit_int(0))),
),
vec![variable("s"), variable("v")],
);
let test = ConformanceTest::new(
"type-04",
ConformanceGroup::TypeSystem,
algebra,
ds,
ConformanceResult::ResultCount(5), );
runner().run_test(&test).expect("type-04 failed");
}
#[test]
fn test_type_05_negative_number() {
let mut ds = InMemoryDataset::new();
ds.add_triple(
ex("r1"),
ex("val"),
crate::algebra::Term::Literal(crate::algebra::Literal {
value: "-5".to_string(),
language: None,
datatype: Some(oxirs_core::model::NamedNode::new_unchecked(
"http://www.w3.org/2001/XMLSchema#integer",
)),
}),
);
ds.add_triple(ex("r2"), ex("val"), int_lit(10));
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("val"), var("v"))]),
expr_lt(expr_var("v"), expr_lit(lit_int(0))),
),
vec![variable("s"), variable("v")],
);
let test = ConformanceTest::new(
"type-05",
ConformanceGroup::TypeSystem,
algebra,
ds,
ConformanceResult::ResultCount(1), );
runner().run_test(&test).expect("type-05 failed");
}
#[test]
fn test_type_06_lang_tagged() {
let mut ds = InMemoryDataset::new();
ds.add_triple(ex("a"), ex("label"), lang_lit("Hello", "en"));
ds.add_triple(ex("b"), ex("label"), lang_lit("Bonjour", "fr"));
let algebra = project(
filter(
bgp(vec![triple(var("s"), ex("label"), var("label"))]),
expr_eq(
expr_fn("lang", vec![expr_var("label")]),
expr_lit(lit_str("fr")),
),
),
vec![variable("s")],
);
let test = ConformanceTest::new(
"type-06",
ConformanceGroup::TypeSystem,
algebra,
ds,
ConformanceResult::ResultCount(1), );
runner().run_test(&test).expect("type-06 failed");
}