Improve coverage of regex
This commit is contained in:
parent
c71825f80e
commit
ecd8fa3437
@ -375,14 +375,14 @@ private:
|
|||||||
bool Eval(Stack<Allocator>& operandStack, Operator op) {
|
bool Eval(Stack<Allocator>& operandStack, Operator op) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case kConcatenation:
|
case kConcatenation:
|
||||||
if (operandStack.GetSize() >= sizeof(Frag) * 2) {
|
RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag) * 2);
|
||||||
|
{
|
||||||
Frag e2 = *operandStack.template Pop<Frag>(1);
|
Frag e2 = *operandStack.template Pop<Frag>(1);
|
||||||
Frag e1 = *operandStack.template Pop<Frag>(1);
|
Frag e1 = *operandStack.template Pop<Frag>(1);
|
||||||
Patch(e1.out, e2.start);
|
Patch(e1.out, e2.start);
|
||||||
*operandStack.template Push<Frag>() = Frag(e1.start, e2.out, Min(e1.minIndex, e2.minIndex));
|
*operandStack.template Push<Frag>() = Frag(e1.start, e2.out, Min(e1.minIndex, e2.minIndex));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return true;
|
||||||
|
|
||||||
case kAlternation:
|
case kAlternation:
|
||||||
if (operandStack.GetSize() >= sizeof(Frag) * 2) {
|
if (operandStack.GetSize() >= sizeof(Frag) * 2) {
|
||||||
@ -430,8 +430,7 @@ private:
|
|||||||
|
|
||||||
bool EvalQuantifier(Stack<Allocator>& operandStack, unsigned n, unsigned m) {
|
bool EvalQuantifier(Stack<Allocator>& operandStack, unsigned n, unsigned m) {
|
||||||
RAPIDJSON_ASSERT(n <= m);
|
RAPIDJSON_ASSERT(n <= m);
|
||||||
if (operandStack.GetSize() < sizeof(Frag))
|
RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag));
|
||||||
return false;
|
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
if (m == 0) // a{0} not support
|
if (m == 0) // a{0} not support
|
||||||
@ -647,8 +646,7 @@ private:
|
|||||||
|
|
||||||
// Return whether the added states is a match state
|
// Return whether the added states is a match state
|
||||||
bool AddState(Stack<Allocator>& l, SizeType index) const {
|
bool AddState(Stack<Allocator>& l, SizeType index) const {
|
||||||
if (index == kRegexInvalidState)
|
RAPIDJSON_ASSERT(index != kRegexInvalidState);
|
||||||
return true;
|
|
||||||
|
|
||||||
const State& s = GetState(index);
|
const State& s = GetState(index);
|
||||||
if (s.out1 != kRegexInvalidState) { // Split
|
if (s.out1 != kRegexInvalidState) { // Split
|
||||||
|
@ -17,6 +17,14 @@
|
|||||||
|
|
||||||
using namespace rapidjson::internal;
|
using namespace rapidjson::internal;
|
||||||
|
|
||||||
|
TEST(Regex, Single) {
|
||||||
|
Regex re("a");
|
||||||
|
ASSERT_TRUE(re.IsValid());
|
||||||
|
EXPECT_TRUE(re.Match("a"));
|
||||||
|
EXPECT_FALSE(re.Match(""));
|
||||||
|
EXPECT_FALSE(re.Match("b"));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(Regex, Concatenation) {
|
TEST(Regex, Concatenation) {
|
||||||
Regex re("abc");
|
Regex re("abc");
|
||||||
ASSERT_TRUE(re.IsValid());
|
ASSERT_TRUE(re.IsValid());
|
||||||
@ -560,6 +568,9 @@ TEST(Regex, Invalid) {
|
|||||||
TEST_INVALID("a{1,0}");
|
TEST_INVALID("a{1,0}");
|
||||||
TEST_INVALID("a{-1,0}");
|
TEST_INVALID("a{-1,0}");
|
||||||
TEST_INVALID("a{-1,1}");
|
TEST_INVALID("a{-1,1}");
|
||||||
|
TEST_INVALID("a{4294967296}"); // overflow of unsigned
|
||||||
|
TEST_INVALID("a{1a}");
|
||||||
|
TEST_INVALID("[");
|
||||||
TEST_INVALID("[]");
|
TEST_INVALID("[]");
|
||||||
TEST_INVALID("[^]");
|
TEST_INVALID("[^]");
|
||||||
TEST_INVALID("[\\a]");
|
TEST_INVALID("[\\a]");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user