-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.test.ts
141 lines (113 loc) · 3.55 KB
/
app.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
const assert = require('assert');
import { search } from './app';
import { times } from './app';
import { match } from './app';
import { TextContent } from './app';
import { Lines } from './app';
describe('Text Content Search', () => {
it('should search for a term', () => {
assert.ok(search('foo', 'foobar'));
});
it('should throws arguments exception for search', () => {
assert.throws(() => {
search(1, 10);
}, {
name: 'Error',
message: 'Each argument, must be a string'
});
});
});
describe('Text Content Times', () => {
it('should have times of a term', () => {
assert.equal(times('baz', 'bazfoobarbaz'), 2);
});
it('should throws arguments exception for times', () => {
assert.throws(() => {
times(1, 10);
}, {
name: 'Error',
message: 'Each argument, must be a string'
});
});
});
describe('Text Content Match', () => {
it('should have match of term', () => {
assert.equal(match('baz', 'foobarbaz'), 'foobarbaz');
});
it('should throws arguments exception for match', () => {
assert.throws(() => {
match(1, 10);
}, {
name: 'Error',
message: 'Each argument, must be a string'
});
});
});
describe('Text Content', () => {
let txt = null;
before(() => {
txt = new TextContent('foobarbaz');
});
it('should be an instance of', () => {
assert.ok(txt instanceof TextContent);
});
it('should be an content', () => {
assert.ok(txt.content, 'foobarbaz', 'TextContent content not settled');
});
it('should be set a content', () => {
assert.ok(txt.setContent('foobarbazbuzz') instanceof TextContent);
});
it('should be get a content', () => {
assert.equal(txt.getContent(), 'foobarbazbuzz');
});
it('should be search by a term in content', () => {
assert.ok(txt.search('buzz'));
});
it('should be have times of term occured on the content', () => {
txt.setContent('fuzzbarfuzzbuzzfuzz');
assert.equal(txt.times('fuzz'), 3);
});
it('should be match by term on the content', () => {
assert.equal(txt.match('buzz'), 'fuzzbarfuzzbuzzfuzz');
});
});
describe('Text Content processing buffer', () => {
let txtBuff = null;
before(() => {
txtBuff = new TextContent(Buffer.from('foobarbaz'));
});
it('should be an instance of', () => {
assert.ok(txtBuff instanceof TextContent);
});
it('should be an content', () => {
assert.ok(txtBuff.content, Buffer.from('foobarbaz'), 'TextContent content not settled');
});
it('should be a buffer', () => {
assert.ok(txtBuff.isBuffer(Buffer.from('bar')));
});
it('should be search by a term in content as buffer', () => {
assert.ok(txtBuff.search(Buffer.from('bar')));
});
it('should be have times of term occured on the content as buffer', () => {
txtBuff.setContent(Buffer.from('fuzzbarfuzzbuzzfuzz'));
assert.equal(txtBuff.times(Buffer.from('fuzz')), 3);
});
it('should be match by term on the content as buffer', () => {
assert.deepEqual(txtBuff.match(Buffer.from('buzz')), {1: Buffer.from('fuzzbarfuzzbuzzfuzz')});
});
it('should be match by line on the content as buffer', () => {
txtBuff.setContent(Buffer.from('fizzbuzz\nfizzbar\nfoobar'));
assert.deepEqual(txtBuff.match(Buffer.from('fizz')),
{1: Buffer.from('fizzbuzz'), 2: Buffer.from('fizzbar')});
});
});
describe('Text Content processing lines', () => {
let lines = null;
before(() => {
lines = new Lines();
});
it('should be an instance of', () => {
assert.ok(lines instanceof Lines);
});
});