: regex: /[///[]}/ [p1, '{/\\/[}\\]]/}', p2], //
: regex: /\/[}\]]/ [p1, '{x/y}', '', '{x/g}', p2], //
: NOT regex: /y}{x/g [p1, '{a++/b}', '', '{/i}', p2], //
: NOT regex: /b}{/i [p1, "{''+/b}{/i}", p2], //
: regex: /b}{/i [p1, '{a==/b}{/i}', p2], //
: regex: /b}{/i [p1, '{a=/{}}}}/}', p2] //
: regex: /{}}}}/ ] var qblocks = [ '/}/', '/[///[]}/', '/\\/[}\\]]/', undefined, undefined, '/b}{/i', '/b}{/i', '/{}}}}/', ] resetBrackets() for (n = 0; n < atest.length; ++n) { var a, t = atest[n] a = brackets.split(t.join(''), 1) expect(a).to.have.length(t.length) expect(a[0]).to.be(unq(t[0])) expect(a.qblocks[0]).to.be(qblocks[n]) expect(a[2]).to.be(unq(t[2])) } function unq (s) { return /^{.*}$/.test(s) ? s.slice(1, -1) : s } }) }) // end of brackets.split }) // end of brackets 2.4 suite }) describe('regexes', function () { it('literal strings with escaped quotes inside (double quotes)', function () { var match = ' """\\"" "x" "a\\" "'.match(brackets.R_STRINGS) // R_STRINGS has global flag expect(match).to.have.length(4) expect(match[0]).to.be('""') expect(match[1]).to.be('"\\""') expect(match[2]).to.be('"x"') expect(match[3]).to.be('"a\\" "') }) it('literal strings with escaped quotes inside (single quotes)', function () { var match = " '''\\'' 'x' 'a\\' '".match(brackets.R_STRINGS) // R_STRINGS has global flag expect(match).to.have.length(4) expect(match[0]).to.be("''") expect(match[1]).to.be("'\\''") expect(match[2]).to.be("'x'") expect(match[3]).to.be("'a\\' '") }) it('multiline javascript comments in almost all forms', function () { var match = ' /* a *//**/ /*/**/ /*//\n*/ /\\*/**/'.match(brackets.R_MLCOMMS) expect(match).to.have.length(5) expect(match[0]).to.be('/* a */') expect(match[1]).to.be('/**/') expect(match[2]).to.be('/*/**/') expect(match[3]).to.be('/*//\n*/') expect(match[4]).to.be('/**/') }) it('no problema with mixed quoted strings and comments', function () { var re = new RegExp(brackets.S_QBLOCKS + '|' + brackets.R_MLCOMMS.source, 'g'), match = ' /* a */"" /*""*/ "/*\\"*/" \\\'/*2*/\\\'\'\''.match(re) expect(match).to.have.length(5) expect(match[0]).to.be('/* a */') expect(match[1]).to.be('""') expect(match[2]).to.be('/*""*/') expect(match[3]).to.be('"/*\\"*/"') expect(match[4]).to.be("'/*2*/\\\''") // yes, the match is correct :) }) })