MIRROR: javascript for 🐜's, a tiny runtime with big ambitions
1import { test, summary } from './helpers.js';
2
3console.log('Escape Sequence Tests\n');
4
5test('null char (\\0) charCodeAt', '\0'.charCodeAt(0), 0);
6test('backspace (\\b) charCodeAt', '\b'.charCodeAt(0), 8);
7test('tab (\\t) charCodeAt', '\t'.charCodeAt(0), 9);
8test('newline (\\n) charCodeAt', '\n'.charCodeAt(0), 10);
9test('vertical tab (\\v) charCodeAt', '\v'.charCodeAt(0), 11);
10test('form feed (\\f) charCodeAt', '\f'.charCodeAt(0), 12);
11test('carriage return (\\r) charCodeAt', '\r'.charCodeAt(0), 13);
12
13test('escaped quote single', "'".length, 1);
14test('escaped quote double', '"'.length, 1);
15test('escaped backslash', '\\'.charCodeAt(0), 92);
16
17test('hex escape \\x41', '\x41', 'A');
18test('hex escape \\x00', '\x00'.charCodeAt(0), 0);
19test('hex escape \\x7f', '\x7f'.charCodeAt(0), 127);
20
21test('unicode \\u0041 (A)', '\u0041', 'A');
22test('unicode \\u0000 (null)', '\u0000'.charCodeAt(0), 0);
23test('unicode \\u00e9 (é)', '\u00e9', 'é');
24test('unicode \\u263A (smiley)', '\u263A', '☺');
25test('unicode \\u4e2d (中)', '\u4e2d', '中');
26
27test('unicode code point escape keeps following chars', '\u{1F499} streams', '💙 streams');
28test('unicode code point escape in string body keeps spaces', 'I \u{1F499} streams', 'I 💙 streams');
29
30test('string with null char length', 'a\0b'.length, 3);
31test('string with null indexOf', 'a\0b'.indexOf('\0'), 1);
32
33test('mixed escapes', 'a\tb\nc', 'a\tb\nc');
34test('multiple escapes', '\n\r\t\0'.length, 4);
35
36summary();