about summary refs log tree commit diff stats
path: root/cpp/050scenario
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/050scenario')
-rw-r--r--cpp/050scenario47
1 files changed, 46 insertions, 1 deletions
diff --git a/cpp/050scenario b/cpp/050scenario
index 8dd734c5..9295752c 100644
--- a/cpp/050scenario
+++ b/cpp/050scenario
@@ -12,6 +12,8 @@ struct scenario {
 :(before "End Globals")
 vector<scenario> Scenarios;
 
+//: How we check Scenarios.
+
 :(before "End Tests")
 time_t mu_time; time(&mu_time);
 cerr << "\nMu tests: " << ctime(&mu_time);
@@ -37,6 +39,20 @@ for (size_t i = 0; i < Scenarios.size(); ++i) {
   if (Passed) cerr << ".";
 }
 
+//: How we create Scenarios.
+
+:(scenarios "parse_scenario")
+:(scenario "parse_scenario_memory_expectation")
+scenario foo [
+  run [
+    a <- b
+  ]
+  memory should contain [
+    1 <- 0
+  ]
+]
++parse: scenario will run: a <- b
+
 :(before "End Command Handlers")
 else if (command == "scenario") {
 //?   cout << "AAA scenario\n"; //? 1
@@ -61,7 +77,6 @@ scenario parse_scenario(istream& in) {
     // Scenario Command Handlers
     if (scenario_command == "run") {
       handle_scenario_run_directive(inner, x);
-      trace("parse") << "scenario will run: " << x.to_run;
     }
     else if (scenario_command == "memory") {
       handle_scenario_memory_directive(inner, x);
@@ -82,6 +97,9 @@ void handle_scenario_run_directive(istream& in, scenario& result) {
   skip_bracket(in, "'run' inside scenario must begin with '['");
   ostringstream buffer;
   slurp_until_matching_bracket(in, buffer);
+  string trace_result = buffer.str();  // temporary copy
+  trace("parse") << "scenario will run: " << trim(trace_result);
+//?   cout << buffer.str() << '\n'; //? 1
   result.to_run = "recipe test-"+result.name+" [" + buffer.str() + "]";
 }
 
@@ -123,3 +141,30 @@ void slurp_until_matching_bracket(istream& in, ostream& out) {
     out << c;
   }
 }
+
+// for tests
+void parse_scenario(const string& s) {
+  istringstream in(s);
+  in >> std::noskipws;
+  skip_whitespace_and_comments(in);
+  string _scenario = next_word(in);
+//?   cout << _scenario << '\n'; //? 1
+  assert(_scenario == "scenario");
+  parse_scenario(in);
+}
+
+string &trim(string &s) {
+  return ltrim(rtrim(s));
+}
+
+string &ltrim(string &s) {
+  s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(isspace))));
+  return s;
+}
+
+string &rtrim(string &s) {
+  s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(isspace))).base(), s.end());
+  return s;
+}
+
+:(scenarios run)
or: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/bin/sh
# Little helper to quickly build SubX programs from the commandline.
# Only works for programs in some standard places the repo knows about.

if [ $# -eq 0 ]
then
  echo "Usage: $0 <file root without subdirectory or .subx extension>"
  echo
  echo "Naming convention: Files starting with 'ex' will be assumed to live in examples/ and be self-contained."
  echo "Other files will be assumed to live in apps/ and need the standard library."
  exit 1
fi

# Build in debug mode since the common case at the moment is building small
# files. To override, calling scripts should do their own builds to ensure
# subx_bin is up to date.
export CFLAGS=-g

if [[ $1 == 'ex'* ]]
then
  ./subx translate examples/$1.subx -o examples/`echo $1 |sed 's/\..*//'`
  exit $?
fi

./subx translate *.subx apps/$1.subx  -o apps/`echo $1 |sed 's/\..*//'`
exit $?