1
1
import { expect } from 'chai' ;
2
2
3
+ import { CARRIAGE_RETURN_PLACEHOLDER } from '../../src/client/constants' ;
3
4
import { formatDOM } from '../../src/client/utilities' ;
4
5
import { revertEscapedCharacters } from '../../src/client/utilities' ;
5
6
import { escapeSpecialCharacters } from '../../src/client/utilities' ;
@@ -15,59 +16,67 @@ describe('client utilities', () => {
15
16
16
17
describe ( 'escapeSpecialCharacters' , ( ) => {
17
18
it ( 'escapes carriage return characters' , ( ) => {
18
- const input = 'Hello\rWorld' ;
19
- const expected = ' Hello\\rWorld' ;
20
- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( expected ) ;
19
+ expect ( escapeSpecialCharacters ( 'Hello\rWorld' ) ) . to . equal (
20
+ ` Hello${ CARRIAGE_RETURN_PLACEHOLDER } World` ,
21
+ ) ;
21
22
} ) ;
22
23
23
24
it ( 'does not modify strings without special characters' , ( ) => {
24
- const input = 'Hello World' ;
25
- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( input ) ;
25
+ const text = 'Hello World' ;
26
+ expect ( escapeSpecialCharacters ( text ) ) . to . equal ( text ) ;
26
27
} ) ;
27
28
28
29
it ( 'handles empty strings' , ( ) => {
29
- expect ( escapeSpecialCharacters ( '' ) ) . to . equal ( '' ) ;
30
+ const text = '' ;
31
+ expect ( escapeSpecialCharacters ( text ) ) . to . equal ( text ) ;
30
32
} ) ;
31
33
32
34
it ( 'handles multiple carriage returns' , ( ) => {
33
- const input = 'Hello\rDear\rWorld' ;
34
- const expected = ' Hello\\rDear\\rWorld' ;
35
- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( expected ) ;
35
+ expect ( escapeSpecialCharacters ( 'Hello\rDear\rWorld' ) ) . to . equal (
36
+ ` Hello${ CARRIAGE_RETURN_PLACEHOLDER } Dear ${ CARRIAGE_RETURN_PLACEHOLDER } World` ,
37
+ ) ;
36
38
} ) ;
37
39
38
40
it ( 'only escapes carriage returns' , ( ) => {
39
- const input = 'Hello\rWorld\n' ; // \n should not be affected
40
- const expected = 'Hello\\rWorld\n' ;
41
- expect ( escapeSpecialCharacters ( input ) ) . to . equal ( expected ) ;
41
+ // `\n` and `\right` should not be affected
42
+ expect ( escapeSpecialCharacters ( 'Hello\rWorld\n\right' ) ) . to . equal (
43
+ `Hello${ CARRIAGE_RETURN_PLACEHOLDER } World\n${ CARRIAGE_RETURN_PLACEHOLDER } ight` ,
44
+ ) ;
42
45
} ) ;
43
46
} ) ;
44
47
45
48
describe ( 'revertEscapedCharacters' , ( ) => {
46
49
it ( 'reverts escaped carriage return characters' , ( ) => {
47
- const input = 'Hello\\rWorld' ;
48
- const expected = ' Hello\rWorld' ;
49
- expect ( revertEscapedCharacters ( input ) ) . to . equal ( expected ) ;
50
+ expect (
51
+ revertEscapedCharacters ( ` Hello${ CARRIAGE_RETURN_PLACEHOLDER } World` ) ,
52
+ ) . to . equal ( 'Hello\rWorld' ) ;
50
53
} ) ;
51
54
52
55
it ( 'does not modify strings without escaped characters' , ( ) => {
53
- const input = 'Hello World' ;
54
- expect ( revertEscapedCharacters ( input ) ) . to . equal ( input ) ;
56
+ const text = 'Hello World' ;
57
+ expect ( revertEscapedCharacters ( text ) ) . to . equal ( text ) ;
55
58
} ) ;
56
59
57
60
it ( 'handles empty strings' , ( ) => {
58
- expect ( revertEscapedCharacters ( '' ) ) . to . equal ( '' ) ;
61
+ const text = '' ;
62
+ expect ( revertEscapedCharacters ( text ) ) . to . equal ( text ) ;
59
63
} ) ;
60
64
61
65
it ( 'handles multiple escaped carriage returns' , ( ) => {
62
- const input = 'Hello\\rDear\\rWorld' ;
63
- const expected = 'Hello\rDear\rWorld' ;
64
- expect ( revertEscapedCharacters ( input ) ) . to . equal ( expected ) ;
66
+ expect (
67
+ revertEscapedCharacters (
68
+ `Hello${ CARRIAGE_RETURN_PLACEHOLDER } Dear${ CARRIAGE_RETURN_PLACEHOLDER } World` ,
69
+ ) ,
70
+ ) . to . equal ( 'Hello\rDear\rWorld' ) ;
65
71
} ) ;
66
72
67
73
it ( 'only reverts escaped carriage returns' , ( ) => {
68
- const input = 'Hello\\rWorld\\n' ; // \n should not be affected
69
- const expected = 'Hello\rWorld\\n' ;
70
- expect ( revertEscapedCharacters ( input ) ) . to . equal ( expected ) ;
74
+ // `\n` and `\right` should not be affected
75
+ expect (
76
+ revertEscapedCharacters (
77
+ `Hello${ CARRIAGE_RETURN_PLACEHOLDER } World\\n\\right` ,
78
+ ) ,
79
+ ) . to . equal ( 'Hello\rWorld\\n\\right' ) ;
71
80
} ) ;
72
81
} ) ;
73
82
} ) ;
0 commit comments