From c0ea7d66d7975759a4c2b6dcae13acfa6b692155 Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Wed, 8 Dec 2010 12:20:00 +0100 Subject: [PATCH] Allow checking variable state in tests, use it in iterations.ccl, explain in example.ccl --- tests/data/example.ccl | 8 ++++++++ tests/data/iterations.ccl | 5 +++++ tests/datadriven.cpp | 19 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/data/example.ccl b/tests/data/example.ccl index bdabf49..3cbd81c 100644 --- a/tests/data/example.ccl +++ b/tests/data/example.ccl @@ -4,6 +4,7 @@ After the --- line comes the first test -- the operator string, followed by an e If the first operator line is "position=XXX", position is parsed as an int and that is used as the current position in the sentence for this and any following tests. Default position is 0. Tests are separated from one another by a --- line. This test loads no sentence, but can change the position anyway. Tagset is kipi by default. +Variable state can be checked by a name=value lines after the expected output. tagset=ikipi --- equal(["aaa"], "aaa") @@ -13,3 +14,10 @@ True lower(["A"]) ["a"] +--- +setvar($b:A, setvar($t:B, subst)) + +True +A=True +B={subst} + diff --git a/tests/data/iterations.ccl b/tests/data/iterations.ccl index 60b5052..f17e4ae 100644 --- a/tests/data/iterations.ccl +++ b/tests/data/iterations.ccl @@ -1,6 +1,11 @@ tagset=kipi +sentence=t01.xml --- rlook(begin, end, $Test, True) True --- +llook(0, end, $V, False) + +False +V=nowhere diff --git a/tests/datadriven.cpp b/tests/datadriven.cpp index 5b62d31..e0ee151 100644 --- a/tests/datadriven.cpp +++ b/tests/datadriven.cpp @@ -98,7 +98,24 @@ void test_one_item_actual(const compare_test& c) expected_output = ""; operator_string = ""; ++line_no; - std::getline(ifs_in, line); + while (ifs_in.good() && line != "---" && line != "") { + std::getline(ifs_in, line); + std::vector<std::string> fields; + boost::algorithm::split(fields, line, boost::is_any_of(separators)); + if (fields.size() == 2) { + boost::shared_ptr<Wccl::Value> v; + v = fu.variables()->get<Wccl::Value>(fields[0]); + if (!v) { + BOOST_ERROR("Invalid variable name in test: " + << fields[0] << " on line " << line_no); + } else if (v->to_string(tagset) != fields[1]) { + BOOST_ERROR("Variable " << fields[0] + << "value mismatch on line " + << line_no << "\n: expected " << fields[1] + << " got " << v->to_string(tagset)); + } + } + } BOOST_REQUIRE(line == "---" || line == ""); } else { if (operator_string.empty() && line.substr(0, 9) == "position=") { -- GitLab