-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
104 lines (85 loc) · 2.44 KB
/
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
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
102
103
104
'use strict';
const assert = require('assert');
const Vinyl = require('vinyl');
const typograf = require('./');
it('should prepare text', function (cb) {
const input = ' Hello world!! ';
const output = 'Hello world!';
const stream = typograf({locale: ['ru', 'en-US']});
stream.on('data', function(data) {
assert.equal(data.contents.toString(), output);
cb();
});
stream.write(new Vinyl({
contents: Buffer.from(input)
}));
});
it('should prepare text with disabled rule "ru/punctuation/exclamation"', function (cb) {
const input = ' Hello world!! ';
const output = 'Hello world!!';
const stream = typograf({
locale: ['ru', 'en-US'],
disableRule: ['ru/punctuation/exclamation']
});
stream.on('data', function(data) {
assert.equal(data.contents.toString(), output);
cb();
});
stream.write(new Vinyl({
contents: Buffer.from(input)
}));
});
it('should prepare text with enabled rule "ru/money/ruble"', function (cb) {
const input = ' 1 руб. ';
const output = '1\u00A0₽';
const stream = typograf({
locale: 'ru',
enableRule: ['ru/money/ruble']
});
stream.on('data', function(data) {
assert.equal(data.contents.toString(), output);
cb();
});
stream.write(new Vinyl({
contents: Buffer.from(input)
}));
});
it('should execute own rules', function (cb) {
const input = ' :-) ';
const output = ':—)';
const stream = typograf({
locale: 'ru',
rules: [
{
name: 'common/other/typographicalEmoticon',
handler: function(text, settings) {
return text.replace(/:-\)/, ':—)');
}
}
]
});
stream.on('data', function(data) {
assert.equal(data.contents.toString(), output);
cb();
});
stream.write(new Vinyl({
contents: Buffer.from(input)
}));
});
it('should add safe tags', function (cb) {
const input = '<notypography> "Hello" </notypography>';
const output = input;
const stream = typograf({
locale: 'ru',
safeTags: [
['<notypography>', '</notypography>']
]
});
stream.on('data', function(data) {
assert.equal(data.contents.toString(), output);
cb();
});
stream.write(new Vinyl({
contents: Buffer.from(input)
}));
});