-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
129 lines (112 loc) · 5.98 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
'use strict';
require('mocha');
var assert = require('assert');
var isPosixBracket = require('./');
describe('isPosixBracket', function() {
it('should not match non-character classes:', function() {
assert.equal(isPosixBracket('foo[[lower:]]bar'), false);
assert.equal(isPosixBracket('foo[[lower]]bar'), false);
});
it('should not match imbalanced character classes:', function() {
assert.equal(isPosixBracket('foo[:[lower:]]bar'), false);
assert.equal(isPosixBracket('foo[:[:lower]]bar'), false);
assert.equal(isPosixBracket('foo[:[:lower]]:bar'), false);
// this one's a maybe
assert.equal(isPosixBracket('foo[:[:lower]:]bar'), false);
});
it('should match character classes:', function() {
assert.equal(isPosixBracket('foo[:[:lower:]:]bar'), true);
assert.equal(isPosixBracket('foo[[:lower:]]bar'), true);
assert.equal(isPosixBracket('foo[[:lower:][:upper:]]bar'), true);
assert.equal(isPosixBracket('[[:alpha:]123]'), true);
assert.equal(isPosixBracket('[[:lower:]]'), true);
assert.equal(isPosixBracket('[![:lower:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:upper:][:space:]]'), true);
assert.equal(isPosixBracket('[[:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'), true);
assert.equal(isPosixBracket('[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'), true);
assert.equal(isPosixBracket('[a-c[:digit:]x-z]'), true);
assert.equal(isPosixBracket('[:al:]'), true);
assert.equal(isPosixBracket('[abc[:punct:][0-9]'), true);
});
it('should return `true` when the pattern matches:', function() {
assert.equal(isPosixBracket('[[:lower:]]'), true);
assert.equal(isPosixBracket('[[:upper:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:upper:][:space:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:upper:][:space:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:upper:][:space:]]'), true);
assert.equal(isPosixBracket('[[:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:graph:][:lower:][:print:][:punct:][:space:][:upper:][:xdigit:]]'), true);
assert.equal(isPosixBracket('[^[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'), true);
assert.equal(isPosixBracket('[a-c[:digit:]x-z]'), true);
assert.equal(isPosixBracket('[a-c[:digit:]x-z]'), true);
assert.equal(isPosixBracket('[a-c[:digit:]x-z]'), true);
});
it('should return `false` when the pattern does not match:', function() {
assert.equal(isPosixBracket('[[:lower:]]'), true);
assert.equal(isPosixBracket('[![:lower:]]'), true);
assert.equal(isPosixBracket('[[:upper:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:upper:][:space:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:upper:][:space:]]'), true);
assert.equal(isPosixBracket('[[:alnum:][:alpha:][:blank:][:cntrl:][:digit:][:lower:][:space:][:upper:][:xdigit:]]'), true);
assert.equal(isPosixBracket('[a-c[:digit:]x-z]'), true);
assert.equal(isPosixBracket('[[:alpha:]][[:digit:]][[:upper:]]'), true);
assert.equal(isPosixBracket('[[:digit:][:punct:][:space:]]'), true);
});
});
describe('POSIX: From the test suite for the POSIX.2 (BRE) pattern matching code:', function() {
it('First, test POSIX.2 character classes', function() {
assert.equal(isPosixBracket('[[:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:xdigit:]]'), true);
assert.equal(isPosixBracket('[[:alpha:]123]'), true);
assert.equal(isPosixBracket('[[:alpha:]123]'), true);
});
it('should match with POSIX.2 negation patterns', function() {
assert.equal(isPosixBracket('[![:alpha:]]'), true);
});
it('invalid character class expressions are just characters to be matched', function() {
assert.equal(isPosixBracket('[:al:]'), true);
assert.equal(isPosixBracket('[[:al:]'), true);
assert.equal(isPosixBracket('[abc[:punct:][0-9]'), true);
});
it('should match the start of a valid sh identifier', function() {
assert.equal(isPosixBracket('[_[:alpha:]]*'), true);
});
it('how about A?', function() {
assert.equal(isPosixBracket('[[:digit:]]'), true);
assert.equal(isPosixBracket('[[:digit:]]'), true);
assert.equal(isPosixBracket('[[:lower:]][[:upper:]]'), true);
assert.equal(isPosixBracket('[_[:alpha:]][_[:alnum:]][_[:alnum:]]*'), true);
assert.equal(isPosixBracket('[[:alpha:][:digit:]]'), true);
assert.equal(isPosixBracket('[[:alpha:]\\]'), true);
});
it('OK, what\'s a tab? is it a blank? a space?', function() {
assert.equal(isPosixBracket('[[:blank:]]'), true);
assert.equal(isPosixBracket('[[:space:]]'), true);
assert.equal(isPosixBracket('[[:space:]]'), true);
});
it('let\'s check out characters in the ASCII range', function() {
assert.equal(isPosixBracket('[[:ascii:]]'), true);
assert.equal(isPosixBracket('[1[:alpha:]123]'), true);
});
it('punctuation', function() {
assert.equal(isPosixBracket('[[:punct:]]'), true);
});
it('graph', function() {
assert.equal(isPosixBracket('[[:graph:]]'), true);
assert.equal(isPosixBracket('[[:graph:]]'), true);
assert.equal(isPosixBracket('[[:graph:]]'), true);
assert.equal(isPosixBracket('[[:graph:]]'), true);
});
it('and finally, test POSIX.2 equivalence classes', function() {
assert.equal(isPosixBracket('[[:alpha:]][[=b=]][[:ascii:]]'), true);
assert.equal(isPosixBracket('[[:alpha:]][[=B=]][[:ascii:]]'), true);
});
it('an incomplete equiv class is just a string', function() {
assert.equal(isPosixBracket('[[=b=]'), true);
assert.equal(isPosixBracket('[=b=]]'), true);
});
});