From 3f83393ac45b2987d8a1bf142747a6a0c261350d Mon Sep 17 00:00:00 2001 From: Ambroz Bizjak Date: Sat, 8 Nov 2014 21:50:13 +0100 Subject: [PATCH] ncd: tests: Add basic_functions tests. --- ncd/tests/basic_functions.ncd | 238 ++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 ncd/tests/basic_functions.ncd diff --git a/ncd/tests/basic_functions.ncd b/ncd/tests/basic_functions.ncd new file mode 100644 index 000000000..c2f5b82c1 --- /dev/null +++ b/ncd/tests/basic_functions.ncd @@ -0,0 +1,238 @@ +process main { + var(@identity("Foo")) x; + val_equal(x, "Foo") a; + assert(a); + + + var(@if("true", "T", "F")) x; + val_equal(x, "T") a; + assert(a); + + var(@if("ntrue", "T", "F")) x; + val_equal(x, "F") a; + assert(a); + + + var(@bool("ntrue")) x; + assert_false(x); + + var(@bool("true")) x; + assert(x); + + + var(@not("ntrue")) x; + assert(x); + + var(@not("true")) x; + assert_false(x); + + + + var(@and("ntrue")) x; + assert_false(x); + + var(@and("true")) x; + assert(x); + + var(@and("ntrue", "ntrue")) x; + assert_false(x); + + var(@and("ntrue", "true")) x; + assert_false(x); + + var(@and("true", "ntrue")) x; + assert_false(x); + + var(@and("true", "true")) x; + assert(x); + + + var(@or("ntrue")) x; + assert_false(x); + + var(@or("true")) x; + assert(x); + + var(@or("ntrue", "ntrue")) x; + assert_false(x); + + var(@or("ntrue", "true")) x; + assert(x); + + var(@or("true", "ntrue")) x; + assert(x); + + var(@or("true", "true")) x; + assert(x); + + + var(@imp("ntrue", "ntrue")) x; + assert(x); + + var(@imp("ntrue", "true")) x; + assert(x); + + var(@imp("true", "ntrue")) x; + assert_false(x); + + var(@imp("true", "true")) x; + assert(x); + + + var(@val_lesser("B", "A")) x; + assert_false(x); + + var(@val_lesser("B", "B")) x; + assert_false(x); + + var(@val_lesser("B", "C")) x; + assert(x); + + + var(@val_greater("B", "A")) x; + assert(x); + + var(@val_greater("B", "B")) x; + assert_false(x); + + var(@val_greater("B", "C")) x; + assert_false(x); + + + var(@val_lesser_equal("B", "A")) x; + assert_false(x); + + var(@val_lesser_equal("B", "B")) x; + assert(x); + + var(@val_lesser_equal("B", "C")) x; + assert(x); + + + var(@val_greater_equal("B", "A")) x; + assert(x); + + var(@val_greater_equal("B", "B")) x; + assert(x); + + var(@val_greater_equal("B", "C")) x; + assert_false(x); + + + var(@val_equal("B", "A")) x; + assert_false(x); + + var(@val_equal("B", "B")) x; + assert(x); + + var(@val_equal("B", "C")) x; + assert_false(x); + + + var(@val_different("B", "A")) x; + assert(x); + + var(@val_different("B", "B")) x; + assert_false(x); + + var(@val_different("B", "C")) x; + assert(x); + + + var(@concat("Foo", "Bar", {"Baaz", "Qux", {"M"}})) x; + val_equal(x, "FooBarBaazQuxM") a; + assert(a); + + + var(@concatlist({"A"}, {}, {{}, []})) x; + val_equal(x, {"A", {}, []}) a; + assert(a); + + + var(@num_lesser("10", "9")) x; + assert_false(x); + + var(@num_lesser("10", "10")) x; + assert_false(x); + + var(@num_lesser("10", "11")) x; + assert(x); + + + var(@num_greater("10", "9")) x; + assert(x); + + var(@num_greater("10", "10")) x; + assert_false(x); + + var(@num_greater("10", "11")) x; + assert_false(x); + + + var(@num_lesser_equal("10", "9")) x; + assert_false(x); + + var(@num_lesser_equal("10", "10")) x; + assert(x); + + var(@num_lesser_equal("10", "11")) x; + assert(x); + + + var(@num_greater_equal("10", "9")) x; + assert(x); + + var(@num_greater_equal("10", "10")) x; + assert(x); + + var(@num_greater_equal("10", "11")) x; + assert_false(x); + + + var(@num_equal("10", "9")) x; + assert_false(x); + + var(@num_equal("10", "10")) x; + assert(x); + + var(@num_equal("10", "11")) x; + assert_false(x); + + + var(@num_different("10", "9")) x; + assert(x); + + var(@num_different("10", "10")) x; + assert_false(x); + + var(@num_different("10", "11")) x; + assert(x); + + + var(@num_add("6", "14")) x; + val_equal(x, "20") a; + assert(a); + + + var(@num_subtract("30", "3")) x; + val_equal(x, "27") a; + assert(a); + + + var(@num_multiply("62", "2")) x; + val_equal(x, "124") a; + assert(a); + + + var(@num_divide("31", "15")) x; + val_equal(x, "2") a; + assert(a); + + + var(@num_modulo("31", "15")) x; + val_equal(x, "1") a; + assert(a); + + + exit("0"); +}