about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--cpp/013literal_string.cc1
-rw-r--r--cpp/tangle/030tangle.cc39
-rw-r--r--cpp/tangle/030tangle.test.cc13
3 files changed, 38 insertions, 15 deletions
diff --git a/cpp/013literal_string.cc b/cpp/013literal_string.cc
index 203859e1..c709f58f 100644
--- a/cpp/013literal_string.cc
+++ b/cpp/013literal_string.cc
@@ -74,4 +74,5 @@ recipe main [
 +parse: instruction: 1
 +parse:   ingredient: {name: "abc", value: 0, type: 0, properties: ["abc": "literal-string"]}
 +parse:   product: {name: "1", value: 0, type: 2-5-4, properties: ["1": "address":"array":"character"]}
+# no other ingredients
 $parse: 3
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc
index f4b22f2b..944b12ef 100644
--- a/cpp/tangle/030tangle.cc
+++ b/cpp/tangle/030tangle.cc
@@ -95,26 +95,35 @@ void tangle(istream& in, list<Line>& out) {
 }
 
 void process_next_hunk(istream& in, const string& directive, const string& filename, size_t& line_number, list<Line>& out) {
+  istringstream directive_stream(directive.substr(2));  // length of ":("
+  string cmd = next_tangle_token(directive_stream);
+
+  // first slurp all lines until next directive
   list<Line> hunk;
-  string curr_line;
-  while (!in.eof()) {
-    std::streampos old = in.tellg();
-    getline(in, curr_line);
-    if (starts_with(curr_line, ":(")) {
-      in.seekg(old);
-      break;
-    }
-    if (starts_with(curr_line, "//:")) {
+  {
+    string curr_line;
+    while (!in.eof()) {
+      std::streampos old = in.tellg();
+      getline(in, curr_line);
+      if (starts_with(curr_line, ":(")) {
+        in.seekg(old);
+        break;
+      }
+      if (starts_with(curr_line, "//:")) {
+        // tangle comments
+        ++line_number;
+        continue;
+      }
+      if (cmd == "scenario" && starts_with(curr_line, "#")) {
+        // scenarios can contain mu comments
+        ++line_number;
+        continue;
+      }
+      hunk.push_back(Line(curr_line, filename, line_number));
       ++line_number;
-      continue;
     }
-    hunk.push_back(Line(curr_line, filename, line_number));
-    ++line_number;
   }
 
-  istringstream directive_stream(directive.substr(2));  // length of ":("
-  string cmd = next_tangle_token(directive_stream);
-
   if (cmd == "code") {
     out.insert(out.end(), hunk.begin(), hunk.end());
     return;
diff --git a/cpp/tangle/030tangle.test.cc b/cpp/tangle/030tangle.test.cc
index ea1b9c2b..9ea0353d 100644
--- a/cpp/tangle/030tangle.test.cc
+++ b/cpp/tangle/030tangle.test.cc
@@ -291,6 +291,19 @@ void test_tangle_can_check_for_count_in_scenario() {
   CHECK(lines.empty());
 }
 
+void test_tangle_can_handle_mu_comments_in_scenario() {
+  istringstream in(":(scenario does_bar)\nabc def\n# comment1\n  efg\n  # indented comment 2\n+layer1: pqr\n# comment inside expected_trace\n+layer1: xyz\n# comment after expected trace\n-layer1: z\n# comment before trace count\n$layer1: 2\n# comment at end\n\n");
+  list<Line> lines;
+  tangle(in, lines);
+  CHECK_EQ(lines.front().contents, "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, "  CHECK_TRACE_CONTENTS(\"layer1: pqrlayer1: xyz\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_TRACE_DOESNT_CONTAIN(\"layer1: z\");");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "  CHECK_EQ(trace_count(\"layer1\"), 2);");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
+  CHECK(lines.empty());
+}
+
 
 
 void test_trim() {