forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.test.ts
More file actions
76 lines (63 loc) · 3.13 KB
/
Text.test.ts
File metadata and controls
76 lines (63 loc) · 3.13 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
// 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...');
});
});
});