X Tutup
Skip to content

Commit d85335d

Browse files
committed
Add unit test for backslash escapes
1 parent e825500 commit d85335d

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

libraries/rushell/src/test/Tokenizer.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { Tokenizer, TokenKind } from '../Tokenizer';
66
function escape(s: string): string {
77
return s.replace(/\n/g, '[n]')
88
.replace(/\r/g, '[r]')
9-
.replace(/\t/g, '[t]');
9+
.replace(/\t/g, '[t]')
10+
.replace(/\\/g, '[b]');
1011
}
1112

1213
function matchSnapshot(input: string): void {
@@ -17,11 +18,15 @@ function matchSnapshot(input: string): void {
1718
}).toMatchSnapshot();
1819
}
1920

20-
test('empty inputs', () => {
21+
test('00: empty inputs', () => {
2122
matchSnapshot('');
2223
matchSnapshot('\r\n');
2324
});
2425

25-
test('white space tokens', () => {
26-
matchSnapshot(' abc \r\ndef \n ghi\n\r ');
26+
test('01: white space tokens', () => {
27+
matchSnapshot(' \t abc \r\ndef \n ghi\n\r ');
28+
});
29+
30+
test('02: text with escapes', () => {
31+
matchSnapshot(' ab+56\\>qrst$(abc\\))');
2732
});

libraries/rushell/src/test/__snapshots__/Tokenizer.test.ts.snap

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`empty inputs 1`] = `
3+
exports[`00: empty inputs 1`] = `
44
Object {
55
"input": "",
66
"tokens": Array [],
77
}
88
`;
99

10-
exports[`empty inputs 2`] = `
10+
exports[`00: empty inputs 2`] = `
1111
Object {
1212
"input": "[r][n]",
1313
"tokens": Array [
@@ -19,7 +19,7 @@ Object {
1919
}
2020
`;
2121

22-
exports[`white space tokens 1`] = `
22+
exports[`01: white space tokens 1`] = `
2323
Object {
2424
"input": " [t] abc [r][n]def [n] ghi[n][r] ",
2525
"tokens": Array [
@@ -74,3 +74,43 @@ Object {
7474
],
7575
}
7676
`;
77+
78+
exports[`02: text with escapes 1`] = `
79+
Object {
80+
"input": " ab+56[b]>qrst$(abc[b]))",
81+
"tokens": Array [
82+
Array [
83+
"Spaces",
84+
" ",
85+
],
86+
Array [
87+
"Text",
88+
"ab",
89+
],
90+
Array [
91+
"Other",
92+
"+",
93+
],
94+
Array [
95+
"Text",
96+
"56>qrst",
97+
],
98+
Array [
99+
"Other",
100+
"$",
101+
],
102+
Array [
103+
"Other",
104+
"(",
105+
],
106+
Array [
107+
"Text",
108+
"abc)",
109+
],
110+
Array [
111+
"Other",
112+
")",
113+
],
114+
],
115+
}
116+
`;

0 commit comments

Comments
 (0)
X Tutup