Skip to content

Commit 3f8e7ff

Browse files
kooperojonschlinkert
authored andcommitted
Failing test cases for issue \#29 (#30)
1 parent 0c04d6f commit 3f8e7ff

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

test/braces.compile.js

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ describe('braces.compile()', () => {
4343
assert.equal(compile(parse('{a..e..x..z}')), '{a..e..x..z}');
4444
assert.equal(compile(parse('{a..e..x..z}'), { escapeInvalid: true }), '\\{a..e..x..z\\}');
4545
});
46+
47+
it('should compile very simple numeric ranges', () => {
48+
assert.equal(compile(parse('{1..5}')), '([1-5])');
49+
});
50+
51+
it('should compile numeric ranges with increments', () => {
52+
assert.equal(compile(parse('{1..5..2}')), '(1|3|5)');
53+
});
54+
55+
it('should compile zero-padded numeric ranges', () => {
56+
assert.equal(compile(parse('{01..05}')), '(0[1-5])');
57+
});
58+
59+
it('should compile zero-padded numeric ranges with increments', () => {
60+
assert.equal(compile(parse('{01..05..2}')), '(01|03|05)');
61+
});
4662
});
4763

4864
describe('invalid', () => {

test/braces.expand.js

+12
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,17 @@ describe('unit tests from brace-expand', () => {
164164
});
165165
});
166166
});
167+
168+
describe('additional brace expansion test', () => {
169+
describe('sequences', () => {
170+
it('zero-padded numeric sequences', () => {
171+
equal('{008..012}', ['008', '009', '010', '011', '012']);
172+
});
173+
174+
it('zero-padded numeric sequences with increments', () => {
175+
equal('{008..012..2}', ['008', '010', '012']);
176+
});
177+
});
178+
});
167179
});
168180

test/readme.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
require('mocha');
4+
const assert = require('assert').strict;
5+
const braces = require('..');
6+
7+
describe('Examples from README.md', () => {
8+
describe('Brace Expansion vs. Compilation', () => {
9+
it('Compiled', () => {
10+
assert.deepEqual( braces('a/{x,y,z}/b'), ['a/(x|y|z)/b'] );
11+
assert.deepEqual( braces(['a/{01..20}/b', 'a/{1..5}/b']), [ 'a/(0[1-9]|1[0-9]|20)/b', 'a/([1-5])/b' ] );
12+
});
13+
14+
it('Expanded', () => {
15+
assert.deepEqual(braces('a/{x,y,z}/b', { expand: true }), ['a/x/b', 'a/y/b', 'a/z/b'] );
16+
assert.deepEqual(braces.expand('{01..10}'), ['01','02','03','04','05','06','07','08','09','10'] );
17+
});
18+
});
19+
20+
describe('Sequences', () => {
21+
it('first set of examples', () => {
22+
assert.deepEqual( braces.expand('{1..3}'), ['1', '2', '3']);
23+
assert.deepEqual( braces.expand('a/{1..3}/b'), ['a/1/b', 'a/2/b', 'a/3/b']);
24+
assert.deepEqual( braces('{a..c}', { expand: true }), ['a', 'b', 'c']);
25+
assert.deepEqual( braces('foo/{a..c}', { expand: true }), ['foo/a', 'foo/b', 'foo/c']);
26+
})
27+
28+
it('zero-padding examples', () => {
29+
// supports zero-padded ranges
30+
assert.deepEqual( braces('a/{01..03}/b'), ['a/(0[1-3])/b']);
31+
assert.deepEqual( braces('a/{001..300}/b'), ['a/(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)/b']);
32+
})
33+
});
34+
});

0 commit comments

Comments
 (0)