Repository navigation
Expand file tree
/
Copy pathText.test.ts
More file actions
101 lines (87 loc) · 4.22 KB
/
Copy pathText.test.ts
File metadata and controls
101 lines (87 loc) · 4.22 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import { Text } from '../Text';
describe('Text', () => {
describe('padEnd', () => {
test("Throws an exception if the padding character isn't a single character", () => {
expect(() => Text.padEnd('123', 1, '')).toThrow();
expect(() => Text.padEnd('123', 1, ' ')).toThrow();
});
test("Doesn't change the string if it's already at or greater than the minimum length", () => {
expect(Text.padEnd('12345', 5)).toEqual('12345');
expect(Text.padEnd('123456', 5)).toEqual('123456');
expect(Text.padEnd('12345', 5, '0')).toEqual('12345');
expect(Text.padEnd('123456', 5, '0')).toEqual('123456');
});
test('Appends the default character (spaces) to the end of a string', () => {
expect(Text.padEnd('', 5)).toEqual(' ');
expect(Text.padEnd('123', 5)).toEqual('123 ');
});
test('Appends the characters to the end of a string', () => {
expect(Text.padEnd('', 5, '0')).toEqual('00000');
expect(Text.padEnd('123', 5, '0')).toEqual('12300');
});
});
describe('padStart', () => {
test("Throws an exception if the padding character isn't a single character", () => {
expect(() => Text.padStart('123', 1, '')).toThrow();
expect(() => Text.padStart('123', 1, ' ')).toThrow();
});
test("Doesn't change the string if it's already at or greater than the minimum length", () => {
expect(Text.padStart('12345', 5)).toEqual('12345');
expect(Text.padStart('123456', 5)).toEqual('123456');
expect(Text.padStart('12345', 5, '0')).toEqual('12345');
expect(Text.padStart('123456', 5, '0')).toEqual('123456');
});
test('Appends the default character (spaces) to the end of a string', () => {
expect(Text.padStart('', 5)).toEqual(' ');
expect(Text.padStart('123', 5)).toEqual(' 123');
});
test('Appends the characters to the end of a string', () => {
expect(Text.padStart('', 5, '0')).toEqual('00000');
expect(Text.padStart('123', 5, '0')).toEqual('00123');
});
});
describe('truncateWithEllipsis', () => {
test('Throws an exception if the maximum length is less than zero', () => {
expect(() => Text.truncateWithEllipsis('123', -1)).toThrow();
});
test("Doesn't change the string if it's already shorter than the maximum length", () => {
expect(Text.truncateWithEllipsis('', 2)).toEqual('');
expect(Text.truncateWithEllipsis('1', 2)).toEqual('1');
expect(Text.truncateWithEllipsis('12', 2)).toEqual('12');
expect(Text.truncateWithEllipsis('123', 5)).toEqual('123');
expect(Text.truncateWithEllipsis('1234', 5)).toEqual('1234');
});
test('Truncates strings', () => {
expect(Text.truncateWithEllipsis('123', 0)).toEqual('');
expect(Text.truncateWithEllipsis('123', 2)).toEqual('12');
expect(Text.truncateWithEllipsis('12345', 5)).toEqual('12345');
expect(Text.truncateWithEllipsis('123456', 5)).toEqual('12...');
});
});
describe('convertToLf', () => {
test('degenerate adjacent newlines', () => {
expect(Text.convertToLf('')).toEqual('');
expect(Text.convertToLf('\n')).toEqual('\n');
expect(Text.convertToLf('\r')).toEqual('\n');
expect(Text.convertToLf('\n\n')).toEqual('\n\n');
expect(Text.convertToLf('\r\n')).toEqual('\n');
expect(Text.convertToLf('\n\r')).toEqual('\n');
expect(Text.convertToLf('\r\r')).toEqual('\n\n');
expect(Text.convertToLf('\n\n\n')).toEqual('\n\n\n');
expect(Text.convertToLf('\r\n\n')).toEqual('\n\n');
expect(Text.convertToLf('\n\r\n')).toEqual('\n\n');
expect(Text.convertToLf('\r\r\n')).toEqual('\n\n');
expect(Text.convertToLf('\n\n\r')).toEqual('\n\n');
expect(Text.convertToLf('\r\n\r')).toEqual('\n\n');
expect(Text.convertToLf('\n\r\r')).toEqual('\n\n');
expect(Text.convertToLf('\r\r\r')).toEqual('\n\n\n');
});
test('degenerate mixed newlines', () => {
expect(Text.convertToLf('\nX\n\r')).toEqual('\nX\n');
expect(Text.convertToLf('\rX\r')).toEqual('\nX\n');
expect(Text.convertToLf('\r \n')).toEqual('\n \n');
});
});
});