about summary refs log tree commit diff stats
path: root/082persist.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-01 22:16:09 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-01 22:16:09 -0700
commit48e40252b005e3c37e3e5c087daf4f14657295f6 (patch)
tree00e1d10fc9c3b9f2abde3c605011e14db43d12ba /082persist.cc
parent5257d0b41aa111b732796c190077af27a55cf905 (diff)
downloadmu-48e40252b005e3c37e3e5c087daf4f14657295f6.tar.gz
1913 - save expected response for each sandbox
Diffstat (limited to '082persist.cc')
-rw-r--r--082persist.cc22
1 files changed, 15 insertions, 7 deletions
diff --git a/082persist.cc b/082persist.cc
index 0cae8c32..3e53ff6a 100644
--- a/082persist.cc
+++ b/082persist.cc
@@ -58,14 +58,22 @@ case SAVE: {
     raise << current_recipe_name() << ": 'save' requires exactly two ingredients, but got " << current_instruction().to_string() << '\n' << end();
     break;
   }
-  if (!scalar(ingredients.at(0)))
-    raise << current_recipe_name() << ": first ingredient of 'save' should be a literal string, but got " << current_instruction().ingredients.at(0).to_string() << '\n' << end();
-  if (!scalar(ingredients.at(1)))
-    raise << current_recipe_name() << ": second ingredient of 'save' should be an address:array:character, but got " << current_instruction().ingredients.at(1).to_string() << '\n' << end();
   if (Current_scenario) break;  // do nothing in tests
-  string filename = current_instruction().ingredients.at(0).name;
-  if (!is_literal(current_instruction().ingredients.at(0)))
-    filename = to_string(ingredients.at(0).at(0));
+  string filename;
+  if (is_literal_string(current_instruction().ingredients.at(0))) {
+    filename = current_instruction().ingredients.at(0).name;
+  }
+  else if (is_mu_string(current_instruction().ingredients.at(0))) {
+    filename = read_mu_string(ingredients.at(0).at(0));
+  }
+  else {
+    raise << current_recipe_name() << ": first ingredient of 'save' should be a string, but got " << current_instruction().ingredients.at(0).to_string() << '\n' << end();
+    break;
+  }
+  if (!scalar(ingredients.at(1))) {
+    raise << current_recipe_name() << ": second ingredient of 'save' should be an address:array:character, but got " << current_instruction().ingredients.at(1).to_string() << '\n' << end();
+    break;
+  }
   ofstream fout(("lesson/"+filename).c_str());
   string contents = read_mu_string(ingredients.at(1).at(0));
   fout << contents;