Ejemplo n.º 1
0
TEST(pragma_handler_map, processing_non_existing_handler)
{
  pragma_handler_map m;
  const data::command cmd{data::cpp_code(/* #pragma metashell */ "foo")};

  null_displayer d;
  ASSERT_ANY_THROW(m.process(cmd.begin(), cmd.end(), d));
}
Ejemplo n.º 2
0
TEST(pragma_handler_map, pragma_with_two_token_name_is_called)
{
  bool foo_bar_run = false;
  pragma_handler_map m;
  m.add("foo", "bar", test_handler(foo_bar_run));
  const data::command cmd{data::cpp_code(/* #pragma metashell */ "foo bar")};

  null_displayer d;
  m.process(cmd.begin(), cmd.end(), d);

  ASSERT_TRUE(foo_bar_run);
}
Ejemplo n.º 3
0
TEST(pragma_handler_map, processing_existing_handler)
{
  bool foo_run = false;
  pragma_handler_map m;
  m.add("foo", test_handler(foo_run));
  const data::command cmd{data::cpp_code(/* #pragma metashell */ "foo")};

  null_displayer d;
  m.process(cmd.begin(), cmd.end(), d);

  ASSERT_TRUE(foo_run);
}
Ejemplo n.º 4
0
boost::optional<data::command::iterator>
metashell::parse_pragma(const data::command& cmd_)
{
  data::command::iterator i = skip_whitespace(cmd_.begin(), cmd_.end());

  if (i != cmd_.end() && (i->type() == data::token_type::p_pragma ||
                          i->type() == data::token_type::operator_pound))
  {
    i = skip_whitespace(skip(i), cmd_.end());

    if (i != cmd_.end() && i->type() == data::token_type::identifier &&
        (i->value() == "metashell" || i->value() == "msh"))
    {
      i = skip_whitespace(skip(i), cmd_.end());
      if (i == cmd_.end() || i->value().empty())
      {
        throw exception("The name of the metashell pragma is missing.");
      }
      else if (i->type() == data::token_type::identifier)
      {
        return i;
      }
      else
      {
        std::ostringstream s;
        s << "Invalid pragma name " << i->value();
        throw exception(s.str());
      }
    }
  }

  return boost::none;
}
Ejemplo n.º 5
0
TEST(pragma_handler_map,
     pragma_prefix_is_selected_when_longer_version_is_available)
{
  bool foo_bar_run = false;
  bool foo_run = false;
  pragma_handler_map m;
  m.add("foo", test_handler(foo_run));
  m.add("foo", "bar", test_handler(foo_bar_run));
  const data::command cmd{data::cpp_code(/* #pragma metashell */ "foo x")};

  null_displayer d;
  m.process(cmd.begin(), cmd.end(), d);

  ASSERT_TRUE(foo_run);
  ASSERT_FALSE(foo_bar_run);
}
Ejemplo n.º 6
0
 inline bool is_environment_setup_command(const data::command& cmd_)
 {
   return is_environment_setup_command(cmd_.begin(), cmd_.end());
 }