Skip to content

Commit

Permalink
Failing test cases for issue \#29 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
koopero authored and jonschlinkert committed Jun 16, 2019
1 parent 0c04d6f commit 3f8e7ff
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/braces.compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ describe('braces.compile()', () => {
assert.equal(compile(parse('{a..e..x..z}')), '{a..e..x..z}');
assert.equal(compile(parse('{a..e..x..z}'), { escapeInvalid: true }), '\\{a..e..x..z\\}');
});

it('should compile very simple numeric ranges', () => {
assert.equal(compile(parse('{1..5}')), '([1-5])');
});

it('should compile numeric ranges with increments', () => {
assert.equal(compile(parse('{1..5..2}')), '(1|3|5)');
});

it('should compile zero-padded numeric ranges', () => {
assert.equal(compile(parse('{01..05}')), '(0[1-5])');
});

it('should compile zero-padded numeric ranges with increments', () => {
assert.equal(compile(parse('{01..05..2}')), '(01|03|05)');
});
});

describe('invalid', () => {
Expand Down
12 changes: 12 additions & 0 deletions test/braces.expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,17 @@ describe('unit tests from brace-expand', () => {
});
});
});

describe('additional brace expansion test', () => {
describe('sequences', () => {
it('zero-padded numeric sequences', () => {
equal('{008..012}', ['008', '009', '010', '011', '012']);
});

it('zero-padded numeric sequences with increments', () => {
equal('{008..012..2}', ['008', '010', '012']);
});
});
});
});

34 changes: 34 additions & 0 deletions test/readme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

require('mocha');
const assert = require('assert').strict;
const braces = require('..');

describe('Examples from README.md', () => {
describe('Brace Expansion vs. Compilation', () => {
it('Compiled', () => {
assert.deepEqual( braces('a/{x,y,z}/b'), ['a/(x|y|z)/b'] );
assert.deepEqual( braces(['a/{01..20}/b', 'a/{1..5}/b']), [ 'a/(0[1-9]|1[0-9]|20)/b', 'a/([1-5])/b' ] );
});

it('Expanded', () => {
assert.deepEqual(braces('a/{x,y,z}/b', { expand: true }), ['a/x/b', 'a/y/b', 'a/z/b'] );
assert.deepEqual(braces.expand('{01..10}'), ['01','02','03','04','05','06','07','08','09','10'] );
});
});

describe('Sequences', () => {
it('first set of examples', () => {
assert.deepEqual( braces.expand('{1..3}'), ['1', '2', '3']);
assert.deepEqual( braces.expand('a/{1..3}/b'), ['a/1/b', 'a/2/b', 'a/3/b']);
assert.deepEqual( braces('{a..c}', { expand: true }), ['a', 'b', 'c']);
assert.deepEqual( braces('foo/{a..c}', { expand: true }), ['foo/a', 'foo/b', 'foo/c']);
})

it('zero-padding examples', () => {
// supports zero-padded ranges
assert.deepEqual( braces('a/{01..03}/b'), ['a/(0[1-3])/b']);
assert.deepEqual( braces('a/{001..300}/b'), ['a/(0{2}[1-9]|0[1-9][0-9]|[12][0-9]{2}|300)/b']);
})
});
});

0 comments on commit 3f8e7ff

Please sign in to comment.