about summary refs log tree commit diff stats
path: root/cpp/tangle
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-04-28 22:45:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-04-28 22:55:04 -0700
commitc51043abdf83243f81685858d8f76793faed042b (patch)
tree362afefaa547dc1f8dd490947056a558d5fe3b17 /cpp/tangle
parente3fa6cc7af792a6c0d83d9004859d6e9452c5fdb (diff)
downloadmu-c51043abdf83243f81685858d8f76793faed042b.tar.gz
1217 - string literals weren't handling later comments
Diffstat (limited to 'cpp/tangle')
-rw-r--r--cpp/tangle/030tangle.cc15
-rw-r--r--cpp/tangle/030tangle.test.cc11
2 files changed, 25 insertions, 1 deletions
diff --git a/cpp/tangle/030tangle.cc b/cpp/tangle/030tangle.cc
index 872b4d9d..8a107fc0 100644
--- a/cpp/tangle/030tangle.cc
+++ b/cpp/tangle/030tangle.cc
@@ -267,6 +267,7 @@ list<Line>::iterator balancing_curly(list<Line>::iterator curr) {
 //  followed by a return value ('=>')
 //  followed by one or more lines expected in trace in order ('+')
 //  followed by one or more lines trace shouldn't include ('-')
+//  followed by one or more lines expressing counts of specific layers emitted in trace ('$')
 // Remember to update is_input below if you add to this format.
 void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
   Line tmp;
@@ -294,6 +295,18 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
       result.push_back(expected_not_in_trace(front(lines)));
       lines.pop_front();
     }
+    if (!lines.empty() && front(lines).contents[0] == '$') {
+      const string& in = front(lines).contents;
+      size_t pos = in.find(": ");
+      string layer = in.substr(1, pos-1);
+      string count = in.substr(pos+2);
+      Line tmp;
+      tmp.line_number = front(lines).line_number;
+      tmp.filename = front(lines).filename;
+      tmp.contents = "  CHECK_EQ(trace_count(\""+layer+"\"), "+count+");";
+      result.push_back(tmp);
+      lines.pop_front();
+    }
     if (!lines.empty() && front(lines).contents == "===") {
       Line tmp;
       tmp.line_number = front(lines).line_number;
@@ -330,7 +343,7 @@ void emit_test(const string& name, list<Line>& lines, list<Line>& result) {
 
 bool is_input(const string& line) {
   if (line.empty()) return true;
-  return line != "===" && line[0] != '+' && line[0] != '-' && !starts_with(line, "=>");
+  return line != "===" && line[0] != '+' && line[0] != '-' && !starts_with(line, "=>") && line[0] != '$' && line[0] != '?';
 }
 
 Line input_lines(list<Line>& hunk) {
diff --git a/cpp/tangle/030tangle.test.cc b/cpp/tangle/030tangle.test.cc
index d97981dc..ea1b9c2b 100644
--- a/cpp/tangle/030tangle.test.cc
+++ b/cpp/tangle/030tangle.test.cc
@@ -280,6 +280,17 @@ void test_tangle_can_check_for_absence_at_end_of_scenarios2() {
   CHECK(lines.empty());
 }
 
+void test_tangle_can_check_for_count_in_scenario() {
+  istringstream in(":(scenario does_bar)\nabc def\n  efg\n$layer1: 2");
+  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_EQ(trace_count(\"layer1\"), 2);");  lines.pop_front();
+  CHECK_EQ(lines.front().contents, "}");  lines.pop_front();
+  CHECK(lines.empty());
+}
+
 
 
 void test_trim() {