-
-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathlogpoint.ts
More file actions
98 lines (80 loc) Β· 4.93 KB
/
logpoint.ts
File metadata and controls
98 lines (80 loc) Β· 4.93 KB
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
import { LogPointManager } from '../logpoint'
import * as assert from 'assert'
describe('logpoint', () => {
const FILE_URI1 = 'file://my/file1'
const FILE_URI2 = 'file://my/file2'
const FILE_URI3 = 'file://my/file3'
const LOG_MESSAGE_VAR = '{$variable1}'
const LOG_MESSAGE_MULTIPLE = '{$variable1} {$variable3} {$variable2}'
const LOG_MESSAGE_TEXT_AND_VAR = 'This is my {$variable1}'
const LOG_MESSAGE_TEXT_AND_MULTIVAR = 'Those variables: {$variable1} ${$variable2} should be replaced'
const LOG_MESSAGE_REPEATED_VAR = 'This {$variable1} and {$variable1} should be equal'
const LOG_MESSAGE_BADLY_FORMATED_VAR = 'Only {$variable1} should be resolved and not }$variable1 and $variable1{}'
const REPLACE_FUNCTION = (str: string): Promise<string> => {
return Promise.resolve(`${str}_value`)
}
let logPointManager: LogPointManager
beforeEach('create new instance', () => (logPointManager = new LogPointManager()))
describe('basic map management', () => {
it('should contain added logpoints', () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_VAR)
logPointManager.addLogPoint(FILE_URI1, 11, LOG_MESSAGE_VAR)
logPointManager.addLogPoint(FILE_URI2, 12, LOG_MESSAGE_VAR)
logPointManager.addLogPoint(FILE_URI3, 13, LOG_MESSAGE_VAR)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 10), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 11), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI2, 12), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI3, 13), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 12), false)
assert.equal(logPointManager.hasLogPoint(FILE_URI2, 13), false)
assert.equal(logPointManager.hasLogPoint(FILE_URI3, 10), false)
})
it('should add and clear entries', () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_VAR)
logPointManager.addLogPoint(FILE_URI1, 11, LOG_MESSAGE_VAR)
logPointManager.addLogPoint(FILE_URI2, 12, LOG_MESSAGE_VAR)
logPointManager.addLogPoint(FILE_URI3, 13, LOG_MESSAGE_VAR)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 10), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 11), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI2, 12), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI3, 13), true)
logPointManager.clearFromFile(FILE_URI1)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 10), false)
assert.equal(logPointManager.hasLogPoint(FILE_URI1, 11), false)
assert.equal(logPointManager.hasLogPoint(FILE_URI2, 12), true)
assert.equal(logPointManager.hasLogPoint(FILE_URI3, 13), true)
})
})
describe('variable resolution', () => {
it('should resolve variables', async () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_VAR)
const result = await logPointManager.resolveExpressions(FILE_URI1, 10, REPLACE_FUNCTION)
assert.equal(result, '$variable1_value')
})
it('should resolve multiple variables', async () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_MULTIPLE)
const result = await logPointManager.resolveExpressions(FILE_URI1, 10, REPLACE_FUNCTION)
assert.equal(result, '$variable1_value $variable3_value $variable2_value')
})
it('should resolve variables with text', async () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_TEXT_AND_VAR)
const result = await logPointManager.resolveExpressions(FILE_URI1, 10, REPLACE_FUNCTION)
assert.equal(result, 'This is my $variable1_value')
})
it('should resolve multiple variables with text', async () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_TEXT_AND_MULTIVAR)
const result = await logPointManager.resolveExpressions(FILE_URI1, 10, REPLACE_FUNCTION)
assert.equal(result, 'Those variables: $variable1_value $$variable2_value should be replaced')
})
it('should resolve repeated variables', async () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_REPEATED_VAR)
const result = await logPointManager.resolveExpressions(FILE_URI1, 10, REPLACE_FUNCTION)
assert.equal(result, 'This $variable1_value and $variable1_value should be equal')
})
it('should resolve repeated bad formated messages correctly', async () => {
logPointManager.addLogPoint(FILE_URI1, 10, LOG_MESSAGE_BADLY_FORMATED_VAR)
const result = await logPointManager.resolveExpressions(FILE_URI1, 10, REPLACE_FUNCTION)
assert.equal(result, 'Only $variable1_value should be resolved and not }$variable1 and $variable1')
})
})
})