chalk / slice-ansi

Slice a string with ANSI escape codes
MIT License
47 stars 21 forks source link

Add failing tests #16

Closed kjirou closed 6 years ago

kjirou commented 6 years ago

I rewrote to add minimum tests to reproduce the contents of #14 .


Contents of an old description Hello. Fix to work correctly when ordinary string and ANSI string are mixed. In order to fix bugs, I fixed the places that I seemed wrong with internal logic. Although the correction range has become wide, can you confirm it? Especially I did not know the situation that needed `ansi-styles`. Ref) #14 ### Problem summary reproduce.js) ```js const sliceAnsi = require('./index'); const chalk = require('chalk'); const str = 'a' + chalk.red('bc') + 'd'; console.log('a:', sliceAnsi(str, 0, 1) === 'a'); console.log('b:', sliceAnsi(str, 1, 2) === chalk.red('b')); console.log('c:', sliceAnsi(str, 2, 3) === chalk.red('c')); console.log('d:', sliceAnsi(str, 3, 4) === 'd'); ``` before) ```bash node reproduce.js a: false b: true c: false d: false ``` after) ```bash node reproduce.js a: true b: true c: true d: true ```
kjirou commented 6 years ago

I understood the meaning of using ansi-styles. It was a bad fix, so I close it.

sindresorhus commented 6 years ago

The failing tests are still useful, even if the fix is not correct. Can you remove the fix and keep the tests only? (Note: No need to open a new PR each time. You can just update this one)

kjirou commented 6 years ago

@sindresorhus I rebased to be test only.