Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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('(?<a>\\\\d)').test('9')"));
eval(t.TEST("t.unify(RE2('(?</a><a>-)', 'g').match('a-b-c'), ['-', '-'])"));
eval(t.TEST("t.unify(RE2('(?</a><a>-)').split('a-b-c'), ['a', '-', 'b', '-', 'c'])"));
eval(t.TEST("RE2('(?</a><a>-)', '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"));</a>
"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/u);
} catch (e) {
threw = true;
eval(t.TEST("e instanceof SyntaxError"));
eval(t.TEST("e.message === 'invalid escape sequence: \\\\1'"));
}
t.test(threw);
"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() === '/(?:)/'"));
eval(t.TEST("RE2('a').toString() === '/a/'"));
eval(t.TEST("RE2('b', 'i').toString() === '/b/i'"));
eval(t.TEST("RE2('c', 'g').toString() === '/c/g'"));
eval(t.TEST("RE2('d', 'm').toString() === '/d/m'"));
eval(t.TEST("RE2('\\\\d+', 'gi') + '' === '/\\\\d+/ig'"));
eval(t.TEST("RE2('\\\\s*', 'gm') + '' === '/\\\\s*/gm'"));
eval(t.TEST("RE2('\\\\S{1,3}', 'ig') + '' === '/\\\\S{1,3}/ig'"));
eval(t.TEST("RE2('\\\\D{,2}', 'mig') + '' === '/\\\\D{,2}/igm'"));
eval(t.TEST("RE2('^a{2,}', 'mi') + '' === '/^a{2,}/im'"));
eval(t.TEST("RE2('^a{5}$', 'gim') + '' === '/^a{5}$/igm'"));
eval(t.TEST("RE2('\\\\u{1F603}/', 'iy') + '' === '/\\\\x{1F603}\\\\//iy'"));
}
"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"));
}
]);
"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+");
"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+)/);
"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");