Skip to content

Commit 64038ff

Browse files
committed
[Test] Unit tests for logDebugger
1 parent e17651b commit 64038ff

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import * as assert from 'assert';
2+
import { LogDebugger } from '../../logDebugger';
3+
4+
suite('LogDebugger Test Suite', () => {
5+
let logDebugger: LogDebugger;
6+
7+
setup(() => {
8+
logDebugger = new LogDebugger();
9+
});
10+
11+
suite('Line navigation', () => {
12+
test('starts at line 1', () => {
13+
assert.strictEqual(logDebugger.linenum(), 1);
14+
});
15+
16+
test('stepForward increments line', () => {
17+
logDebugger.setToLog('/fake/log', 100);
18+
logDebugger.stepForward();
19+
assert.strictEqual(logDebugger.linenum(), 2);
20+
});
21+
22+
test('stepForward clamps at logLines', () => {
23+
logDebugger.setToLog('/fake/log', 3);
24+
logDebugger.stepForward();
25+
logDebugger.stepForward();
26+
logDebugger.stepForward();
27+
assert.strictEqual(logDebugger.linenum(), 3);
28+
});
29+
30+
test('stepBackward decrements line', () => {
31+
logDebugger.setToLog('/fake/log', 100);
32+
logDebugger.stepForward();
33+
logDebugger.stepForward();
34+
logDebugger.stepBackward();
35+
assert.strictEqual(logDebugger.linenum(), 2);
36+
});
37+
38+
test('stepBackward clamps at line 1', () => {
39+
logDebugger.setToLog('/fake/log', 100);
40+
logDebugger.stepBackward();
41+
assert.strictEqual(logDebugger.linenum(), 1);
42+
});
43+
});
44+
45+
suite('Breakpoints', () => {
46+
const logPath = '/fake/log.log';
47+
48+
test('hasBreakpoints is false with no breakpoints set', () => {
49+
logDebugger.setToLog(logPath, 100);
50+
assert.strictEqual(logDebugger.hasBreakpoints(), false);
51+
});
52+
53+
test('hasBreakpoints is true after breakpoints set', () => {
54+
logDebugger.setToLog(logPath, 100);
55+
logDebugger.setBreakPoint(logPath, [{ line: 10 }]);
56+
assert.ok(logDebugger.hasBreakpoints());
57+
});
58+
59+
test('hasBreakpoints is false after empty breakpoints set', () => {
60+
logDebugger.setToLog(logPath, 100);
61+
logDebugger.setBreakPoint(logPath, []);
62+
assert.strictEqual(logDebugger.hasBreakpoints(), false);
63+
});
64+
65+
test('gotoNextBreakpoint advances to next breakpoint', () => {
66+
logDebugger.setToLog(logPath, 100);
67+
// setBreakPoint moves _line to the first breakpoint (10) when starting at line 1
68+
logDebugger.setBreakPoint(logPath, [{ line: 10 }, { line: 20 }, { line: 30 }]);
69+
assert.strictEqual(logDebugger.linenum(), 10);
70+
logDebugger.gotoNextBreakpoint();
71+
assert.strictEqual(logDebugger.linenum(), 20);
72+
logDebugger.gotoNextBreakpoint();
73+
assert.strictEqual(logDebugger.linenum(), 30);
74+
});
75+
76+
test('gotoNextBreakpoint reverse retreats to previous breakpoint', () => {
77+
logDebugger.setToLog(logPath, 100);
78+
// setBreakPoint moves _line to 10; navigate forward to 30, then reverse to 20
79+
logDebugger.setBreakPoint(logPath, [{ line: 10 }, { line: 20 }, { line: 30 }]);
80+
logDebugger.gotoNextBreakpoint(); // 10 → 20
81+
logDebugger.gotoNextBreakpoint(); // 20 → 30
82+
logDebugger.gotoNextBreakpoint(true); // 30 → 20
83+
assert.strictEqual(logDebugger.linenum(), 20);
84+
});
85+
86+
test('gotoNextBreakpoint past last clamps to logLines', () => {
87+
logDebugger.setToLog(logPath, 100);
88+
logDebugger.setBreakPoint(logPath, [{ line: 10 }]);
89+
logDebugger.gotoNextBreakpoint();
90+
logDebugger.gotoNextBreakpoint();
91+
assert.strictEqual(logDebugger.linenum(), 100);
92+
});
93+
94+
test('gotoNextBreakpoint before first in reverse clamps to line 1', () => {
95+
logDebugger.setToLog(logPath, 100);
96+
logDebugger.setBreakPoint(logPath, [{ line: 10 }]);
97+
logDebugger.gotoNextBreakpoint(true);
98+
assert.strictEqual(logDebugger.linenum(), 1);
99+
});
100+
});
101+
});

0 commit comments

Comments
 (0)