-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.test.js
46 lines (35 loc) · 1.34 KB
/
utils.test.js
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
const { correctTitle, parsePrefixMapping, extractKnownPrefixes } = require('./utils');
test('simple test', () => {
const simpleTitle = 'hello world';
expect(correctTitle(simpleTitle, 'FOO', ['FOO', 'BAR'])).toBe('FOO hello world');
});
test('test with same existing prefix', () => {
const title = 'FOO hello world';
expect(correctTitle(title, 'FOO', ['FOO', 'BAR'])).toBe('FOO hello world');
});
test('test with different existing prefix', () => {
const title = 'BAR hello world';
expect(correctTitle(title, 'FOO', ['FOO', 'BAR'])).toBe('FOO hello world');
});
test('parse prefix mappings', () => {
const input = `foo=FOO
bar=BAR`;
const mappings = parsePrefixMapping(input);
expect(mappings).toStrictEqual({'foo': 'FOO', 'bar': 'BAR'});
});
test('test extracting known prefixes from mapping' , () => {
const input = `foo=FOO
bar=BAR`;
const mappings = parsePrefixMapping(input);
const title = 'BAR hello world';
const knownPrefixes = extractKnownPrefixes(mappings);
expect(correctTitle(title, 'FOO', knownPrefixes)).toBe('FOO hello world');
});
test('test emojis' , () => {
const input = `foo=🔴
bar=🔹`;
const mappings = parsePrefixMapping(input);
const title = '🔹 hello world';
const knownPrefixes = extractKnownPrefixes(mappings);
expect(correctTitle(title, '🔴', knownPrefixes)).toBe('🔴 hello world');
});