-
Notifications
You must be signed in to change notification settings - Fork 1
/
strLimit.test.ts
35 lines (26 loc) · 1.53 KB
/
strLimit.test.ts
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 { describe, it, expect } from 'vitest';
import strLimit from '../../src/strLimit.js';
describe('str/strLimit', () => {
it('works with non ascii strings', () => {
expect(strLimit('Laravel is a free, open source PHP web application framework.', 10)).toEqual('Laravel is...');
const string = 'The PHP framework for web artisans.';
expect(strLimit(string, 7)).toEqual('The PHP...');
expect(strLimit(string, 7, '')).toEqual('The PHP');
expect(strLimit(string, string.length - 1, '')).toEqual('The PHP framework for web artisans');
expect(strLimit(string, string.length)).toEqual('The PHP framework for web artisans.');
expect(strLimit(string, string.length + 1)).toEqual('The PHP framework for web artisans.');
expect(strLimit(string, string.length + 100)).toEqual('The PHP framework for web artisans.');
});
it('does NOT work with ascii strings', () => {
expect(strLimit('这是一段中文', 6)).toEqual('这是一段中文');
const nonAsciiString = '这是一段中文';
expect(strLimit(nonAsciiString, 6)).toEqual(nonAsciiString);
expect(strLimit(nonAsciiString, 6, '')).toEqual(nonAsciiString);
});
// it('works with ascii strings', () => {
// expect(strLimit('这是一段中文', 6)).toEqual('这是一...');
// const nonAsciiString = '这是一段中文';
// expect(strLimit(nonAsciiString, 6)).toEqual('这是一...');
// expect(strLimit(nonAsciiString, 6, '')).toEqual('这是一');
// });
});