From a18f5328ebe8d5cb878c90bf9ca03c1ab864a7d2 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Wed, 25 Jul 2018 14:41:48 -0700 Subject: 4405 --- tangle/003tangle.cc | 27 +++++++++++-------- tangle/003tangle.test.cc | 67 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/tangle/003tangle.cc b/tangle/003tangle.cc index bc67051a..384af5e6 100644 --- a/tangle/003tangle.cc +++ b/tangle/003tangle.cc @@ -310,7 +310,7 @@ void emit_test(const string& name, list& lines, list& result) { lines.pop_front(); } if (lines.empty()) break; - result.push_back(input_lines(lines)); + emit_input_lines(lines, result); emit_expected_in_trace(lines, result); while (!lines.empty() && !front(lines).contents.empty() && front(lines).contents.at(0) == '-') { result.push_back(expected_not_in_trace(front(lines))); @@ -341,17 +341,24 @@ bool is_input(const string& line) { return line != "===" && line.find_first_of("+-$?%") != 0; } -Line input_lines(list& hunk) { +void emit_input_lines(list& hunk, list& out) { assert(!hunk.empty()); - Line result; - result.line_number = hunk.front().line_number; - result.filename = hunk.front().filename; - while (!hunk.empty() && is_input(hunk.front().contents)) { - result.contents += hunk.front().contents+""; // temporary delimiter; replace with escaped newline after escaping other backslashes - hunk.pop_front(); + Line curr_out; + curr_out.line_number = hunk.front().line_number; + curr_out.filename = hunk.front().filename; + curr_out.contents = " "+Toplevel+"("; + out.push_back(curr_out); + for (/*nada*/; !hunk.empty() && is_input(front(hunk).contents); hunk.pop_front()) { + Line curr_out; + curr_out.line_number = front(hunk).line_number; + curr_out.filename = front(hunk).filename; + curr_out.contents = " \""+escape(front(hunk).contents+'')+"\""; + out.push_back(curr_out); } - result.contents = " "+Toplevel+"(\""+escape(result.contents)+"\");"; - return result; + curr_out.line_number = out.back().line_number; + curr_out.filename = out.back().filename; + curr_out.contents = " );"; + out.push_back(curr_out); } // pull lines starting with '+' out of 'hunk', and append translated lines to 'out' diff --git a/tangle/003tangle.test.cc b/tangle/003tangle.test.cc index 606e6fc9..4a1dc8de 100644 --- a/tangle/003tangle.test.cc +++ b/tangle/003tangle.test.cc @@ -363,7 +363,9 @@ void test_tangle_supports_scenarios() { list 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, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: xyz\""); lines.pop_front(); @@ -381,7 +383,9 @@ void test_tangle_ignores_empty_lines_in_scenarios() { list 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, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: xyz\""); lines.pop_front(); @@ -409,7 +413,9 @@ void test_tangle_supports_configurable_toplevel() { list lines; tangle(in, lines); CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); - CHECK_EQ(lines.front().contents, " foo(\"abc def\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " foo("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); @@ -430,7 +436,9 @@ void test_tangle_can_hide_warnings_in_scenarios() { tangle(in, lines); CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); CHECK_EQ(lines.front().contents, " Hide_warnings = true;"); lines.pop_front(); - CHECK_EQ(lines.front().contents, " run(\"abc def\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: xyz\""); lines.pop_front(); @@ -448,7 +456,9 @@ void test_tangle_can_include_c_code_at_end_of_scenario() { list 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, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: xyz\""); lines.pop_front(); @@ -465,7 +475,9 @@ void test_tangle_can_include_c_code_at_end_of_scenario_without_trace_expectation list 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, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); 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()); @@ -479,7 +491,9 @@ void test_tangle_supports_strings_in_scenarios() { list 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, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc \\\"def\\\"\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: \\\"xyz\\\"\""); lines.pop_front(); @@ -496,7 +510,9 @@ void test_tangle_supports_strings_in_scenarios2() { list lines; tangle(in, lines); CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); - CHECK_EQ(lines.front().contents, " run(\"abc \\\"\\\"\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc \\\"\\\"\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: \\\"\\\"\""); lines.pop_front(); @@ -514,7 +530,10 @@ void test_tangle_supports_multiline_input_in_scenarios() { list 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 efg\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \" efg\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: \\\"\\\"\""); lines.pop_front(); @@ -533,9 +552,13 @@ void test_tangle_supports_reset_in_scenarios() { list 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, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CLEAR_TRACE;"); lines.pop_front(); - CHECK_EQ(lines.front().contents, " run(\"efg\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"efg\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer2: \\\"\\\"\""); lines.pop_front(); @@ -555,7 +578,10 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios() { //? for (list::iterator p = lines.begin(); p != lines.end(); ++p) //? cerr << p->contents << '\n'; CHECK_EQ(lines.front().contents, "void test_does_bar() {"); lines.pop_front(); - CHECK_EQ(lines.front().contents, " run(\"abc def\\n efg\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \" efg\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); @@ -573,7 +599,10 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios2() { list 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 efg\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \" efg\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_DOESNT_CONTAIN(\"layer1: pqr\");"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_DOESNT_CONTAIN(\"layer1: xyz\");"); lines.pop_front(); CHECK_EQ(lines.front().contents, "}"); lines.pop_front(); @@ -588,7 +617,10 @@ void test_tangle_can_check_for_count_in_scenario() { list 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 efg\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \" efg\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_COUNT(\"layer1\", 2);"); lines.pop_front(); CHECK_EQ(lines.front().contents, "}"); lines.pop_front(); CHECK(lines.empty()); @@ -612,7 +644,12 @@ void test_tangle_can_handle_mu_comments_in_scenario() { list 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# comment1\\n efg\\n # indented comment 2\\n\");"); lines.pop_front(); + CHECK_EQ(lines.front().contents, " run("); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"abc def\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \"# comment1\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \" efg\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " \" # indented comment 2\\n\""); lines.pop_front(); + CHECK_EQ(lines.front().contents, " );"); lines.pop_front(); CHECK_EQ(lines.front().contents, " CHECK_TRACE_CONTENTS("); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: pqr\""); lines.pop_front(); CHECK_EQ(lines.front().contents, " \"layer1: xyz\""); lines.pop_front(); -- cgit 1.4.1-2-gfad0