diff options
-rw-r--r-- | tangle/003tangle.cc | 2 | ||||
-rw-r--r-- | tangle/003tangle.test.cc | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tangle/003tangle.cc b/tangle/003tangle.cc index ff9aa56e..5cb80b3e 100644 --- a/tangle/003tangle.cc +++ b/tangle/003tangle.cc @@ -305,6 +305,7 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) { result.push_back(Line(" "+front(lines).contents.substr(strlen("% ")), front(lines))); lines.pop_front(); } + if (lines.empty()) break; result.push_back(input_lines(lines)); if (!lines.empty() && !front(lines).contents.empty() && front(lines).contents[0] == '+') result.push_back(expected_in_trace(lines)); @@ -338,6 +339,7 @@ bool is_input(const string& line) { } Line input_lines(list<Line>& hunk) { + assert(!hunk.empty()); Line result; result.line_number = hunk.front().line_number; result.filename = hunk.front().filename; diff --git a/tangle/003tangle.test.cc b/tangle/003tangle.test.cc index 9c8c4040..45e1f110 100644 --- a/tangle/003tangle.test.cc +++ b/tangle/003tangle.test.cc @@ -220,6 +220,18 @@ void test_tangle_can_hide_warnings_in_scenarios() { CHECK(lines.empty()); } +void test_tangle_can_include_c_code_at_end_of_scenario() { + istringstream in(":(scenario does_bar)\nabc def\n+layer1: pqr\n+layer2: xyz\n% int x = 1;"); + list<Line> lines; + tangle(in, lines); + CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run(\"abc def\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS(\"layer1: pqrlayer2: xyz\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " int x = 1;"); lines.pop_front(); + CHECK_EQ(lines.front().contents, "}"); lines.pop_front(); + CHECK(lines.empty()); +} + void test_tangle_supports_strings_in_scenarios() { istringstream in(":(scenario does_bar)\nabc \"def\"\n+layer1: pqr\n+layer2: \"xyz\""); list<Line> lines; |