forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathescape.test.ts
More file actions
35 lines (30 loc) · 850 Bytes
/
escape.test.ts
File metadata and controls
35 lines (30 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { escapeString } from './escape';
describe('Escape methods', () => {
describe('escapeString', () => {
it('does nothing to a safe string', () => {
expect(
escapeString("hello world")
).toBe("hello world");
});
it('escapes double quotes by default', () => {
expect(
escapeString('"hello world"')
).toBe('\\"hello world\\"');
});
it('escapes newlines by default', () => {
expect(
escapeString('hello\r\nworld')
).toBe('hello\\r\\nworld');
});
it('escapes backslashes', () => {
expect(
escapeString('hello\\world')
).toBe('hello\\\\world');
});
it('escapes unrepresentable characters', () => {
expect(
escapeString('hello \u0000') // 0 = ASCII 'null' character
).toBe('hello \\u0000');
});
});
});