about summary refs log tree commit diff stats
path: root/html/071recipe.cc.html
diff options
context:
space:
mode:
Diffstat (limited to 'html/071recipe.cc.html')
-rw-r--r--html/071recipe.cc.html48
1 files changed, 40 insertions, 8 deletions
diff --git a/html/071recipe.cc.html b/html/071recipe.cc.html
index 47204f71..56f55901 100644
--- a/html/071recipe.cc.html
+++ b/html/071recipe.cc.html
@@ -212,22 +212,29 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa
 <span class="Delimiter">}</span>
 
 recipe from_reagent<span class="Delimiter">(</span><span class="Normal">const</span> reagent&amp; r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
-  assert<span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom &amp;&amp; r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>atom &amp;&amp; r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">);</span>
+  assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span>
   recipe result_header<span class="Delimiter">;</span>  <span class="Comment">// will contain only ingredients and products, nothing else</span>
   result_header<span class="Delimiter">.</span>has_header = <span class="Constant">true</span><span class="Delimiter">;</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+    assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">);</span>
+    <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>
+  <span class="Delimiter">}</span>
+  assert<span class="Delimiter">(</span>root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-&gt;</span>name == <span class="Constant">&quot;recipe&quot;</span><span class="Delimiter">);</span>
   <span class="Normal">const</span> type_tree* curr = r<span class="Delimiter">.</span>type<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>
   <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr &amp;&amp; !curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span>
     <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>atom &amp;&amp; curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">-&gt;</span>name == <span class="Constant">&quot;-&gt;&quot;</span><span class="Delimiter">)</span> <span class="Delimiter">{</span>
       curr = curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">;</span>  <span class="Comment">// skip delimiter</span>
-      <span class="Identifier">break</span><span class="Delimiter">;</span>
+      <span class="Identifier">goto</span> read_products<span class="Delimiter">;</span>
     <span class="Delimiter">}</span>
     result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">));</span>
-    <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>right &amp;&amp; curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span>
-      result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">));</span>
-      <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>  <span class="Comment">// no products</span>
-    <span class="Delimiter">}</span>
   <span class="Delimiter">}</span>
-  <span class="Normal">for</span> <span class="Delimiter">(;</span> curr &amp;&amp; !curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span>
+  <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
+    assert<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">);</span>
+    result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">));</span>
+    <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>  <span class="Comment">// no products</span>
+  <span class="Delimiter">}</span>
+  <span class="Normal">read_products</span>:
+  <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr &amp;&amp; !curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-&gt;</span>right<span class="Delimiter">)</span>
     result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">));</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
     assert<span class="Delimiter">(</span>curr<span class="Delimiter">-&gt;</span>atom<span class="Delimiter">);</span>
@@ -236,8 +243,33 @@ recipe from_reagent<span class="Delimiter">(</span><span class="Normal">const</s
   <span class="Identifier">return</span> result_header<span class="Delimiter">;</span>
 <span class="Delimiter">}</span>
 
-<span class="Comment">// todo: unit test: 'recipe number' vs 'recipe -&gt; number'</span>
+<span class="Delimiter">:(before &quot;End Unit Tests&quot;)</span>
+<span class="Normal">void</span> test_from_reagent_atomic<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: recipe}&quot;</span><span class="Delimiter">);</span>
+  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
+  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
+  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
+<span class="Delimiter">}</span>
+<span class="Normal">void</span> test_from_reagent_non_atomic<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: (recipe number -&gt; number)}&quot;</span><span class="Delimiter">);</span>
+  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
+  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
+  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
+<span class="Delimiter">}</span>
+<span class="Normal">void</span> test_from_reagent_reads_ingredient_at_end<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: (recipe number number)}&quot;</span><span class="Delimiter">);</span>
+  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
+  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span>
+  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
+<span class="Delimiter">}</span>
+<span class="Normal">void</span> test_from_reagent_reads_sole_ingredient_at_end<span class="Delimiter">()</span> <span class="Delimiter">{</span>
+  reagent a<span class="Delimiter">(</span><span class="Constant">&quot;{f: (recipe number)}&quot;</span><span class="Delimiter">);</span>
+  recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span>
+  CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span>
+  CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span>
+<span class="Delimiter">}</span>
 
+<span class="Delimiter">:(code)</span>
 reagent next_recipe_reagent<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* curr<span class="Delimiter">)</span> <span class="Delimiter">{</span>
   <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">-&gt;</span>left<span class="Delimiter">)</span> <span class="Identifier">return</span> reagent<span class="Delimiter">(</span><span class="Constant">&quot;recipe:&quot;</span>+curr<span class="Delimiter">-&gt;</span>name<span class="Delimiter">);</span>
   reagent result<span class="Delimiter">;</span>