forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (31 loc) · 1.03 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var assert = require('assert');
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('test', function() {
it('returns true if string matches dotAll pattern', function() {
eq(R.test(/x.*z/s, 'x.\nyz'), true);
});
it('returns true if string matches pattern', function() {
eq(R.test(/^x/, 'xyz'), true);
});
it('returns false if string does not match pattern', function() {
eq(R.test(/^y/, 'xyz'), false);
});
it('is referentially transparent', function() {
var pattern = /x/g;
eq(pattern.lastIndex, 0);
eq(R.test(pattern, 'xyz'), true);
eq(pattern.lastIndex, 0);
eq(R.test(pattern, 'xyz'), true);
});
it('throws if first argument is not a regexp', function() {
assert.throws(
function() { R.test('foo', 'bar'); },
function(err) {
return err.constructor === TypeError &&
err.message === '‘test’ requires a value of type RegExp ' +
'as its first argument; received "foo"';
}
);
});
});