-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
42 lines (30 loc) · 1.16 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
const Cstring = require('./index');
describe('Constant String Base Operations', () => {
it('eval should return initialized value', () => {
expect(new Cstring('foo').eval()).toBe('foo');
});
it('should be able to concatinate two strings', () => {
const result = new Cstring('foo').concat('bar');
expect(result.eval()).toBe('foobar');
});
it('should support inserting', () => {
const atStart = new Cstring('bar').insert('foo', 0);
expect(atStart.eval()).toBe('foobar');
const inMiddle = new Cstring('bar').insert('foo', 1);
expect(inMiddle.eval()).toBe('bfooar');
const atEnd = new Cstring('bar').insert('foo', 4);
expect(atEnd.eval()).toBe('barfoo');
const afterEnd = new Cstring('bar').insert('foo', 10);
expect(afterEnd.eval()).toBe('barfoo');
});
it('should support substring', () => {
const result = new Cstring('foo').concat('bar').substring(0, 3);
expect(result.eval()).toBe('foo');
});
});
describe('Constant string immutability tests', () => {
const start = new Cstring('bar');
const other = start.concat('foo');
expect(start.eval()).toBe('bar');
expect(other.eval()).toBe('barfoo');
});