@@ -24,9 +24,9 @@ test('main', t => {
24
24
}
25
25
}
26
26
27
- const a = util . inspect ( '\u001B[31mthe \u001B[39m\u001B[32mquick \u001B[39m\u001B[34m\u001B[39m ' ) ;
28
- const b = util . inspect ( '\u001B[32m\u001B[39m\u001B[ 34mbrown \u001B[39m\u001B[36mfox \u001B[39m\u001B[33m \u001B[39m' ) ;
29
- const c = util . inspect ( '\u001B[31m \u001B[39m\u001B[32mquick \u001B[39m\u001B[34mbrown \u001B[39m\u001B[36mfox \u001B[39m\u001B[33m\u001B[39m ' ) ;
27
+ const a = util . inspect ( '\u001B[31mthe \u001B[39m\u001B[32mquick \u001B[39m' ) ;
28
+ const b = util . inspect ( '\u001B[34mbrown \u001B[39m\u001B[36mfox \u001B[39m' ) ;
29
+ const c = util . inspect ( '\u001B[31m \u001B[39m\u001B[32mquick \u001B[39m\u001B[34mbrown \u001B[39m\u001B[36mfox \u001B[39m' ) ;
30
30
31
31
t . is ( util . inspect ( sliceAnsi ( fixture , 0 , 10 ) ) , a ) ;
32
32
t . is ( util . inspect ( sliceAnsi ( fixture , 10 , 20 ) ) , b ) ;
@@ -50,33 +50,45 @@ test('doesn\'t add unnecessary escape codes', t => {
50
50
t . is ( sliceAnsi ( '\u001B[31municorn\u001B[39m' , 0 , 3 ) , '\u001B[31muni\u001B[39m' ) ;
51
51
} ) ;
52
52
53
- test . failing ( 'can slice a normal character before a colored character' , t => {
53
+ test ( 'can slice a normal character before a colored character' , t => {
54
54
t . is ( sliceAnsi ( 'a\u001B[31mb\u001B[39m' , 0 , 1 ) , 'a' ) ;
55
55
} ) ;
56
56
57
- test . failing ( 'can slice a normal character after a colored character' , t => {
57
+ test ( 'can slice a normal character after a colored character' , t => {
58
58
t . is ( sliceAnsi ( '\u001B[31ma\u001B[39mb' , 1 , 2 ) , 'b' ) ;
59
59
} ) ;
60
60
61
61
// See https://github.com/chalk/slice-ansi/issues/22
62
- test . failing ( 'can slice a string styled with both background and foreground' , t => {
62
+ test ( 'can slice a string styled with both background and foreground' , t => {
63
63
// Test string: `chalk.bgGreen.black('test');`
64
64
t . is ( sliceAnsi ( '\u001B[42m\u001B[30mtest\u001B[39m\u001B[49m' , 0 , 1 ) , '\u001B[42m\u001B[30mt\u001B[39m\u001B[49m' ) ;
65
65
} ) ;
66
66
67
+ test ( 'can slice a string styled with modifier' , t => {
68
+ // Test string: `chalk.underline('test');`
69
+ t . is ( sliceAnsi ( '\u001B[4mtest\u001B[24m' , 0 , 1 ) , '\u001B[4mt\u001B[24m' ) ;
70
+ } ) ;
71
+
72
+ test ( 'can slice a string with unknown ANSI color' , t => {
73
+ t . is ( sliceAnsi ( '\u001B[20mTEST\u001B[49m' , 0 , 4 ) , '\u001B[20mTEST\u001B[0m' ) ;
74
+ t . is ( sliceAnsi ( '\u001B[1001mTEST\u001B[49m' , 0 , 3 ) , '\u001B[1001mTES\u001B[0m' ) ;
75
+ t . is ( sliceAnsi ( '\u001B[1001mTEST\u001B[49m' , 0 , 2 ) , '\u001B[1001mTE\u001B[0m' ) ;
76
+ } ) ;
77
+
67
78
test ( 'weird null issue' , t => {
68
79
const s = '\u001B[1mautotune.flipCoin("easy as") ? 🎂 : 🍰 \u001B[33m★\u001B[39m\u001B[22m' ;
69
80
const result = sliceAnsi ( s , 38 ) ;
70
81
t . false ( result . includes ( 'null' ) ) ;
71
82
} ) ;
72
83
73
84
test ( 'support true color escape sequences' , t => {
74
- t . is ( sliceAnsi ( '\u001B[[ 1m\u001B[[ 48;2;255;255;255m\u001B[[ 38;2;255;0;0municorn\u001B[[ 39m\u001B[[ 49m\u001B[[ 22m' , 0 , 3 ) , '\u001B[1m\u001B[48;2;255;255;25m \u001B[38;2;255;0;0muni\u001B[39m' ) ;
85
+ t . is ( sliceAnsi ( '\u001B[1m\u001B[48;2;255;255;255m\u001B[38;2;255;0;0municorn\u001B[39m\u001B[49m\u001B[22m' , 0 , 3 ) , '\u001B[1m\u001B[48;2;255;255;255m \u001B[38;2;255;0;0muni\u001B[22m\u001B[49m \u001B[39m' ) ;
75
86
} ) ;
76
87
77
88
// See https://github.com/chalk/slice-ansi/issues/24
78
- test . failing ( 'doesn\'t add extra escapes' , t => {
89
+ test ( 'doesn\'t add extra escapes' , t => {
79
90
const output = `${ chalk . black . bgYellow ( ' RUNS ' ) } ${ chalk . green ( 'test' ) } ` ;
80
91
t . is ( sliceAnsi ( output , 0 , 7 ) , `${ chalk . black . bgYellow ( ' RUNS ' ) } ` ) ;
81
92
t . is ( sliceAnsi ( output , 0 , 8 ) , `${ chalk . black . bgYellow ( ' RUNS ' ) } ` ) ;
93
+ t . is ( sliceAnsi ( '\u001B[31m' + output , 0 , 4 ) , `\u001B[31m${ chalk . black . bgYellow ( ' RUN' ) } ` ) ;
82
94
} ) ;
0 commit comments