mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-23 18:29:50 -04:00
TESTS: Add a whole raft of integration tests.
* Integrate them into the build::comopile_test module as well.
This commit is contained in:
parent
9fdc845e77
commit
b87d75c5c7
56
integration_tests/comparisons_test.ucg
Normal file
56
integration_tests/comparisons_test.ucg
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Simple Comparisons
|
||||||
|
let one = 1;
|
||||||
|
let two = 2;
|
||||||
|
let foo = "foo";
|
||||||
|
let bar = "bar";
|
||||||
|
let tpl1 = {
|
||||||
|
foo = "bar",
|
||||||
|
one = 1
|
||||||
|
};
|
||||||
|
let tpl2 = tpl1{};
|
||||||
|
let tpl3 = {
|
||||||
|
bar = "foo",
|
||||||
|
two = 1
|
||||||
|
};
|
||||||
|
let list = [1, 2, 3];
|
||||||
|
let list2 = list;
|
||||||
|
let list3 = [1, 2];
|
||||||
|
|
||||||
|
assert "one == one";
|
||||||
|
assert "one == one";
|
||||||
|
assert "one >= one";
|
||||||
|
assert "two > one";
|
||||||
|
assert "two >= two";
|
||||||
|
assert "tpl1 == tpl2";
|
||||||
|
assert "tpl1 != tpl3";
|
||||||
|
assert "list == list2";
|
||||||
|
assert "list != list3";
|
||||||
|
|
||||||
|
// Deep Comparisons
|
||||||
|
let tpl4 = {
|
||||||
|
foo = "bar",
|
||||||
|
lst = [1, 2, 3],
|
||||||
|
inner = {
|
||||||
|
fld = "value",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let copy = tpl4;
|
||||||
|
let extra = tpl4{one = 1};
|
||||||
|
let less = {
|
||||||
|
foo = "bar"
|
||||||
|
};
|
||||||
|
|
||||||
|
assert "tpl4.inner == copy.inner";
|
||||||
|
assert "tpl4.inner.fld == copy.inner.fld";
|
||||||
|
assert "tpl4.lst == copy.lst";
|
||||||
|
assert "tpl4.foo == copy.foo";
|
||||||
|
assert "tpl4 == copy";
|
||||||
|
assert "tpl4 != extra";
|
||||||
|
assert "tpl4 != less";
|
||||||
|
|
||||||
|
// Expression comparisons
|
||||||
|
assert "2 == 1+1";
|
||||||
|
assert "(1+1) == 2";
|
||||||
|
assert "(1+1) == (1+1)";
|
||||||
|
let want = "foo";
|
||||||
|
assert "select want, 1, { foo=2, } == 2";
|
5
integration_tests/empty_test.ucg
Normal file
5
integration_tests/empty_test.ucg
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
let empty = NULL;
|
||||||
|
let tpl = {
|
||||||
|
foo = NULL,
|
||||||
|
};
|
||||||
|
assert "tpl.foo == empty";
|
7
integration_tests/operator_precedence_test.ucg
Normal file
7
integration_tests/operator_precedence_test.ucg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
assert "2 * 2 + 1 == 5";
|
||||||
|
assert "2 + 2 * 3 == 8";
|
||||||
|
assert "2 * (2 + 1) == 6";
|
||||||
|
assert "2 * 2 + 1 > 4";
|
||||||
|
assert "2 * 2 + 1 > 6";
|
||||||
|
assert "2 * 2 + 1 >= 5";
|
||||||
|
assert "2 * 2 + 1 <= 5";
|
@ -30,97 +30,27 @@ fn assert_build(input: &str) {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_comparisons() {
|
fn test_comparisons() {
|
||||||
assert_build(
|
assert_build(include_str!("../../integration_tests/comparisons_test.ucg"));
|
||||||
"let one = 1;
|
}
|
||||||
let two = 2;
|
|
||||||
let foo = \"foo\";
|
#[test]
|
||||||
let bar = \"bar\";
|
fn test_macros() {
|
||||||
let tpl1 = {
|
assert_build(include_str!("../../integration_tests/macros_test.ucg"));
|
||||||
foo = \"bar\",
|
}
|
||||||
one = 1
|
|
||||||
};
|
#[test]
|
||||||
let tpl2 = tpl1{};
|
fn test_selectors() {
|
||||||
let tpl3 = {
|
assert_build(include_str!("../../integration_tests/selectors_test.ucg"));
|
||||||
bar = \"foo\",
|
|
||||||
two = 1
|
|
||||||
};
|
|
||||||
let list = [1, 2, 3];
|
|
||||||
let list2 = list;
|
|
||||||
let list3 = [1, 2];
|
|
||||||
assert \"one == one\";
|
|
||||||
assert \"one == one\";
|
|
||||||
assert \"one >= one\";
|
|
||||||
assert \"two > one\";
|
|
||||||
assert \"two >= two\";
|
|
||||||
assert \"tpl1 == tpl2\";
|
|
||||||
assert \"tpl1 != tpl3\";
|
|
||||||
assert \"list == list2\";
|
|
||||||
assert \"list != list3\";
|
|
||||||
",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_value() {
|
fn test_empty_value() {
|
||||||
assert_build(
|
assert_build(include_str!("../../integration_tests/empty_test.ucg"));
|
||||||
"let empty = NULL;
|
|
||||||
let tpl = {
|
|
||||||
foo = NULL,
|
|
||||||
};
|
|
||||||
assert \"tpl.foo == empty\";
|
|
||||||
",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_deep_comparison() {
|
|
||||||
assert_build(
|
|
||||||
"let tpl1 = {
|
|
||||||
foo = \"bar\",
|
|
||||||
lst = [1, 2, 3],
|
|
||||||
inner = {
|
|
||||||
fld = \"value\",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let copy = tpl1;
|
|
||||||
let extra = tpl1{one = 1};
|
|
||||||
let less = {
|
|
||||||
foo = \"bar\"
|
|
||||||
};
|
|
||||||
assert \"tpl1.inner == copy.inner\";
|
|
||||||
assert \"tpl1.inner.fld == copy.inner.fld\";
|
|
||||||
assert \"tpl1.lst == copy.lst\";
|
|
||||||
assert \"tpl1.foo == copy.foo\";
|
|
||||||
assert \"tpl1 == copy\";
|
|
||||||
assert \"tpl1 != extra\";
|
|
||||||
assert \"tpl1 != less\";
|
|
||||||
",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_expression_comparisons() {
|
|
||||||
assert_build("assert \"2 == 1+1\";");
|
|
||||||
assert_build("assert \"(1+1) == 2\";");
|
|
||||||
assert_build("assert \"(1+1) == (1+1)\";");
|
|
||||||
assert_build(
|
|
||||||
"let want = \"foo\";
|
|
||||||
assert \"select want, 1, { foo=2, } == 2\";",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_binary_operator_precedence() {
|
fn test_binary_operator_precedence() {
|
||||||
assert_build(
|
assert_build(include_str!(
|
||||||
"let result = 2 * 2 + 1;
|
"../../integration_tests/operator_precedence_test.ucg"
|
||||||
assert \"result == 5\";",
|
));
|
||||||
);
|
|
||||||
assert_build(
|
|
||||||
"let result = 2 + 2 * 3;
|
|
||||||
assert \"result == 8\";",
|
|
||||||
);
|
|
||||||
assert_build(
|
|
||||||
"let result = 2 * (2 + 1);
|
|
||||||
assert \"result == 6\";",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user