Permalink
Browse files

predicate/parse: Allow - in names.

  • Loading branch information...
1 parent 349815e commit 09176ed702a135cc30cccf95872e8bc0c66ce2a9 Christopher Alfeld committed Mar 5, 2014
Showing with 51 additions and 2 deletions.
  1. +1 −1 predicate/parse.cpp
  2. +1 −1 predicate/parse.hpp
  3. +49 −0 predicate/tests/test_parse.cpp
View
@@ -69,7 +69,7 @@ bool name_char(char c)
( c >= 'a' && c <= 'z' ) ||
( c >= 'A' && c <= 'Z' ) ||
( c >= '0' && c <= '9' ) ||
- c == '_'
+ c == '_' || c == '-'
;
}
View
@@ -64,7 +64,7 @@ node_p parse_literal(
* string := '\'' + *(/[^'\\]/ | '\\\\' | '\\'') + '\''
* integer := /^-?[0-9]+$/
* float := /^-?[0-9]+(\.[0-9]+)?$/
- * name := [_A-Za-z0-9]+
+ * name := [-_A-Za-z0-9]+
* @endcode
*
* @param [in] text Text to parse.
@@ -66,6 +66,29 @@ class CallB : public CallBase
}
};
+class Named : public CallBase
+{
+public:
+ explicit Named(const std::string& name) :
+ m_name(name)
+ {
+ // nop
+ }
+
+ virtual std::string name() const
+ {
+ return m_name;
+ }
+
+private:
+ const std::string m_name;
+};
+
+call_p named(const std::string& name)
+{
+ return call_p(new Named(name));
+}
+
TEST(TestParse, ValidLiteral)
{
size_t i;
@@ -242,3 +265,29 @@ TEST(TestParse, InvalidCall)
i = 0;
EXPECT_THROW(parse_call("(CallA @)", i, f), IronBee::einval);
}
+
+TEST(TestParse, Names)
+{
+ static const char* names[] = {
+ "foo-bar",
+ "_foobar",
+ "129839213",
+ "fO0-_",
+ NULL
+ };
+
+ size_t i;
+ CallFactory f;
+
+ for (const char** name = names; *name; ++name) {
+ f.add(*name, named);
+
+ string expr;
+ node_p r;
+ expr = string("(") + *name + ")";
+ i = 0;
+ ASSERT_NO_THROW(r = parse_call(expr, i, f)) << expr;
+ EXPECT_EQ(expr, r->to_s()) << expr;
+ EXPECT_EQ(expr.length() - 1, i) << expr;
+ }
+}

0 comments on commit 09176ed

Please sign in to comment.