Sha256: 337940b4806855cfcc0b97e88763b48c7d46c633710127a6790f3e832746e50b

Contents?: true

Size: 1.76 KB

Versions: 67

Compression:

Stored size: 1.76 KB

Contents

'use strict';

var test = require('tape');
var isRegex = require('./');
var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';

test('not regexes', function (t) {
	t.notOk(isRegex(), 'undefined is not regex');
	t.notOk(isRegex(null), 'null is not regex');
	t.notOk(isRegex(false), 'false is not regex');
	t.notOk(isRegex(true), 'true is not regex');
	t.notOk(isRegex(42), 'number is not regex');
	t.notOk(isRegex('foo'), 'string is not regex');
	t.notOk(isRegex([]), 'array is not regex');
	t.notOk(isRegex({}), 'object is not regex');
	t.notOk(isRegex(function () {}), 'function is not regex');
	t.end();
});

test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
	var regex = /a/g;
	var fakeRegex = {
		toString: function () { return String(regex); },
		valueOf: function () { return regex; }
	};
	fakeRegex[Symbol.toStringTag] = 'RegExp';
	t.notOk(isRegex(fakeRegex), 'fake RegExp with @@toStringTag "RegExp" is not regex');
	t.end();
});

test('regexes', function (t) {
	t.ok(isRegex(/a/g), 'regex literal is regex');
	t.ok(isRegex(new RegExp('a', 'g')), 'regex object is regex');
	t.end();
});

test('does not mutate regexes', function (t) {
	t.test('lastIndex is a marker object', function (st) {
		var regex = /a/;
		var marker = {};
		regex.lastIndex = marker;
		st.equal(regex.lastIndex, marker, 'lastIndex is the marker object');
		st.ok(isRegex(regex), 'is regex');
		st.equal(regex.lastIndex, marker, 'lastIndex is the marker object after isRegex');
		st.end();
	});

	t.test('lastIndex is nonzero', function (st) {
		var regex = /a/;
		regex.lastIndex = 3;
		st.equal(regex.lastIndex, 3, 'lastIndex is 3');
		st.ok(isRegex(regex), 'is regex');
		st.equal(regex.lastIndex, 3, 'lastIndex is 3 after isRegex');
		st.end();
	});

	t.end();
});

Version data entries

67 entries across 67 versions & 10 rubygems

Version Path
disco_app-0.18.0 test/dummy/node_modules/is-regex/test.js
disco_app-0.18.2 test/dummy/node_modules/is-regex/test.js
disco_app-0.16.1 test/dummy/node_modules/is-regex/test.js
disco_app-0.15.2 test/dummy/node_modules/is-regex/test.js
disco_app-0.18.4 test/dummy/node_modules/is-regex/test.js
disco_app-0.18.1 test/dummy/node_modules/is-regex/test.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/is-regex/test.js
disco_app-0.14.0 test/dummy/node_modules/is-regex/test.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/is-regex/test.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/is-regex/test.js
jester-data-8.0.0 node_modules/is-regex/test.js
ezii-os-5.2.1 node_modules/is-regex/test.js
ezii-os-2.0.1 node_modules/is-regex/test.js
ezii-os-1.1.0 node_modules/is-regex/test.js
ezii-os-1.0.0 node_modules/is-regex/test.js
ezii-os-0.0.0.1.0 node_modules/is-regex/test.js
ezii-os-0.0.0.0.1 node_modules/is-regex/test.js
govuk_publishing_components-18.0.0 node_modules/is-regex/test.js
govuk_publishing_components-17.21.0 node_modules/is-regex/test.js
govuk_publishing_components-17.20.0 node_modules/is-regex/test.js