How to use heya-unit - 7 common examples

To help you get started, we’ve selected a few heya-unit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uhop / node-re2 / tests / test_groups.js View on Github external
"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>
github uhop / node-re2 / tests / test_invalid.js View on Github external
"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);
github uhop / node-re2 / tests / test_toString.js View on Github external
"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'"));
	}
github uhop / node-re2 / tests / test_prototype.js View on Github external
"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"));
	}
]);
github uhop / node-re2 / tests / test_general.js View on Github external
"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+");
github uhop / node-re2 / tests / test_replace.js View on Github external
"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+)/);
github uhop / node-re2 / tests / test_source.js View on Github external
"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");

heya-unit

Super simple unit test harness.

BSD
Latest version published 9 years ago

Package Health Score

42 / 100
Full package analysis

Popular heya-unit functions