Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor keyboard navigation #106

Merged
merged 2 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Change navigation test to check overlapping positions
  • Loading branch information
Discookie committed Apr 11, 2022
commit b94b179bb1b8bd2f8b0ab45509d6ffb27a3af362
60 changes: 43 additions & 17 deletions src/test/editor/editor.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,14 @@ suite('Functional Test: Frontend - Editor', () => {
});

test('Navigation commands, in same file as well as between different files', async function() {
// The path of this division by zero has 6 steps, with steps 2-4 in main.h, rest in main.cpp
// Positions are tested by line number/file only, since selection ranges can differ between methods
// The path of this division by zero has 6 steps, with steps 3-4 in main.h, rest in main.cpp
const changePositionViaCommand = async (command: string, ...params: any[]) => {
await wrapWithEvent(
window.onDidChangeTextEditorSelection,
async () => await commands.executeCommand(command, ...params)
);
};

const assertLine = (line: number) => {
assert.strictEqual(window.activeTextEditor?.selection.active.line, line, 'Line position mismatch');
};

await openFileWithEvent(diagnosticsApi.diagnosticsUpdated, filePath);

await window.showTextDocument(Uri.file(filePath), { selection: new Range(0, 0, 0, 0) });
Expand All @@ -103,22 +98,53 @@ suite('Functional Test: Frontend - Editor', () => {
'Unexpected CodeChecker results, the test needs updating'
);

// In baz, on line 8
const positions: [string, number, number][] = [
[filePath, 3, 17], // Passing 0
[filePath, 3, 13], // Entering call
[headerPath, 3, 0], // Entered call
[headerPath, 4, 2], // Returning zero
[filePath, 3, 13], // Returning from foo - same position as Entering call (issue #86)
[filePath, 3, 11] // Entered call
];

const assertPosition = (idx: number) => {
const [file, line, col] = positions[idx];

assert.strictEqual(
window.activeTextEditor?.document.uri.fsPath,
file,
'File mismatch on step ' + idx
);
assert.strictEqual(
window.activeTextEditor?.selection.active.line,
line,
'Line mismatch on step ' + idx
);
assert.strictEqual(
window.activeTextEditor?.selection.active.character,
col,
'Column mismatch on step ' + idx
);
};

// Report position is the same as step 5 in this case
await changePositionViaCommand('codechecker.editor.jumpToReport', filePath, 0);
assertLine(7);
assertPosition(5);

// In main, on line 4
await changePositionViaCommand('codechecker.editor.jumpToStep', filePath, 0, 0);
assertLine(3);
assertPosition(0);

// In file main.h
await changePositionViaCommand('codechecker.editor.nextStep');
assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, headerPath, 'Next step opens invalid file');
// Step forwards all the way
for (let idx = 1; idx < positions.length; idx++) {
await changePositionViaCommand('codechecker.editor.nextStep');
assertPosition(idx);
}

// File main.cpp in main, on line 4
await changePositionViaCommand('codechecker.editor.previousStep');
assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, filePath, 'Prev step opens invalid file');
assertLine(3);
// And then backwards all the way
for (let idx = positions.length - 2; idx >= 0; idx--) {
await changePositionViaCommand('codechecker.editor.previousStep');
assertPosition(idx);
}

// closeAllTabs handles all resulting events
await commands.executeCommand('codechecker.editor.toggleSteps', filePath, 0, false);
Expand Down
6 changes: 1 addition & 5 deletions src/test/staticFiles/workspace/file.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "file.h"

int main() {
return foo();
}

int bar(int param) {
return 1 / param;
return 1 / foo(0);
}
6 changes: 2 additions & 4 deletions src/test/staticFiles/workspace/file.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#ifndef FILE_H
#define FILE_H

int bar(int param);

int foo() {
return bar(0);
int foo(int x) {
return x;
}

#endif