braces
braces copied to clipboard
Braces don't expand if they start with the range operator
Example:
braces.expand('{..a,b}/c')
Expected result:
[ '..ac', 'bc' ]
Actual result:
[ '{..a,b}c' ]
Note that the current behaviour is differing from the bash implementation:
tim@EK-22-LT-04:~/virtuoso-test-data$ echo {..a,b}c
..ac bc
Note that it does work if the .. comes anywhere except the first parameter to the brace, so
'{b,..a}c'
{b,z,..a}c
do each give
[ 'bc', '..ac' ]
[ 'bc', 'zc', '..ac' ]
@tim-hitchins-ekkosense thanks for reporting this. That's definitely a bug.
@jonschlinkert I'm happy to take a stab at a PR for this if it would be helpful, but I've not looked into it yet, so it may take me a while to find a fix!
Sure, that would be great!
Okay, used
# test.sh
echo {..a,b}
echo {b,..a}
echo {a..,b}
echo {...,b}
echo {a,..,b}
echo ..{a,b}
echo {{..,..},a,b}
echo {{{..,..}a,b}c,d}
echo ..{..,{..,{..,..}a,b}c,d}
echo ..
echo {,..}
echo {..,}
echo {..,..,..}
echo {...,..,..}
echo {..,...,..}
echo {./../.,../../}
echo {../../../,../../}
echo {...,...,...}
echo {.,..,.}
echo ,{..,..,.},
echo {1..2,3..4}
echo {..2,3..4}
echo {1..,2}
echo {1..,..2..,..3}
echo ..{1..3}
echo ..{1..3}{..,..}
echo {..a,b
echo {b,..a
echo {a..,b
echo {...,b
echo {a,..,b
echo ..{a,b
echo {{..,..},a,b
echo {{{..,..}a,b}c,d
echo {{{..,..}a,bc,d}
echo ..{..,{..,{..,..}a,b}c,d
echo ..
echo {,..
echo {..,
echo {..,..,..
echo {...,..,..
echo {..,...,..
echo {./../.,../../
echo {../../../,../../
echo {...,...,...
echo {.,..,.
echo ,{..,..,.},
echo {1..2,3..4
echo {..2,3..4
echo {1..,2
echo {1..,..2..,..3
echo ..{1..3
echo ..{1..3}{..,..
echo ..a,b}
echo b,..a}
echo a..,b}
echo ...,b}
echo a,..,b}
echo ..a,b}
echo {..,..},a,b}
echo {{..,..}a,b}c,d}
echo ....,{..,{..,..}a,b}c,d}
echo ..
echo ,..}
echo ..,}
echo ..,..,..}
echo ...,..,..}
echo ..,...,..}
echo ./../.,../../}
echo ../../../,../../}
echo ...,...,...}
echo .,..,.}
echo ,..,..,.},
echo 1..2,3..4}
echo ..2,3..4}
echo 1..,2}
echo 1..,..2..,..3}
echo ..1..3}
echo ..1..3}{..,..}
and then
./test.sh | sed "s/ /', '/g" | xargs -d$"\n" printf "['%s']\n"
to assess a load of test cases and generate the expected results.
Aside, I don't know if this is something you'd want, but because this library is a) aiming to copy bash (almost - I think you support spaces in braces) and b) it's a constrained character set, it's a good case for some fuzz testing.
import random
alphabet = ['a', 'b', 'c', '1', '2', '3', '{', '}', '.', ',']
for i in range (int(1e2)):
string = ''
for i in range (random.randint(3, 25)):
string += random.choice(alphabet)
print (string)
and then run with the very ugly
python3 test.py | xargs -d$"\n" -I % bash -c "echo -n \"%|\"; echo %" | sed "s/ /', '/g" | sed "s/|/', {}, ['/" | xargs -d$"\n" printf "['%s']]\n"
for some output like
['3b{33abbb,b1ba,c{{,3}', {}, ['3b{33abbb,b1ba,c{', '3b{33abbb,b1ba,c{3']]
['3.c,,c{bc2}cc', {}, ['3.c,,c{bc2}cc']]
['b}c22.b{b,2,{12aaa3cc3c', {}, ['b}c22.b{b,2,{12aaa3cc3c']]
['11}..122', {}, ['11}..122']]
['2c{', {}, ['2c{']]
['}bc22b{3a{3a22a3..', {}, ['}bc22b{3a{3a22a3..']]
['}1,{ca{,{{,}.c1c321,a1}1', {}, ['}1,{ca{,.c1c3211', '}1,{ca{,.c1c3211', '}1,{ca{,a11']]
['c2b3b2b}c,,.}23b12,a,b}11', {}, ['c2b3b2b}c,,.}23b12,a,b}11']]
to give a load of test cases. Add | grep "', '" to get only cases that actually have some expansion.
Let me know if you'd like this sort of thing added (in another task).
Anyway, @jonschlinkert - PR raised.
[ '..ac', 'bc' ]