bind(v8::MaybeLocal param, L lambda)
{
return param.IsEmpty() ? v8::MaybeLocal() : lambda(param.ToLocalChecked());
}
void consoleCall(const v8::Local &methodName, v8::Local text);
void printDeprecationWarning(const char *warning);
v8::Local callToString(const v8::Local &object);
#endif
node-re2-1.10.5/lib/wrapped_re2.h000066400000000000000000000054321357256744100163640ustar00rootroot00000000000000#ifndef WRAPPED_RE2_H_
#define WRAPPED_RE2_H_
#include
#include
#include
#include
class WrappedRE2 : public Nan::ObjectWrap
{
private:
WrappedRE2(const re2::StringPiece &pattern, const re2::RE2::Options &options, const std::string &s,
const bool &g, const bool &i, const bool &m, const bool &y) : regexp(pattern, options),
source(s), global(g), ignoreCase(i), multiline(m), sticky(y), lastIndex(0) {}
static NAN_METHOD(New);
static NAN_METHOD(ToString);
static NAN_GETTER(GetSource);
static NAN_GETTER(GetFlags);
static NAN_GETTER(GetGlobal);
static NAN_GETTER(GetIgnoreCase);
static NAN_GETTER(GetMultiline);
static NAN_GETTER(GetUnicode);
static NAN_GETTER(GetSticky);
static NAN_GETTER(GetLastIndex);
static NAN_SETTER(SetLastIndex);
static NAN_GETTER(GetInternalSource);
// RegExp methods
static NAN_METHOD(Exec);
static NAN_METHOD(Test);
// String methods
static NAN_METHOD(Match);
static NAN_METHOD(Replace);
static NAN_METHOD(Search);
static NAN_METHOD(Split);
// strict Unicode warning support
static NAN_GETTER(GetUnicodeWarningLevel);
static NAN_SETTER(SetUnicodeWarningLevel);
static Nan::Persistent constructor;
static Nan::Persistent ctorTemplate;
public:
static void Initialize(v8::Local exports, v8::Local module);
static inline bool HasInstance(v8::Local object)
{
return Nan::New(ctorTemplate)->HasInstance(object);
}
enum UnicodeWarningLevels
{
NOTHING,
WARN_ONCE,
WARN,
THROW
};
static UnicodeWarningLevels unicodeWarningLevel;
static bool alreadyWarnedAboutUnicode;
re2::RE2 regexp;
std::string source;
bool global;
bool ignoreCase;
bool multiline;
bool sticky;
size_t lastIndex;
};
// utilities
inline size_t getUtf8Length(const uint16_t *from, const uint16_t *to)
{
size_t n = 0;
while (from != to)
{
uint16_t ch = *from++;
if (ch <= 0x7F)
++n;
else if (ch <= 0x7FF)
n += 2;
else if (0xD800 <= ch && ch <= 0xDFFF)
{
n += 4;
if (from == to)
break;
++from;
}
else if (ch < 0xFFFF)
n += 3;
else
n += 4;
}
return n;
}
inline size_t getUtf16Length(const char *from, const char *to)
{
size_t n = 0;
while (from != to)
{
unsigned ch = *from & 0xFF;
if (ch < 0xF0)
{
if (ch < 0x80)
{
++from;
}
else
{
if (ch < 0xE0)
{
from += 2;
if (from == to + 1)
{
++n;
break;
}
}
else
{
from += 3;
if (from > to && from < to + 3)
{
++n;
break;
}
}
}
++n;
}
else
{
from += 4;
n += 2;
if (from > to && from < to + 4)
break;
}
}
return n;
}
inline size_t getUtf8CharSize(char ch)
{
return ((0xE5000000 >> ((ch >> 3) & 0x1E)) & 3) + 1;
}
#endif
node-re2-1.10.5/package-lock.json000066400000000000000000000022251357256744100164440ustar00rootroot00000000000000{
"name": "re2",
"version": "1.10.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"heya-ice": {
"version": "0.1.11",
"resolved": "https://registry.npmjs.org/heya-ice/-/heya-ice-0.1.11.tgz",
"integrity": "sha1-XW2lnGC1nHAjqDRw+26XcddwWEk=",
"dev": true
},
"heya-unify": {
"version": "0.2.7",
"resolved": "https://registry.npmjs.org/heya-unify/-/heya-unify-0.2.7.tgz",
"integrity": "sha512-d/4NacYl52tt4ofbP7gz+YmbjLrI2jkrRxSSd1a26yXfRS1vQxmZkZ6L+O1xUsgDSwx4HCDWR5U+ZFykdoHVig==",
"dev": true,
"requires": {
"heya-ice": "^0.1.11"
}
},
"heya-unit": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/heya-unit/-/heya-unit-0.3.0.tgz",
"integrity": "sha1-eXR4IIyBnUxbf+NWrEwbhO67ubc=",
"dev": true,
"requires": {
"heya-ice": ">=0.1",
"heya-unify": ">=0.2"
}
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg=="
}
}
}
node-re2-1.10.5/package.json000066400000000000000000000015001357256744100155110ustar00rootroot00000000000000{
"name": "re2",
"version": "1.10.5",
"description": "Bindings for RE2: fast, safe alternative to backtracking regular expression engines.",
"homepage": "http://github.com/uhop/node-re2",
"bugs": "http://github.com/uhop/node-re2/issues",
"main": "re2.js",
"types": "re2.d.ts",
"directories": {
"test": "tests"
},
"dependencies": {
"nan": "^2.14.0"
},
"devDependencies": {
"heya-unit": "^0.3.0"
},
"scripts": {
"test": "node tests/tests.js"
},
"github": "http://github.com/uhop/node-re2",
"repository": {
"type": "git",
"url": "git://github.com/uhop/node-re2.git"
},
"keywords": [
"RegExp",
"RegEx",
"text processing",
"PCRE alternative"
],
"author": "Eugene Lazutkin (http://lazutkin.com/)",
"license": "BSD-3-Clause"
}
node-re2-1.10.5/re2.d.ts000066400000000000000000000001101357256744100145010ustar00rootroot00000000000000declare module 're2' {
class RE2 extends RegExp {}
export = RE2;
}
node-re2-1.10.5/re2.js000066400000000000000000000011131357256744100142510ustar00rootroot00000000000000'use strict';
var RE2 = require('./build/Release/re2.node');
if (typeof Symbol != 'undefined') {
Symbol.match &&
(RE2.prototype[Symbol.match] = function(str) {
return this.match(str);
});
Symbol.search &&
(RE2.prototype[Symbol.search] = function(str) {
return this.search(str);
});
Symbol.replace &&
(RE2.prototype[Symbol.replace] = function(str, repl) {
return this.replace(str, repl);
});
Symbol.split &&
(RE2.prototype[Symbol.split] = function(str, limit) {
return this.split(str, limit);
});
}
module.exports = RE2;
node-re2-1.10.5/tests/000077500000000000000000000000001357256744100143715ustar00rootroot00000000000000node-re2-1.10.5/tests/test_exec.js000066400000000000000000000171611357256744100167200ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
function test_execBasic(t) {
"use strict";
var re = new RE2("quick\\s(brown).+?(jumps)", "ig");
eval(t.TEST("re.source === 'quick\\\\s(brown).+?(jumps)'"));
eval(t.TEST("re.ignoreCase"));
eval(t.TEST("re.global"));
eval(t.TEST("!re.multiline"));
var result = re.exec("The Quick Brown Fox Jumps Over The Lazy Dog");
eval(t.TEST("t.unify(result, ['Quick Brown Fox Jumps', 'Brown', 'Jumps'])"));
eval(t.TEST("result.index === 4"));
eval(t.TEST("result.input === 'The Quick Brown Fox Jumps Over The Lazy Dog'"));
eval(t.TEST("re.lastIndex === 25"));
},
function test_execSucc(t) {
"use strict";
var str = "abbcdefabh";
var re = new RE2("ab*", "g");
var result = re.exec(str);
eval(t.TEST("!!result"));
eval(t.TEST("result[0] === 'abb'"));
eval(t.TEST("result.index === 0"));
eval(t.TEST("re.lastIndex === 3"));
result = re.exec(str);
eval(t.TEST("!!result"));
eval(t.TEST("result[0] === 'ab'"));
eval(t.TEST("result.index === 7"));
eval(t.TEST("re.lastIndex === 9"));
result = re.exec(str);
eval(t.TEST("!result"));
},
function test_execSimple(t) {
"use strict";
var re = new RE2("(hello \\S+)");
var result = re.exec("This is a hello world!");
eval(t.TEST("result[1] === 'hello world!'"));
},
function test_execFail(t) {
"use strict";
var re = new RE2("(a+)?(b+)?");
var result = re.exec("aaabb");
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === 'bb'"));
result = re.exec("aaacbb");
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === undefined"));
eval(t.TEST("result.length === 3"));
},
function test_execAnchoredToBeginning(t) {
"use strict";
var re = RE2('^hello', 'g');
var result = re.exec("hellohello");
eval(t.TEST("t.unify(result, ['hello'])"));
eval(t.TEST("result.index === 0"));
eval(t.TEST("re.lastIndex === 5"));
eval(t.TEST("re.exec('hellohello') === null"));
},
function test_execInvalid(t) {
"use strict";
var re = RE2('');
try {
re.exec({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
},
function test_execAnchor1(t) {
"use strict";
var re = new RE2("b|^a", "g");
var result = re.exec("aabc");
eval(t.TEST("!!result"));
eval(t.TEST("result.index === 0"));
eval(t.TEST("re.lastIndex === 1"));
result = re.exec("aabc");
eval(t.TEST("!!result"));
eval(t.TEST("result.index === 2"));
eval(t.TEST("re.lastIndex === 3"));
result = re.exec("aabc");
eval(t.TEST("!result"));
},
function test_execAnchor2(t) {
"use strict";
var re = new RE2("(?:^a)", "g");
var result = re.exec("aabc");
eval(t.TEST("!!result"));
eval(t.TEST("result.index === 0"));
eval(t.TEST("re.lastIndex === 1"));
result = re.exec("aabc");
eval(t.TEST("!result"));
},
// Unicode tests
function test_execUnicode(t) {
"use strict";
var re = new RE2("охотник\\s(желает).+?(где)", "ig");
eval(t.TEST("re.source === 'охотник\\\\s(желает).+?(где)'"));
eval(t.TEST("re.ignoreCase"));
eval(t.TEST("re.global"));
eval(t.TEST("!re.multiline"));
var result = re.exec("Каждый Охотник Желает Знать Где Сидит Фазан");
eval(t.TEST("t.unify(result, ['Охотник Желает Знать Где', 'Желает', 'Где'])"));
eval(t.TEST("result.index === 7"));
eval(t.TEST("result.input === 'Каждый Охотник Желает Знать Где Сидит Фазан'"));
eval(t.TEST("re.lastIndex === 31"));
eval(t.TEST("result.input.substr(result.index) === 'Охотник Желает Знать Где Сидит Фазан'"));
eval(t.TEST("result.input.substr(re.lastIndex) === ' Сидит Фазан'"));
},
function test_execUnicodeSubsequent(t) {
"use strict";
var str = "аббвгдеабё";
var re = new RE2("аб*", "g");
var result = re.exec(str);
eval(t.TEST("!!result"));
eval(t.TEST("result[0] === 'абб'"));
eval(t.TEST("result.index === 0"));
eval(t.TEST("re.lastIndex === 3"));
result = re.exec(str);
eval(t.TEST("!!result"));
eval(t.TEST("result[0] === 'аб'"));
eval(t.TEST("result.index === 7"));
eval(t.TEST("re.lastIndex === 9"));
result = re.exec(str);
eval(t.TEST("!result"));
},
function test_execUnicodeSupplementary(t) {
"use strict";
var re = new RE2("\\u{1F603}", "g");
eval(t.TEST("re.source === '\\\\u{1F603}'"));
eval(t.TEST("re.internalSource === '\\\\x{1F603}'"));
eval(t.TEST("!re.ignoreCase"));
eval(t.TEST("re.global"));
eval(t.TEST("!re.multiline"));
var result = re.exec("\u{1F603}"); // 1F603 is the SMILING FACE WITH OPEN MOUTH emoji
eval(t.TEST("t.unify(result, ['\\u{1F603}'])"));
eval(t.TEST("result.index === 0"));
eval(t.TEST("result.input === '\\u{1F603}'"));
eval(t.TEST("re.lastIndex === 2"));
var re2 = new RE2(".", "g");
eval(t.TEST("re2.source === '.'"));
eval(t.TEST("!re2.ignoreCase"));
eval(t.TEST("re2.global"));
eval(t.TEST("!re2.multiline"));
var result2 = re2.exec("\u{1F603}");
eval(t.TEST("t.unify(result2, ['\\u{1F603}'])"));
eval(t.TEST("result2.index === 0"));
eval(t.TEST("result2.input === '\\u{1F603}'"));
eval(t.TEST("re2.lastIndex === 2"));
var re3 = new RE2("[\u{1F603}-\u{1F605}]", "g");
eval(t.TEST("re3.source === '[\u{1F603}-\u{1F605}]'"));
eval(t.TEST("!re3.ignoreCase"));
eval(t.TEST("re3.global"));
eval(t.TEST("!re3.multiline"));
var result3 = re3.exec("\u{1F604}");
eval(t.TEST("t.unify(result3, ['\\u{1F604}'])"));
eval(t.TEST("result3.index === 0"));
eval(t.TEST("result3.input === '\\u{1F604}'"));
eval(t.TEST("re3.lastIndex === 2"));
},
// Buffer tests
function test_execBuffer(t) {
"use strict";
var re = new RE2("охотник\\s(желает).+?(где)", "ig");
var buf = new Buffer("Каждый Охотник Желает Знать Где Сидит Фазан");
var result = re.exec(buf);
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] instanceof Buffer"));
eval(t.TEST("result[1] instanceof Buffer"));
eval(t.TEST("result[2] instanceof Buffer"));
eval(t.TEST("result[0].toString() === 'Охотник Желает Знать Где'"));
eval(t.TEST("result[1].toString() === 'Желает'"));
eval(t.TEST("result[2].toString() === 'Где'"));
eval(t.TEST("result.index === 13"));
eval(t.TEST("result.input instanceof Buffer"));
eval(t.TEST("result.input.toString() === 'Каждый Охотник Желает Знать Где Сидит Фазан'"));
eval(t.TEST("re.lastIndex === 58"));
eval(t.TEST("result.input.toString('utf8', result.index) === 'Охотник Желает Знать Где Сидит Фазан'"));
eval(t.TEST("result.input.toString('utf8', re.lastIndex) === ' Сидит Фазан'"));
},
// Sticky tests
function test_execSticky(t) {
"use strict";
var re = new RE2("\\s+", "y");
eval(t.TEST("re.exec('Hello world, how are you?') === null"));
re.lastIndex = 5;
var result = re.exec("Hello world, how are you?");
eval(t.TEST("t.unify(result, [' '])"));
eval(t.TEST("result.index === 5"));
eval(t.TEST("re.lastIndex === 6"));
var re2 = new RE2("\\s+", "gy");
eval(t.TEST("re2.exec('Hello world, how are you?') === null"));
re2.lastIndex = 5;
var result2 = re2.exec("Hello world, how are you?");
eval(t.TEST("t.unify(result2, [' '])"));
eval(t.TEST("result2.index === 5"));
eval(t.TEST("re2.lastIndex === 6"));
}
]);
node-re2-1.10.5/tests/test_general.js000066400000000000000000000135061357256744100174100ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_generalCtr(t) {
"use strict";
eval(t.TEST("!!RE2"));
eval(t.TEST("RE2.toString() === 'function RE2() { [native code] }'"));
eval(t.TEST("!!RE2.prototype"));
},
function test_generalInst(t) {
"use strict";
var re1 = new RE2("\\d+");
eval(t.TEST("!!re1"));
eval(t.TEST("re1 instanceof RE2"));
var re2 = RE2("\\d+");
eval(t.TEST("!!re2"));
eval(t.TEST("re2 instanceof RE2"));
compare(re1, re2, t);
re1 = new RE2("\\d+", "m");
eval(t.TEST("!!re1"));
eval(t.TEST("re1 instanceof RE2"));
re2 = RE2("\\d+", "m");
eval(t.TEST("!!re2"));
eval(t.TEST("re2 instanceof RE2"));
compare(re1, re2, t);
},
function test_instErrors(t) {
try {
var re = new RE2([]);
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
try {
var re = new RE2({});
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
try {
var re = new RE2(new Date());
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
try {
var re = new RE2(null);
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
try {
var re = new RE2();
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
try {
var re = RE2();
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
try {
var re = RE2({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof TypeError"));
}
},
function test_generalIn(t) {
"use strict";
var re = new RE2("\\d+");
eval(t.TEST("'exec' in re"));
eval(t.TEST("'test' in re"));
eval(t.TEST("'match' in re"));
eval(t.TEST("'replace' in re"));
eval(t.TEST("'search' in re"));
eval(t.TEST("'split' in re"));
eval(t.TEST("'source' in re"));
eval(t.TEST("'flags' in re"));
eval(t.TEST("'global' in re"));
eval(t.TEST("'ignoreCase' in re"));
eval(t.TEST("'multiline' in re"));
eval(t.TEST("'sticky' in re"));
eval(t.TEST("'lastIndex' in re"));
},
function test_generalPresent(t) {
"use strict";
var re = new RE2("\\d+");
eval(t.TEST("typeof re.exec == 'function'"));
eval(t.TEST("typeof re.test == 'function'"));
eval(t.TEST("typeof re.match == 'function'"));
eval(t.TEST("typeof re.replace == 'function'"));
eval(t.TEST("typeof re.search == 'function'"));
eval(t.TEST("typeof re.split == 'function'"));
eval(t.TEST("typeof re.source == 'string'"));
eval(t.TEST("typeof re.flags == 'string'"));
eval(t.TEST("typeof re.global == 'boolean'"));
eval(t.TEST("typeof re.ignoreCase == 'boolean'"));
eval(t.TEST("typeof re.multiline == 'boolean'"));
eval(t.TEST("typeof re.sticky == 'boolean'"));
eval(t.TEST("typeof re.lastIndex == 'number'"));
},
function test_generalLastIndex(t) {
"use strict";
var re = new RE2("\\d+");
eval(t.TEST("re.lastIndex === 0"));
re.lastIndex = 5;
eval(t.TEST("re.lastIndex === 5"));
re.lastIndex = 0;
eval(t.TEST("re.lastIndex === 0"));
},
function test_generalRegExp(t) {
"use strict";
var re1 = new RegExp("\\d+");
var re2 = new RE2("\\d+");
compare(re1, re2, t);
re2 = new RE2(re1);
compare(re1, re2, t);
re1 = new RegExp("a", "ig");
re2 = new RE2("a", "ig");
compare(re1, re2, t);
re2 = new RE2(re1);
compare(re1, re2, t);
re1 = /\s/gm;
re2 = new RE2("\\s", "mg");
compare(re1, re2, t);
re2 = new RE2(re1);
compare(re1, re2, t);
re2 = new RE2(/\s/gm);
compare(/\s/gm, re2, t);
re1 = new RE2("b", "gm");
re2 = new RE2(re1);
compare(re1, re2, t);
},
function test_utf8(t) {
"use strict";
var s = "Привет!";
eval(t.TEST("s.length === 7"));
eval(t.TEST("RE2.getUtf8Length(s) === 13"));
var b = new Buffer(s);
eval(t.TEST("b.length === 13"));
eval(t.TEST("RE2.getUtf16Length(b) === 7"));
var s2 = "\u{1F603}";
eval(t.TEST("s2.length === 2"));
eval(t.TEST("RE2.getUtf8Length(s2) === 4"));
var b2 = new Buffer(s2);
eval(t.TEST("b2.length === 4"));
eval(t.TEST("RE2.getUtf16Length(b2) === 2"));
var s3 = "\uD83D";
eval(t.TEST("s3.length === 1"));
eval(t.TEST("RE2.getUtf8Length(s3) === 3"));
var b3 = new Buffer([0xF0]);
eval(t.TEST("b3.length === 1"));
eval(t.TEST("RE2.getUtf16Length(b3) === 2"));
try {
RE2.getUtf8Length({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
eval(t.TEST("RE2.getUtf16Length({ toString() { throw 'corner'; } }) === -1"));
},
function test_flags(t) {
"use strict";
var re = new RE2("a", "u");
eval(t.TEST("re.flags === 'u'"));
re = new RE2("a", "iu");
eval(t.TEST("re.flags === 'iu'"));
re = new RE2("a", "mu");
eval(t.TEST("re.flags === 'mu'"));
re = new RE2("a", "gu");
eval(t.TEST("re.flags === 'gu'"));
re = new RE2("a", "yu");
eval(t.TEST("re.flags === 'uy'"));
re = new RE2("a", "yiu");
eval(t.TEST("re.flags === 'iuy'"));
re = new RE2("a", "yigu");
eval(t.TEST("re.flags === 'giuy'"));
re = new RE2("a", "miu");
eval(t.TEST("re.flags === 'imu'"));
re = new RE2("a", "ygu");
eval(t.TEST("re.flags === 'guy'"));
re = new RE2("a", "myu");
eval(t.TEST("re.flags === 'muy'"));
re = new RE2("a", "migyu");
eval(t.TEST("re.flags === 'gimuy'"));
}
]);
// utilitites
function compare(re1, re2, t) {
// compares regular expression objects
eval(t.TEST("re1.source === re2.source"));
eval(t.TEST("re1.global === re2.global"));
eval(t.TEST("re1.ignoreCase === re2.ignoreCase"));
eval(t.TEST("re1.multiline === re2.multiline"));
// eval(t.TEST("re1.unicode === re2.unicode"));
eval(t.TEST("re1.sticky === re2.sticky"));
}
node-re2-1.10.5/tests/test_groups.js000066400000000000000000000054121357256744100173070ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_groupsNormal(t) {
"use strict";
eval(t.TEST("RE2('(?\\\\d)').test('9')"));
eval(t.TEST("t.unify(RE2('(?-)', 'g').match('a-b-c'), ['-', '-'])"));
eval(t.TEST("t.unify(RE2('(?-)').split('a-b-c'), ['a', '-', 'b', '-', 'c'])"));
eval(t.TEST("RE2('(?-)', 'g').search('a-b-c') === 1"));
},
function test_groupsExec(t) {
"use strict";
var result = new RE2('(\\d)').exec('k9');
eval(t.TEST("result"));
eval(t.TEST("result[0] === '9'"));
eval(t.TEST("result[1] === '9'"));
eval(t.TEST("result.index === 1"));
eval(t.TEST("result.input === 'k9'"));
eval(t.TEST("typeof result.groups == 'undefined'"));
result = new RE2('(?\\d)').exec('k9');
eval(t.TEST("result"));
eval(t.TEST("result[0] === '9'"));
eval(t.TEST("result[1] === '9'"));
eval(t.TEST("result.index === 1"));
eval(t.TEST("result.input === 'k9'"));
eval(t.TEST("t.unify(result.groups, {a: '9'})"));
},
function test_groupsMatch(t) {
"use strict";
var result = new RE2('(\\d)').match('k9');
eval(t.TEST("result"));
eval(t.TEST("result[0] === '9'"));
eval(t.TEST("result[1] === '9'"));
eval(t.TEST("result.index === 1"));
eval(t.TEST("result.input === 'k9'"));
eval(t.TEST("typeof result.groups == 'undefined'"));
result = new RE2('(?\\d)').match('k9');
eval(t.TEST("result"));
eval(t.TEST("result[0] === '9'"));
eval(t.TEST("result[1] === '9'"));
eval(t.TEST("result.index === 1"));
eval(t.TEST("result.input === 'k9'"));
eval(t.TEST("t.unify(result.groups, {a: '9'})"));
},
function test_groupsMatch(t) {
"use strict";
eval(t.TEST("RE2('(?\\\\w)(?\\\\d)', 'g').replace('a1b2c', '$2$1') === '1a2bc'"));
eval(t.TEST("RE2('(?\\\\w)(?\\\\d)', 'g').replace('a1b2c', '$$') === '1a2bc'"));
eval(t.TEST("RE2('(?\\\\w)(?\\\\d)', 'g').replace('a1b2c', replacerByNumbers) === '1a2bc'"));
eval(t.TEST("RE2('(?\\\\w)(?\\\\d)', 'g').replace('a1b2c', replacerByNames) === '1a2bc'"));
function replacerByNumbers(match, group1, group2, index, source, groups) {
return group2 + group1;
}
function replacerByNames(match, group1, group2, index, source, groups) {
return groups.d + groups.w;
}
},
function test_groupsInvalid(t) {
"use strict";
try {
RE2('(?<>.)');
t.test(false); // shouldn'be here
} catch(e) {
eval(t.TEST("e instanceof SyntaxError"));
}
// TODO: do we need to enforce the correct id?
// try {
// RE2('(?<1>.)');
// t.test(false); // shouldn'be here
// } catch(e) {
// eval(t.TEST("e instanceof SyntaxError"));
// }
try {
RE2('(?.)(?.)');
t.test(false); // shouldn'be here
} catch(e) {
eval(t.TEST("e instanceof SyntaxError"));
}
}
]);
node-re2-1.10.5/tests/test_invalid.js000066400000000000000000000015631357256744100174210ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_inval(t) {
"use strict";
var threw;
// Backreferences
threw = false;
try {
new RE2(/(a)\1/);
} catch (e) {
threw = true;
eval(t.TEST("e instanceof SyntaxError"));
eval(t.TEST("e.message === 'invalid escape sequence: \\\\1'"));
}
t.test(threw);
// Lookahead assertions
// Positive
threw = false;
try {
new RE2(/a(?=b)/);
} catch (e) {
threw = true;
eval(t.TEST("e instanceof SyntaxError"));
eval(t.TEST("e.message === 'invalid perl operator: (?='"));
}
t.test(threw);
// Negative
threw = false;
try {
new RE2(/a(?!b)/);
} catch (e) {
threw = true;
eval(t.TEST("e instanceof SyntaxError"));
eval(t.TEST("e.message === 'invalid perl operator: (?!'"));
}
t.test(threw);
},
]);
node-re2-1.10.5/tests/test_match.js000066400000000000000000000066041357256744100170700ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
function test_match(t) {
"use strict";
var str = "For more information, see Chapter 3.4.5.1";
var re = new RE2(/(chapter \d+(\.\d)*)/i);
var result = re.match(str);
eval(t.TEST("result.input === str"));
eval(t.TEST("result.index === 26"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[1] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
function test_matchGlobal(t) {
"use strict";
var re = new RE2(/[A-E]/gi);
var result = re.match("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
eval(t.TEST("t.unify(result, ['A', 'B', 'C', 'D', 'E', 'a', 'b', 'c', 'd', 'e'])"));
},
function test_matchFail(t) {
"use strict";
var re = new RE2("(a+)?(b+)?");
var result = re.match("aaabb");
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === 'bb'"));
result = re.match("aaacbb");
eval(t.TEST("result[1] === 'aaa'"));
eval(t.TEST("result[2] === undefined"));
},
function test_matchInvalid(t) {
"use strict";
var re = RE2('');
try {
re.match({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
},
// Unicode tests
function test_matchUnicode(t) {
"use strict";
var str = "Это ГЛАВА 3.4.5.1";
var re = new RE2(/(глава \d+(\.\d)*)/i);
var result = re.match(str);
eval(t.TEST("result.input === str"));
eval(t.TEST("result.index === 4"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[1] === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
// Buffer tests
function test_matchBuffer(t) {
"use strict";
var buf = new Buffer("Это ГЛАВА 3.4.5.1");
var re = new RE2(/(глава \d+(\.\d)*)/i);
var result = re.match(buf);
eval(t.TEST("result.input instanceof Buffer"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] instanceof Buffer"));
eval(t.TEST("result[1] instanceof Buffer"));
eval(t.TEST("result[2] instanceof Buffer"));
eval(t.TEST("result.input === buf"));
eval(t.TEST("result.index === 7"));
eval(t.TEST("result.input.toString('utf8', result.index) === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[0].toString() === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[1].toString() === 'ГЛАВА 3.4.5.1'"));
eval(t.TEST("result[2].toString() === '.1'"));
},
// Sticky tests
function test_matchSticky(t) {
"use strict";
var re = new RE2("\\s+", "y");
eval(t.TEST("re.match('Hello world, how are you?') === null"));
re.lastIndex = 5;
var result = re.match("Hello world, how are you?");
eval(t.TEST("t.unify(result, [' '])"));
eval(t.TEST("result.index === 5"));
eval(t.TEST("re.lastIndex === 6"));
var re2 = new RE2("\\s+", "gy");
eval(t.TEST("re2.match('Hello world, how are you?') === null"));
re2.lastIndex = 5;
eval(t.TEST("re2.match('Hello world, how are you?') === null"));
var re3 = new RE2(/[A-E]/giy);
var result3 = re3.match("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
eval(t.TEST("t.unify(result3, ['A', 'B', 'C', 'D', 'E'])"));
}
]);
node-re2-1.10.5/tests/test_new.js000066400000000000000000000024471357256744100165660ustar00rootroot00000000000000"use strict";
const unit = require("heya-unit");
const RE2 = require("../re2");
// tests
unit.add(module, [
function test_newUnicodeWarnOnce(t) {
"use strict";
let errorMessage = null;
const consoleError = console.error;
console.error = msg => (errorMessage = msg);
RE2.unicodeWarningLevel = "warnOnce";
let a = new RE2(".*");
eval(t.TEST("errorMessage"));
errorMessage = null;
a = new RE2(".?");
eval(t.TEST("errorMessage === null"));
RE2.unicodeWarningLevel = "warnOnce";
a = new RE2(".+");
eval(t.TEST("errorMessage"));
RE2.unicodeWarningLevel = "nothing";
console.error = consoleError;
},
function test_newUnicodeWarn(t) {
"use strict";
let errorMessage = null;
const consoleError = console.error;
console.error = msg => (errorMessage = msg);
RE2.unicodeWarningLevel = "warn";
let a = new RE2(".*");
eval(t.TEST("errorMessage"));
errorMessage = null;
a = new RE2(".?");
eval(t.TEST("errorMessage"));
RE2.unicodeWarningLevel = "nothing";
console.error = consoleError;
},
function test_newUnicodeWarn(t) {
"use strict";
RE2.unicodeWarningLevel = "throw";
try {
let a = new RE2(".");
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e instanceof SyntaxError"));
}
RE2.unicodeWarningLevel = "nothing";
}
]);
node-re2-1.10.5/tests/test_prototype.js000066400000000000000000000010441357256744100200320ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_prototype(t) {
"use strict";
eval(t.TEST("RE2.prototype.source === '(?:)'"));
eval(t.TEST("RE2.prototype.flags === ''"));
eval(t.TEST("RE2.prototype.global === undefined"));
eval(t.TEST("RE2.prototype.ignoreCase === undefined"));
eval(t.TEST("RE2.prototype.multiline === undefined"));
eval(t.TEST("RE2.prototype.sticky === undefined"));
eval(t.TEST("RE2.prototype.lastIndex === undefined"));
}
]);
node-re2-1.10.5/tests/test_replace.js000066400000000000000000000163101357256744100174020ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
function test_replaceString(t) {
"use strict";
var re = new RE2(/apples/gi);
var result = re.replace("Apples are round, and apples are juicy.", "oranges");
eval(t.TEST("result === 'oranges are round, and oranges are juicy.'"));
re = new RE2(/xmas/i);
result = re.replace("Twas the night before Xmas...", "Christmas");
eval(t.TEST("result === 'Twas the night before Christmas...'"));
re = new RE2(/(\w+)\s(\w+)/);
result = re.replace("John Smith", "$2, $1");
eval(t.TEST("result === 'Smith, John'"));
},
function test_replaceFunReplacer(t) {
"use strict";
function replacer(match, p1, p2, p3, offset, string) {
// p1 is nondigits, p2 digits, and p3 non-alphanumerics
return [p1, p2, p3].join(' - ');
}
var re = new RE2(/([^\d]*)(\d*)([^\w]*)/);
var result = re.replace("abc12345#$*%", replacer);
eval(t.TEST("result === 'abc - 12345 - #$*%'"));
},
function test_replaceFunUpper(t) {
"use strict";
function upperToHyphenLower(match) {
return '-' + match.toLowerCase();
}
var re = new RE2(/[A-Z]/g);
var result = re.replace("borderTop", upperToHyphenLower);
eval(t.TEST("result === 'border-top'"));
},
function test_replaceFunConvert(t) {
"use strict";
function convert(str, p1, offset, s) {
return ((p1 - 32) * 5/9) + 'C';
}
var re = new RE2(/(\d+(?:\.\d*)?)F\b/g);
eval(t.TEST("re.replace('32F', convert) === '0C'"));
eval(t.TEST("re.replace('41F', convert) === '5C'"));
eval(t.TEST("re.replace('50F', convert) === '10C'"));
eval(t.TEST("re.replace('59F', convert) === '15C'"));
eval(t.TEST("re.replace('68F', convert) === '20C'"));
eval(t.TEST("re.replace('77F', convert) === '25C'"));
eval(t.TEST("re.replace('86F', convert) === '30C'"));
eval(t.TEST("re.replace('95F', convert) === '35C'"));
eval(t.TEST("re.replace('104F', convert) === '40C'"));
eval(t.TEST("re.replace('113F', convert) === '45C'"));
eval(t.TEST("re.replace('212F', convert) === '100C'"));
},
{
test: function test_replaceFunLoop(t) {
"use strict";
RE2(/(x_*)|(-)/g).replace("x-x_", function(match, p1, p2) {
if (p1) { t.info("on: " + p1.length); }
if (p2) { t.info("off: 1"); }
});
},
logs: [
{text: "on: 1"},
{text: "off: 1"},
{text: "on: 2"}
]
},
function test_replaceInvalid(t) {
"use strict";
var re = RE2('');
try {
re.replace({ toString() { throw "corner1"; } }, '');
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner1'"));
}
try {
re.replace('', { toString() { throw "corner2"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner2'"));
}
var arg2Stringified = false;
try {
re.replace({ toString() { throw "corner1"; } }, { toString() { arg2Stringified = true; throw "corner2"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner1'"));
eval(t.TEST("!arg2Stringified"));
}
try {
re.replace('', () => { throw "corner2"; });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner2'"));
}
try {
re.replace('', () => ({ toString() { throw "corner2"; } }));
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner2'"));
}
},
// Unicode tests
function test_replaceStrUnicode(t) {
"use strict";
var re = new RE2(/яблоки/gi);
var result = re.replace("Яблоки красны, яблоки сочны.", "апельсины");
eval(t.TEST("result === 'апельсины красны, апельсины сочны.'"));
re = new RE2(/иван/i);
result = re.replace("Могуч Иван Иванов...", "Сидор");
eval(t.TEST("result === 'Могуч Сидор Иванов...'"));
re = new RE2(/иван/ig);
result = re.replace("Могуч Иван Иванов...", "Сидор");
eval(t.TEST("result === 'Могуч Сидор Сидоров...'"));
re = new RE2(/([а-яё]+)\s+([а-яё]+)/i);
result = re.replace("Пётр Петров", "$2, $1");
eval(t.TEST("result === 'Петров, Пётр'"));
},
function test_replaceFunUnicode(t) {
"use strict";
function replacer(match, offset, string) {
t.test(typeof offset == "number");
t.test(typeof string == "string");
t.test(offset === 0 || offset === 7);
t.test(string === "ИВАН и пЁтр");
return match.charAt(0).toUpperCase() + match.substr(1).toLowerCase();
}
var re = new RE2(/(?:иван|пётр|сидор)/ig);
var result = re.replace("ИВАН и пЁтр", replacer);
eval(t.TEST("result === 'Иван и Пётр'"));
},
// Buffer tests
function test_replaceStrBuffer(t) {
"use strict";
var re = new RE2(/яблоки/gi);
var result = re.replace(new Buffer("Яблоки красны, яблоки сочны."), "апельсины");
eval(t.TEST("result instanceof Buffer"));
eval(t.TEST("result.toString() === 'апельсины красны, апельсины сочны.'"));
result = re.replace(new Buffer("Яблоки красны, яблоки сочны."), new Buffer("апельсины"));
eval(t.TEST("result instanceof Buffer"));
eval(t.TEST("result.toString() === 'апельсины красны, апельсины сочны.'"));
result = re.replace("Яблоки красны, яблоки сочны.", new Buffer("апельсины"));
eval(t.TEST("typeof result == 'string'"));
eval(t.TEST("result === 'апельсины красны, апельсины сочны.'"));
},
function test_replaceFunBuffer(t) {
"use strict";
function replacer(match, offset, string) {
eval(t.TEST("match instanceof Buffer"));
eval(t.TEST("typeof offset == 'number'"));
eval(t.TEST("typeof string == 'string'"));
eval(t.TEST("offset === 0 || offset === 12"));
eval(t.TEST("string === 'ИВАН и пЁтр'"));
var s = match.toString();
return s.charAt(0).toUpperCase() + s.substr(1).toLowerCase();
}
replacer.useBuffers = true;
var re = new RE2(/(?:иван|пётр|сидор)/ig);
var result = re.replace("ИВАН и пЁтр", replacer);
eval(t.TEST("typeof result == 'string'"));
eval(t.TEST("result === 'Иван и Пётр'"));
},
// Sticky tests
function test_replaceSticky(t) {
"use strict";
var re = new RE2(/[A-E]/y);
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === '!BCDEFABCDEF'"));
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === 'A!CDEFABCDEF'"));
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === 'AB!DEFABCDEF'"));
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === 'ABC!EFABCDEF'"));
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === 'ABCD!FABCDEF'"));
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === 'ABCDEFABCDEF'"));
eval(t.TEST("re.replace('ABCDEFABCDEF', '!') === '!BCDEFABCDEF'"));
var re2 = new RE2(/[A-E]/gy);
eval(t.TEST("re2.replace('ABCDEFABCDEF', '!') === '!!!!!FABCDEF'"));
eval(t.TEST("re2.replace('FABCDEFABCDE', '!') === 'FABCDEFABCDE'"));
re2.lastIndex = 3;
eval(t.TEST("re2.replace('ABCDEFABCDEF', '!') === '!!!!!FABCDEF'"));
eval(t.TEST("re2.lastIndex === 0"));
}
]);
node-re2-1.10.5/tests/test_search.js000066400000000000000000000042041357256744100172330ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_search(t) {
"use strict";
var str = "Total is 42 units.";
var re = new RE2(/\d+/i);
var result = re.search(str);
eval(t.TEST("result === 9"));
re = new RE2("\\b[a-z]+\\b");
result = re.search(str);
eval(t.TEST("result === 6"));
re = new RE2("\\b\\w+\\b");
result = re.search(str);
eval(t.TEST("result === 0"));
re = new RE2("z", "gm");
result = re.search(str);
eval(t.TEST("result === -1"));
},
function test_searchInvalid(t) {
"use strict";
var re = RE2('');
try {
re.search({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
},
function test_searchUnicode(t) {
"use strict";
var str = "Всего 42 штуки.";
var re = new RE2(/\d+/i);
var result = re.search(str);
eval(t.TEST("result === 6"));
re = new RE2("\\s[а-я]+");
result = re.search(str);
eval(t.TEST("result === 8"));
re = new RE2("[а-яА-Я]+");
result = re.search(str);
eval(t.TEST("result === 0"));
re = new RE2("z", "gm");
result = re.search(str);
eval(t.TEST("result === -1"));
},
function test_searchBuffer(t) {
"use strict";
var buf = new Buffer("Всего 42 штуки.");
var re = new RE2(/\d+/i);
var result = re.search(buf);
eval(t.TEST("result === 11"));
re = new RE2("\\s[а-я]+");
result = re.search(buf);
eval(t.TEST("result === 13"));
re = new RE2("[а-яА-Я]+");
result = re.search(buf);
eval(t.TEST("result === 0"));
re = new RE2("z", "gm");
result = re.search(buf);
eval(t.TEST("result === -1"));
},
function test_searchSticky(t) {
"use strict";
var str = "Total is 42 units.";
var re = new RE2(/\d+/y);
var result = re.search(str);
eval(t.TEST("result === -1"));
re = new RE2("\\b[a-z]+\\b", "y");
result = re.search(str);
eval(t.TEST("result === -1"));
re = new RE2("\\b\\w+\\b", "y");
result = re.search(str);
eval(t.TEST("result === 0"));
re = new RE2("z", "gmy");
result = re.search(str);
eval(t.TEST("result === -1"));
}
]);
node-re2-1.10.5/tests/test_source.js000066400000000000000000000035671357256744100173010ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_sourceIdentity(t) {
"use strict";
var re = new RE2("a\\cM\\u34\\u1234\\u10abcdz");
eval(t.TEST("re.source === 'a\\\\cM\\\\u34\\\\u1234\\\\u10abcdz'"));
re = new RE2("a\\cM\\u34\\u1234\\u{10abcd}z");
eval(t.TEST("re.source === 'a\\\\cM\\\\u34\\\\u1234\\\\u{10abcd}z'"));
re = new RE2("");
eval(t.TEST("re.source === '(?:)'"));
re = new RE2("foo/bar");
eval(t.TEST("re.source === 'foo\\\\/bar'"));
re = new RE2("foo\\/bar");
eval(t.TEST("re.source === 'foo\\\\/bar'"));
re = new RE2("(?bar)", "u");
eval(t.TEST("re.source === '(?bar)'"));
},
function test_sourceTranslation(t) {
"use strict";
var re = new RE2("a\\cM\\u34\\u1234\\u10abcdz");
eval(t.TEST("re.internalSource === 'a\\\\x0D\\\\x{34}\\\\x{1234}\\\\x{10ab}cdz'"));
re = new RE2("a\\cM\\u34\\u1234\\u{10abcd}z");
eval(t.TEST("re.internalSource === 'a\\\\x0D\\\\x{34}\\\\x{1234}\\\\x{10abcd}z'"));
re = new RE2("");
eval(t.TEST("re.internalSource === '(?:)'"));
re = new RE2("foo/bar");
eval(t.TEST("re.internalSource === 'foo\\\\/bar'"));
re = new RE2("foo\\/bar");
eval(t.TEST("re.internalSource === 'foo\\\\/bar'"));
re = new RE2("(?bar)", "u");
eval(t.TEST("re.internalSource === '(?Pbar)'"));
},
function test_sourceBackSlashes(t) {
"use strict";
function compare(source, expected) {
var s = new RE2(source).source;
eval(t.TEST("s === expected"));
}
compare("a/b", "a\\/b");
compare("a\/b", "a\\/b");
compare("a\\/b", "a\\/b");
compare("a\\\/b", "a\\/b");
compare("a\\\\/b", "a\\\\\\/b");
compare("a\\\\\/b", "a\\\\\\/b");
compare("/a/b", "\\/a\\/b");
compare("\\/a/b", "\\/a\\/b");
compare("\\/a\\/b", "\\/a\\/b");
compare("\\/a\\\\/b", "\\/a\\\\\\/b");
}
]);
node-re2-1.10.5/tests/test_split.js000066400000000000000000000123631357256744100171260ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
function test_split(t) {
"use strict";
var re = new RE2(/\s+/);
var result = re.split("Oh brave new world that has such people in it.");
eval(t.TEST("t.unify(result, ['Oh', 'brave', 'new', 'world', 'that', 'has', 'such', 'people', 'in', 'it.'])"));
re = new RE2(",");
result = re.split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec");
eval(t.TEST("t.unify(result, ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])"));
re = new RE2(",");
result = re.split(",Jan,Feb,Mar,Apr,May,Jun,,Jul,Aug,Sep,Oct,Nov,Dec,");
eval(t.TEST("t.unify(result, ['','Jan','Feb','Mar','Apr','May','Jun','','Jul','Aug','Sep','Oct','Nov','Dec',''])"));
re = new RE2(/\s*;\s*/);
result = re.split("Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ");
eval(t.TEST("t.unify(result, ['Harry Trump', 'Fred Barney', 'Helen Rigby', 'Bill Abel', 'Chris Hand '])"));
re = new RE2(/\s+/);
result = re.split("Hello World. How are you doing?", 3);
eval(t.TEST("t.unify(result, ['Hello', 'World.', 'How'])"));
re = new RE2(/(\d)/);
result = re.split("Hello 1 word. Sentence number 2.");
eval(t.TEST("t.unify(result, ['Hello ', '1', ' word. Sentence number ', '2', '.'])"));
eval(t.TEST("RE2(/[x-z]*/).split('asdfghjkl').reverse().join('') === 'lkjhgfdsa'"));
},
function test_splitInvalid(t) {
"use strict";
var re = RE2('');
try {
re.split({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
},
function test_cornerCases(t) {
"use strict";
var re = new RE2(/1/);
var result = re.split("23456");
eval(t.TEST("t.unify(result, ['23456'])"));
},
// Unicode tests
function test_splitUnicode(t) {
"use strict";
var re = new RE2(/\s+/);
var result = re.split("Она не понимает, что этим убивает меня.");
eval(t.TEST("t.unify(result, ['Она', 'не', 'понимает,', 'что', 'этим', 'убивает', 'меня.'])"));
re = new RE2(",");
result = re.split("Пн,Вт,Ср,Чт,Пт,Сб,Вс");
eval(t.TEST("t.unify(result, ['Пн','Вт','Ср','Чт','Пт','Сб','Вс'])"));
re = new RE2(/\s*;\s*/);
result = re.split("Ваня Иванов ;Петро Петренко; Саша Машин ; Маша Сашина");
eval(t.TEST("t.unify(result, ['Ваня Иванов', 'Петро Петренко', 'Саша Машин', 'Маша Сашина'])"));
re = new RE2(/\s+/);
result = re.split("Привет мир. Как дела?", 3);
eval(t.TEST("t.unify(result, ['Привет', 'мир.', 'Как'])"));
re = new RE2(/(\d)/);
result = re.split("Привет 1 слово. Предложение номер 2.");
eval(t.TEST("t.unify(result, ['Привет ', '1', ' слово. Предложение номер ', '2', '.'])"));
eval(t.TEST("RE2(/[э-я]*/).split('фывапролд').reverse().join('') === 'длорпавыф'"));
},
// Buffer tests
function test_splitBuffer(t) {
"use strict";
var re = new RE2(/\s+/);
var result = re.split(new Buffer("Она не понимает, что этим убивает меня."));
eval(t.TEST("t.unify(verifyBuffer(result, t), ['Она', 'не', 'понимает,', 'что', 'этим', 'убивает', 'меня.'])"));
re = new RE2(",");
result = re.split(new Buffer("Пн,Вт,Ср,Чт,Пт,Сб,Вс"));
eval(t.TEST("t.unify(verifyBuffer(result, t), ['Пн','Вт','Ср','Чт','Пт','Сб','Вс'])"));
re = new RE2(/\s*;\s*/);
result = re.split(new Buffer("Ваня Иванов ;Петро Петренко; Саша Машин ; Маша Сашина"));
eval(t.TEST("t.unify(verifyBuffer(result, t), ['Ваня Иванов', 'Петро Петренко', 'Саша Машин', 'Маша Сашина'])"));
re = new RE2(/\s+/);
result = re.split(new Buffer("Привет мир. Как дела?"), 3);
eval(t.TEST("t.unify(verifyBuffer(result, t), ['Привет', 'мир.', 'Как'])"));
re = new RE2(/(\d)/);
result = re.split(new Buffer("Привет 1 слово. Предложение номер 2."));
eval(t.TEST("t.unify(verifyBuffer(result, t), ['Привет ', '1', ' слово. Предложение номер ', '2', '.'])"));
eval(t.TEST("RE2(/[э-я]*/).split(new Buffer('фывапролд')).map(function(x) { return x.toString(); }).reverse().join('') === 'длорпавыф'"));
},
// Sticky tests
function test_splitSticky(t) {
"use strict";
var re = new RE2(/\s+/y); // sticky is ignored
var result = re.split("Oh brave new world that has such people in it.");
eval(t.TEST("t.unify(result, ['Oh', 'brave', 'new', 'world', 'that', 'has', 'such', 'people', 'in', 'it.'])"));
var result2 = re.split(" Oh brave new world that has such people in it.");
eval(t.TEST("t.unify(result2, ['', 'Oh', 'brave', 'new', 'world', 'that', 'has', 'such', 'people', 'in', 'it.'])"));
}
]);
function verifyBuffer(buf, t) {
return buf.map(function(x) {
t.test(x instanceof Buffer);
return x.toString();
});
}
node-re2-1.10.5/tests/test_symbols.js000066400000000000000000000055121357256744100174610ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_match_symbol (t) {
"use strict";
if (typeof Symbol == 'undefined' || !Symbol.match) return;
var str = "For more information, see Chapter 3.4.5.1";
var re = new RE2(/(chapter \d+(\.\d)*)/i);
var result = str.match(re);
eval(t.TEST("result.input === str"));
eval(t.TEST("result.index === 26"));
eval(t.TEST("result.length === 3"));
eval(t.TEST("result[0] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[1] === 'Chapter 3.4.5.1'"));
eval(t.TEST("result[2] === '.1'"));
},
function test_search_symbol (t) {
"use strict";
if (typeof Symbol == 'undefined' || !Symbol.search) return;
var str = "Total is 42 units.";
var re = new RE2(/\d+/i);
var result = str.search(re);
eval(t.TEST("result === 9"));
re = new RE2("\\b[a-z]+\\b");
result = str.search(re);
eval(t.TEST("result === 6"));
re = new RE2("\\b\\w+\\b");
result = str.search(re);
eval(t.TEST("result === 0"));
re = new RE2("z", "gm");
result = str.search(re);
eval(t.TEST("result === -1"));
},
function test_replace_symbol (t) {
"use strict";
if (typeof Symbol == 'undefined' || !Symbol.replace) return;
var re = new RE2(/apples/gi);
var result = "Apples are round, and apples are juicy.".replace(re, "oranges");
eval(t.TEST("result === 'oranges are round, and oranges are juicy.'"));
re = new RE2(/xmas/i);
result = "Twas the night before Xmas...".replace(re, "Christmas");
eval(t.TEST("result === 'Twas the night before Christmas...'"));
re = new RE2(/(\w+)\s(\w+)/);
result = "John Smith".replace(re, "$2, $1");
eval(t.TEST("result === 'Smith, John'"));
},
function test_split(t) {
"use strict";
if (typeof Symbol == 'undefined' || !Symbol.split) return;
var re = new RE2(/\s+/);
var result = "Oh brave new world that has such people in it.".split(re);
eval(t.TEST("t.unify(result, ['Oh', 'brave', 'new', 'world', 'that', 'has', 'such', 'people', 'in', 'it.'])"));
re = new RE2(",");
result = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(re);
eval(t.TEST("t.unify(result, ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])"));
re = new RE2(/\s*;\s*/);
result = "Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ".split(re);
eval(t.TEST("t.unify(result, ['Harry Trump', 'Fred Barney', 'Helen Rigby', 'Bill Abel', 'Chris Hand '])"));
re = new RE2(/\s+/);
result = "Hello World. How are you doing?".split(re, 3);
eval(t.TEST("t.unify(result, ['Hello', 'World.', 'How'])"));
re = new RE2(/(\d)/);
result = "Hello 1 word. Sentence number 2.".split(re);
eval(t.TEST("t.unify(result, ['Hello ', '1', ' word. Sentence number ', '2', '.'])"));
eval(t.TEST("'asdfghjkl'.split(RE2(/[x-z]*/)).reverse().join('') === 'lkjhgfdsa'"));
}
]);
node-re2-1.10.5/tests/test_test.js000066400000000000000000000127221357256744100167510ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
// These tests are copied from MDN:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test
function test_testFromExec(t) {
"use strict";
var re = new RE2("quick\\s(brown).+?(jumps)", "i");
eval(t.TEST("re.test('The Quick Brown Fox Jumps Over The Lazy Dog')"));
eval(t.TEST("re.test('tHE qUICK bROWN fOX jUMPS oVER tHE lAZY dOG')"));
eval(t.TEST("re.test('the quick brown fox jumps over the lazy dog')"));
eval(t.TEST("re.test('THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG')"));
eval(t.TEST("!re.test('THE KWIK BROWN FOX JUMPS OVER THE LAZY DOG')"));
re = new RE2("ab*", "g");
eval(t.TEST("re.test('abbcdefabh')"));
eval(t.TEST("!re.test('qwerty')"));
re = new RE2("(hello \\S+)");
eval(t.TEST("re.test('This is a hello world!')"));
eval(t.TEST("!re.test('This is a Hello world!')"));
},
function test_testSucc(t) {
"use strict";
var str = "abbcdefabh";
var re = new RE2("ab*", "g");
var result = re.test(str);
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 3"));
result = re.test(str);
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 9"));
result = re.test(str);
eval(t.TEST("!result"));
},
function test_testSimple(t) {
"use strict";
var str = "abbcdefabh";
var re1 = new RE2("ab*", "g");
eval(t.TEST("re1.test(str)"));
var re2 = new RE2("ab*");
eval(t.TEST("re2.test(str)"));
var re3 = new RE2("abc");
eval(t.TEST("!re3.test(str)"));
},
function test_testAnchoredToBeginning(t) {
"use strict";
var re = RE2('^hello', 'g');
eval(t.TEST("re.test('hellohello')"));
eval(t.TEST("!re.test('hellohello')"));
},
function test_testInvalid(t) {
"use strict";
var re = RE2('');
try {
re.test({ toString() { throw "corner"; } });
t.test(false); // shouldn't be here
} catch(e) {
eval(t.TEST("e === 'corner'"));
}
},
function test_testAnchor1(t) {
"use strict";
var re = new RE2("b|^a", "g");
var result = re.test("aabc");
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 1"));
result = re.test("aabc");
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 3"));
result = re.test("aabc");
eval(t.TEST("!result"));
},
function test_testAnchor2(t) {
"use strict";
var re = new RE2("(?:^a)", "g");
var result = re.test("aabc");
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 1"));
result = re.test("aabc");
eval(t.TEST("!result"));
},
// Unicode tests
function test_testUnicode(t) {
"use strict";
var re = new RE2("охотник\\s(желает).+?(где)", "i");
eval(t.TEST("re.test('Каждый Охотник Желает Знать Где Сидит Фазан')"));
eval(t.TEST("re.test('кАЖДЫЙ оХОТНИК жЕЛАЕТ зНАТЬ гДЕ сИДИТ фАЗАН')"));
eval(t.TEST("re.test('каждый охотник желает знать где сидит фазан')"));
eval(t.TEST("re.test('КАЖДЫЙ ОХОТНИК ЖЕЛАЕТ ЗНАТЬ ГДЕ СИДИТ ФАЗАН')"));
eval(t.TEST("!re.test('Кажный Стрелок Хочет Найти Иде Прячется Птица')"));
re = new RE2("аб*", "g");
eval(t.TEST("re.test('аббвгдеабё')"));
eval(t.TEST("!re.test('йцукен')"));
re = new RE2("(привет \\S+)");
eval(t.TEST("re.test('Это просто привет всем.')"));
eval(t.TEST("!re.test('Это просто Привет всем.')"));
},
function test_testUnicodeSubsequent(t) {
"use strict";
var str = "аббвгдеабё";
var re = new RE2("аб*", "g");
var result = re.test(str);
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 3"));
result = re.test(str);
eval(t.TEST("result"));
eval(t.TEST("re.lastIndex === 9"));
result = re.test(str);
eval(t.TEST("!result"));
},
// Buffer tests
function test_testBuffer(t) {
"use strict";
var re = new RE2("охотник\\s(желает).+?(где)", "i");
eval(t.TEST("re.test(new Buffer('Каждый Охотник Желает Знать Где Сидит Фазан'))"));
eval(t.TEST("re.test(new Buffer('кАЖДЫЙ оХОТНИК жЕЛАЕТ зНАТЬ гДЕ сИДИТ фАЗАН'))"));
eval(t.TEST("re.test(new Buffer('каждый охотник желает знать где сидит фазан'))"));
eval(t.TEST("re.test(new Buffer('КАЖДЫЙ ОХОТНИК ЖЕЛАЕТ ЗНАТЬ ГДЕ СИДИТ ФАЗАН'))"));
eval(t.TEST("!re.test(new Buffer('Кажный Стрелок Хочет Найти Иде Прячется Птица'))"));
re = new RE2("аб*", "g");
eval(t.TEST("re.test(new Buffer('аббвгдеабё'))"));
eval(t.TEST("!re.test(new Buffer('йцукен'))"));
re = new RE2("(привет \\S+)");
eval(t.TEST("re.test(new Buffer('Это просто привет всем.'))"));
eval(t.TEST("!re.test(new Buffer('Это просто Привет всем.'))"));
},
// Sticky tests
function test_testSticky(t) {
"use strict";
var re = new RE2("\\s+", "y");
eval(t.TEST("!re.test('Hello world, how are you?')"));
re.lastIndex = 5;
eval(t.TEST("re.test('Hello world, how are you?')"));
eval(t.TEST("re.lastIndex === 6"));
var re2 = new RE2("\\s+", "gy");
eval(t.TEST("!re2.test('Hello world, how are you?')"));
re2.lastIndex = 5;
eval(t.TEST("re2.test('Hello world, how are you?')"));
eval(t.TEST("re2.lastIndex === 6"));
}
]);
node-re2-1.10.5/tests/test_toString.js000066400000000000000000000017721357256744100176060ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
var RE2 = require("../re2");
// tests
unit.add(module, [
function test_toString(t) {
"use strict";
eval(t.TEST("RE2('').toString() === '/(?:)/u'"));
eval(t.TEST("RE2('a').toString() === '/a/u'"));
eval(t.TEST("RE2('b', 'i').toString() === '/b/iu'"));
eval(t.TEST("RE2('c', 'g').toString() === '/c/gu'"));
eval(t.TEST("RE2('d', 'm').toString() === '/d/mu'"));
eval(t.TEST("RE2('\\\\d+', 'gi') + '' === '/\\\\d+/giu'"));
eval(t.TEST("RE2('\\\\s*', 'gm') + '' === '/\\\\s*/gmu'"));
eval(t.TEST("RE2('\\\\S{1,3}', 'ig') + '' === '/\\\\S{1,3}/giu'"));
eval(t.TEST("RE2('\\\\D{,2}', 'mig') + '' === '/\\\\D{,2}/gimu'"));
eval(t.TEST("RE2('^a{2,}', 'mi') + '' === '/^a{2,}/imu'"));
eval(t.TEST("RE2('^a{5}$', 'gim') + '' === '/^a{5}$/gimu'"));
eval(t.TEST("RE2('\\\\u{1F603}/', 'iy') + '' === '/\\\\x{1F603}\\\\//iuy'"));
eval(t.TEST("RE2('c', 'ug').toString() === '/c/gu'"));
eval(t.TEST("RE2('d', 'um').toString() === '/d/mu'"));
}
]);
node-re2-1.10.5/tests/tests.js000066400000000000000000000006531357256744100160750ustar00rootroot00000000000000"use strict";
var unit = require("heya-unit");
require("./test_general");
require("./test_source");
require("./test_exec");
require("./test_test");
require("./test_toString");
require("./test_match");
require("./test_replace");
require("./test_search");
require("./test_split");
require("./test_invalid");
require("./test_symbols");
require("./test_prototype");
require("./test_new");
require("./test_groups");
unit.run();
node-re2-1.10.5/vendor/000077500000000000000000000000001357256744100145245ustar00rootroot00000000000000