about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-09-10 16:16:15 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-09-10 16:16:15 -0700
commite7f239014819c2b401c825650091bd5b55d0a679 (patch)
tree08c17266ba68b7978c9b10496ff4d567c7ff7b25
parent65c119d4cc4838660adb1ffb3fb264fe1bcfc6f8 (diff)
downloadmu-e7f239014819c2b401c825650091bd5b55d0a679.tar.gz
3320
-rw-r--r--071recipe.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/071recipe.cc b/071recipe.cc
index b6fb8654..026af6f4 100644
--- a/071recipe.cc
+++ b/071recipe.cc
@@ -189,15 +189,17 @@ recipe from_reagent(const reagent& r) {
   for (/*nada*/; curr && !curr->atom; curr = curr->right) {
     if (curr->left->atom && curr->left->name == "->") {
       curr = curr->right;  // skip delimiter
-      break;
+      goto read_products;
     }
     result_header.ingredients.push_back(next_recipe_reagent(curr->left));
-    if (curr->right && curr->right->atom) {
-      result_header.ingredients.push_back(next_recipe_reagent(curr->right));
-      return result_header;  // no products
-    }
   }
-  for (; curr && !curr->atom; curr=curr->right)
+  if (curr) {
+    assert(curr->atom);
+    result_header.ingredients.push_back(next_recipe_reagent(curr));
+    return result_header;  // no products
+  }
+  read_products:
+  for (/*nada*/; curr && !curr->atom; curr=curr->right)
     result_header.products.push_back(next_recipe_reagent(curr->left));
   if (curr) {
     assert(curr->atom);
@@ -225,6 +227,12 @@ void test_from_reagent_reads_ingredient_at_end() {
   CHECK_EQ(SIZE(r_header.ingredients), 2);
   CHECK(r_header.products.empty());
 }
+void test_from_reagent_reads_sole_ingredient_at_end() {
+  reagent a("{f: (recipe number)}");
+  recipe r_header = from_reagent(a);
+  CHECK_EQ(SIZE(r_header.ingredients), 1);
+  CHECK(r_header.products.empty());
+}
 
 :(code)
 reagent next_recipe_reagent(const type_tree* curr) {