Skip to content

Commit

Permalink
Fix regexps in executables
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Dec 14, 2019
1 parent 48f1415 commit 0af2583
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/alphabet
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ spawnSync('npx', ['webpack', '--mode', 'production', '--output', output, input])
let js = fs.readFileSync(output).toString()
fs.unlinkSync(output)

let match = js.match(/[A-Za-z0-9-_]{30,}/)
let match = js.match(/[\w-]{30,}/)
if (!match) {
process.stderr.write(chalk.red('Alphabet was not found\n'))
process.exit(1)
Expand Down
8 changes: 4 additions & 4 deletions test/alphabet-genetic
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spawnSync('npx', ['webpack', '--mode', 'production', '--output', output, input])
let js = fs.readFileSync(output).toString()
fs.unlinkSync(output)

let match = js.match(/[A-Za-z0-9-_]{30,}/)
let match = js.match(/[\w-]{30,}/)
if (!match) {
process.stderr.write(chalk.red('Alphabet was not found\n'))
process.exit(1)
Expand Down Expand Up @@ -66,7 +66,7 @@ function addMissingCharacter (str, proto) {
}

function fitnessFunction (phenotype) {
let file = js.replace(/[A-Za-z0-9-_]{30,}/, phenotype.alphabet)
let file = js.replace(/[\w-]{30,}/, phenotype.alphabet)
let size = gzipSize.sync(file)
console.log(size, phenotype.alphabet)
return -1 * size
Expand Down Expand Up @@ -106,9 +106,9 @@ console.log(
)
console.log(chalk.green(
'Size new string:',
gzipSize.sync(js.replace(/[A-Za-z0-9-_]{30,}/, best.alphabet))
gzipSize.sync(js.replace(/[\w-]{30,}/, best.alphabet))
))
console.log(chalk.yellow(
'Size old string:',
gzipSize.sync(js.replace(/[A-Za-z0-9-_]{30,}/, firstPhenotype.alphabet)))
gzipSize.sync(js.replace(/[\w-]{30,}/, firstPhenotype.alphabet)))
)
4 changes: 2 additions & 2 deletions test/benchmark
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ let suite = new benchmark.Suite()

function formatNumber (number) {
return String(number)
.replace(/\d\d\d$/, ',$&')
.replace(/^(\d)(\d\d\d)/, '$1,$2')
.replace(/\d{3}$/, ',$&')
.replace(/^(\d)(\d{3})/, '$1,$2')
}

suite
Expand Down

0 comments on commit 0af2583

Please sign in to comment.