summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-regexp.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/test-regexp.cc')
-rw-r--r--deps/v8/test/cctest/test-regexp.cc212
1 files changed, 20 insertions, 192 deletions
diff --git a/deps/v8/test/cctest/test-regexp.cc b/deps/v8/test/cctest/test-regexp.cc
index d71223e73d..1dad8febda 100644
--- a/deps/v8/test/cctest/test-regexp.cc
+++ b/deps/v8/test/cctest/test-regexp.cc
@@ -36,38 +36,17 @@
#include "src/codegen/macro-assembler.h"
#include "src/init/v8.h"
#include "src/objects/objects-inl.h"
-#include "src/regexp/interpreter-irregexp.h"
-#include "src/regexp/jsregexp.h"
-#include "src/regexp/regexp-macro-assembler-irregexp.h"
-#include "src/regexp/regexp-macro-assembler.h"
+#include "src/regexp/regexp-bytecode-generator.h"
+#include "src/regexp/regexp-compiler.h"
+#include "src/regexp/regexp-interpreter.h"
+#include "src/regexp/regexp-macro-assembler-arch.h"
#include "src/regexp/regexp-parser.h"
+#include "src/regexp/regexp.h"
#include "src/strings/char-predicates-inl.h"
#include "src/strings/string-stream.h"
#include "src/strings/unicode-inl.h"
#include "src/utils/ostreams.h"
-#include "src/utils/splay-tree-inl.h"
#include "src/zone/zone-list-inl.h"
-
-#if V8_TARGET_ARCH_ARM
-#include "src/regexp/arm/regexp-macro-assembler-arm.h"
-#elif V8_TARGET_ARCH_ARM64
-#include "src/regexp/arm64/regexp-macro-assembler-arm64.h"
-#elif V8_TARGET_ARCH_S390
-#include "src/regexp/s390/regexp-macro-assembler-s390.h"
-#elif V8_TARGET_ARCH_PPC
-#include "src/regexp/ppc/regexp-macro-assembler-ppc.h"
-#elif V8_TARGET_ARCH_MIPS
-#include "src/regexp/mips/regexp-macro-assembler-mips.h"
-#elif V8_TARGET_ARCH_MIPS64
-#include "src/regexp/mips64/regexp-macro-assembler-mips64.h"
-#elif V8_TARGET_ARCH_X64
-#include "src/regexp/x64/regexp-macro-assembler-x64.h"
-#elif V8_TARGET_ARCH_IA32
-#include "src/regexp/ia32/regexp-macro-assembler-ia32.h"
-#else
-#error Unknown architecture.
-#endif
-
#include "test/cctest/cctest.h"
namespace v8 {
@@ -281,8 +260,9 @@ TEST(RegExpParser) {
CheckParseEq("\\u0034", "'\x34'");
CheckParseEq("\\u003z", "'u003z'");
CheckParseEq("foo[z]*", "(: 'foo' (# 0 - g [z]))");
- CheckParseEq("^^^$$$\\b\\b\\b\\b", "(: @^i @$i @b)");
- CheckParseEq("\\b\\b\\b\\b\\B\\B\\B\\B\\b\\b\\b\\b", "(: @b @B @b)");
+ CheckParseEq("^^^$$$\\b\\b\\b\\b", "(: @^i @^i @^i @$i @$i @$i @b @b @b @b)");
+ CheckParseEq("\\b\\b\\b\\b\\B\\B\\B\\B\\b\\b\\b\\b",
+ "(: @b @b @b @b @B @B @B @B @b @b @b @b)");
CheckParseEq("\\b\\B\\b", "(: @b @B @b)");
// Unicode regexps
@@ -566,8 +546,8 @@ static RegExpNode* Compile(const char* input, bool multiline, bool unicode,
.ToHandleChecked();
Handle<String> sample_subject =
isolate->factory()->NewStringFromUtf8(CStrVector("")).ToHandleChecked();
- RegExpEngine::Compile(isolate, zone, &compile_data, flags, pattern,
- sample_subject, is_one_byte);
+ RegExp::CompileForTesting(isolate, zone, &compile_data, flags, pattern,
+ sample_subject, is_one_byte);
return compile_data.node;
}
@@ -579,128 +559,10 @@ static void Execute(const char* input, bool multiline, bool unicode,
RegExpNode* node = Compile(input, multiline, unicode, is_one_byte, &zone);
USE(node);
#ifdef DEBUG
- if (dot_output) {
- RegExpEngine::DotPrint(input, node, false);
- }
+ if (dot_output) RegExp::DotPrintForTesting(input, node);
#endif // DEBUG
}
-
-class TestConfig {
- public:
- using Key = int;
- using Value = int;
- static const int kNoKey;
- static int NoValue() { return 0; }
- static inline int Compare(int a, int b) {
- if (a < b)
- return -1;
- else if (a > b)
- return 1;
- else
- return 0;
- }
-};
-
-
-const int TestConfig::kNoKey = 0;
-
-
-static unsigned PseudoRandom(int i, int j) {
- return ~(~((i * 781) ^ (j * 329)));
-}
-
-
-TEST(SplayTreeSimple) {
- static const unsigned kLimit = 1000;
- Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
- ZoneSplayTree<TestConfig> tree(&zone);
- bool seen[kLimit];
- for (unsigned i = 0; i < kLimit; i++) seen[i] = false;
-#define CHECK_MAPS_EQUAL() do { \
- for (unsigned k = 0; k < kLimit; k++) \
- CHECK_EQ(seen[k], tree.Find(k, &loc)); \
- } while (false)
- for (int i = 0; i < 50; i++) {
- for (int j = 0; j < 50; j++) {
- int next = PseudoRandom(i, j) % kLimit;
- if (seen[next]) {
- // We've already seen this one. Check the value and remove
- // it.
- ZoneSplayTree<TestConfig>::Locator loc;
- CHECK(tree.Find(next, &loc));
- CHECK_EQ(next, loc.key());
- CHECK_EQ(3 * next, loc.value());
- tree.Remove(next);
- seen[next] = false;
- CHECK_MAPS_EQUAL();
- } else {
- // Check that it wasn't there already and then add it.
- ZoneSplayTree<TestConfig>::Locator loc;
- CHECK(!tree.Find(next, &loc));
- CHECK(tree.Insert(next, &loc));
- CHECK_EQ(next, loc.key());
- loc.set_value(3 * next);
- seen[next] = true;
- CHECK_MAPS_EQUAL();
- }
- int val = PseudoRandom(j, i) % kLimit;
- if (seen[val]) {
- ZoneSplayTree<TestConfig>::Locator loc;
- CHECK(tree.FindGreatestLessThan(val, &loc));
- CHECK_EQ(loc.key(), val);
- break;
- }
- val = PseudoRandom(i + j, i - j) % kLimit;
- if (seen[val]) {
- ZoneSplayTree<TestConfig>::Locator loc;
- CHECK(tree.FindLeastGreaterThan(val, &loc));
- CHECK_EQ(loc.key(), val);
- break;
- }
- }
- }
-}
-
-
-TEST(DispatchTableConstruction) {
- // Initialize test data.
- static const int kLimit = 1000;
- static const int kRangeCount = 8;
- static const int kRangeSize = 16;
- uc16 ranges[kRangeCount][2 * kRangeSize];
- for (int i = 0; i < kRangeCount; i++) {
- Vector<uc16> range(ranges[i], 2 * kRangeSize);
- for (int j = 0; j < 2 * kRangeSize; j++) {
- range[j] = PseudoRandom(i + 25, j + 87) % kLimit;
- }
- std::sort(range.begin(), range.end());
- for (int j = 1; j < 2 * kRangeSize; j++) {
- CHECK(range[j-1] <= range[j]);
- }
- }
- // Enter test data into dispatch table.
- Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
- DispatchTable table(&zone);
- for (int i = 0; i < kRangeCount; i++) {
- uc16* range = ranges[i];
- for (int j = 0; j < 2 * kRangeSize; j += 2)
- table.AddRange(CharacterRange::Range(range[j], range[j + 1]), i, &zone);
- }
- // Check that the table looks as we would expect
- for (int p = 0; p < kLimit; p++) {
- OutSet* outs = table.Get(p);
- for (int j = 0; j < kRangeCount; j++) {
- uc16* range = ranges[j];
- bool is_on = false;
- for (int k = 0; !is_on && (k < 2 * kRangeSize); k += 2)
- is_on = (range[k] <= p && p <= range[k + 1]);
- CHECK_EQ(is_on, outs->Get(j));
- }
- }
-}
-
-
// Test of debug-only syntax.
#ifdef DEBUG
@@ -1392,7 +1254,7 @@ TEST(MacroAssemblerNativeLotsOfRegisters) {
TEST(MacroAssembler) {
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
- RegExpMacroAssemblerIrregexp m(CcTest::i_isolate(), &zone);
+ RegExpBytecodeGenerator m(CcTest::i_isolate(), &zone);
// ^f(o)o.
Label start, fail, backtrack;
@@ -1451,43 +1313,6 @@ TEST(MacroAssembler) {
CHECK_EQ(42, captures[0]);
}
-TEST(AddInverseToTable) {
- static const int kLimit = 1000;
- static const int kRangeCount = 16;
- for (int t = 0; t < 10; t++) {
- Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
- ZoneList<CharacterRange>* ranges =
- new(&zone) ZoneList<CharacterRange>(kRangeCount, &zone);
- for (int i = 0; i < kRangeCount; i++) {
- int from = PseudoRandom(t + 87, i + 25) % kLimit;
- int to = from + (PseudoRandom(i + 87, t + 25) % (kLimit / 20));
- if (to > kLimit) to = kLimit;
- ranges->Add(CharacterRange::Range(from, to), &zone);
- }
- DispatchTable table(&zone);
- DispatchTableConstructor cons(&table, false, &zone);
- cons.set_choice_index(0);
- cons.AddInverse(ranges);
- for (int i = 0; i < kLimit; i++) {
- bool is_on = false;
- for (int j = 0; !is_on && j < kRangeCount; j++)
- is_on = ranges->at(j).Contains(i);
- OutSet* set = table.Get(i);
- CHECK_EQ(is_on, set->Get(0) == false);
- }
- }
- Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
- ZoneList<CharacterRange>* ranges =
- new(&zone) ZoneList<CharacterRange>(1, &zone);
- ranges->Add(CharacterRange::Range(0xFFF0, 0xFFFE), &zone);
- DispatchTable table(&zone);
- DispatchTableConstructor cons(&table, false, &zone);
- cons.set_choice_index(0);
- cons.AddInverse(ranges);
- CHECK(!table.Get(0xFFFE)->Get(0));
- CHECK(table.Get(0xFFFF)->Get(0));
-}
-
#ifndef V8_INTL_SUPPORT
static uc32 canonicalize(uc32 c) {
unibrow::uchar canon[unibrow::Ecma262Canonicalize::kMaxWidth];
@@ -1649,10 +1474,10 @@ TEST(CharacterRangeCaseIndependence) {
#endif // !V8_INTL_SUPPORT
}
-
-static bool InClass(uc32 c, ZoneList<CharacterRange>* ranges) {
+static bool InClass(uc32 c,
+ const UnicodeRangeSplitter::CharacterRangeVector* ranges) {
if (ranges == nullptr) return false;
- for (int i = 0; i < ranges->length(); i++) {
+ for (size_t i = 0; i < ranges->size(); i++) {
CharacterRange range = ranges->at(i);
if (range.from() <= c && c <= range.to())
return true;
@@ -1660,13 +1485,12 @@ static bool InClass(uc32 c, ZoneList<CharacterRange>* ranges) {
return false;
}
-
TEST(UnicodeRangeSplitter) {
Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
ZoneList<CharacterRange>* base =
new(&zone) ZoneList<CharacterRange>(1, &zone);
base->Add(CharacterRange::Everything(), &zone);
- UnicodeRangeSplitter splitter(&zone, base);
+ UnicodeRangeSplitter splitter(base);
// BMP
for (uc32 c = 0; c < 0xD800; c++) {
CHECK(InClass(c, splitter.bmp()));
@@ -1959,6 +1783,10 @@ TEST(UncachedExternalString) {
ExpectString("external.substring(1).match(re)[1]", "z");
}
+#undef CHECK_PARSE_ERROR
+#undef CHECK_SIMPLE
+#undef CHECK_MIN_MAX
+
} // namespace test_regexp
} // namespace internal
} // namespace v8