From 3f8e7ff621872888d46f2bfc944764dda0a4ab84 Mon Sep 17 00:00:00 2001 From: Samm Cooper Date: Sat, 15 Jun 2019 19:54:08 -0700 Subject: [PATCH] Failing test cases for issue \#29 (#30) --- test/braces.compile.js | 16 ++++++++++++++++ test/braces.expand.js | 12 ++++++++++++ test/readme.js | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 test/readme.js diff --git a/test/braces.compile.js b/test/braces.compile.js index f1b8395..41d4b25 100644 --- a/test/braces.compile.js +++ b/test/braces.compile.js @@ -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', () => { diff --git a/test/braces.expand.js b/test/braces.expand.js index 23cd4df..98012ef 100644 --- a/test/braces.expand.js +++ b/test/braces.expand.js @@ -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']); + }); + }); + }); }); diff --git a/test/readme.js b/test/readme.js new file mode 100644 index 0000000..1c1731c --- /dev/null +++ b/test/readme.js @@ -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']); + }) + }); +}); \ No newline at end of file