Skip to content

Commit

Permalink
test: add tests for local import
Browse files Browse the repository at this point in the history
- Add test #10 and #11 in ModuleInstantiator
- Update test values for indexer_map tests
  • Loading branch information
Gustave Penloup committed Aug 28, 2024
1 parent 9fa815c commit 93cf556
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 13 deletions.
43 changes: 42 additions & 1 deletion src/test/ModuleInstantiator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ suite('ModuleInstantiator Tests', () => {

let fullRange = null;
// Range of the module in the document
fullRange = new vscode.Range(new vscode.Position(300, 6), new vscode.Position(324, 0));
fullRange = new vscode.Range(new vscode.Position(301, 6), new vscode.Position(324, 0));

let container = document.getText(fullRange).replace(/^\s+|\s+$/g, '');

Expand Down Expand Up @@ -239,6 +239,47 @@ suite('ModuleInstantiator Tests', () => {

compareInstantiation('azzer', container, instance);
});

test('test #10: formatInstance without parameters and with import', async () => {
let uri = vscode.Uri.file(path.join(__dirname, testFolderLocation, 'test-files', 'ModuleInstantiator.test.1.v')); // prettier-ignore
let document = await vscode.workspace.openTextDocument(uri);

// Range of the module in the document
let fullRange = null;
fullRange = new vscode.Range(new vscode.Position(358, 6), new vscode.Position(392, 0));

const container = document.getText(fullRange).replace(/^\s+|\s+$/g, '');
uri = vscode.Uri.file(path.join(__dirname, testFolderLocation, 'test-files', 'ModuleInstantiator.test.2.v'));
document = await vscode.workspace.openTextDocument(uri);
fullRange = new vscode.Range(new vscode.Position(168, 0), new vscode.Position(179, 0));

let instance = document.getText(fullRange);

compareInstantiation('abber', container, instance);
});

test('test #11: formatInstance with parameters and specific import', async () => {
let uri = vscode.Uri.file(path.join(__dirname, testFolderLocation, 'test-files', 'ModuleInstantiator.test.1.v')); // prettier-ignore
let document = await vscode.workspace.openTextDocument(uri);

let fullRange = null;
// Range of the module in the document
fullRange = new vscode.Range(new vscode.Position(395, 6), new vscode.Position(431, 0));

let container = document.getText(fullRange).replace(/^\s+|\s+$/g, '');

console.log("Container \n\r"+container);

uri = vscode.Uri.file(path.join(__dirname, testFolderLocation, 'test-files', 'ModuleInstantiator.test.2.v'));
document = await vscode.workspace.openTextDocument(uri);

fullRange = new vscode.Range(new vscode.Position(184, 0), new vscode.Position(198, 0));

let instance = document.getText(fullRange);

compareInstantiation('affer', container, instance);
});

});

function compareInstantiation(instance_name, container_name, expected): void {
Expand Down
24 changes: 12 additions & 12 deletions src/test/indexer_map.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let symbols: Map<string, Array<SystemVerilogSymbol>>;
const testFolderLocation = '../../src/test';

const uri = Uri.file(path.join(__dirname, testFolderLocation, 'test-files', 'ModuleInstantiator.test.1.v'));
const documentSymbols = ['adder', 'bar', 'akker', 'accer', 'anner', 'atter', 'apper', 'golden'];
const documentSymbols = ['adder', 'bar', 'akker', 'accer', 'anner', 'atter', 'apper', 'golden', 'abber', 'affer'];

const nonSVUri = Uri.file(path.join(__dirname, testFolderLocation, 'test-files', 'foo.txt'));

Expand All @@ -31,10 +31,10 @@ suite('indexer_map Tests', () => {
assert.strictEqual(symbols.size, 4);
let count = await indexer.addDocumentSymbols(sVDocument, symbols);

assert.strictEqual(count, 10);
assert.strictEqual(count, 12);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(symbols.get(uri.fsPath).length, 10);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(symbols.get(uri.fsPath).length, 12);
assert.strictEqual(getSymbolsCount(), 25);

documentSymbols.forEach((symbolName) => {
if (!symbolExists(symbolName)) {
Expand All @@ -47,28 +47,28 @@ suite('indexer_map Tests', () => {
assert.strictEqual(count, 0);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(symbols.get(nonSVUri.fsPath), undefined);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(getSymbolsCount(), 25);

// undefined/null document
count = await indexer.addDocumentSymbols(undefined, symbols);
assert.strictEqual(count, 0);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(getSymbolsCount(), 25);

count = await indexer.addDocumentSymbols(sVDocument, undefined);
assert.strictEqual(count, 0);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(getSymbolsCount(), 25);

count = await indexer.addDocumentSymbols(undefined, undefined);
assert.strictEqual(count, 0);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(getSymbolsCount(), 25);

count = await indexer.addDocumentSymbols(null, symbols);
assert.strictEqual(count, 0);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(getSymbolsCount(), 25);
});

test('test #2: removeDocumentSymbols', async () => {
Expand All @@ -80,9 +80,9 @@ suite('indexer_map Tests', () => {
assert.strictEqual(symbols.size, 4);
let count = await indexer.addDocumentSymbols(sVDocument, symbols);

assert.strictEqual(count, 10);
assert.strictEqual(count, 12);
assert.strictEqual(symbols.size, 5);
assert.strictEqual(getSymbolsCount(), 23);
assert.strictEqual(getSymbolsCount(), 25);

count = indexer.removeDocumentSymbols(sVDocument.uri.fsPath, symbols);

Expand All @@ -92,7 +92,7 @@ suite('indexer_map Tests', () => {
}
});

assert.strictEqual(count, -10);
assert.strictEqual(count, -12);
assert.strictEqual(symbols.size, 4);
assert.strictEqual(getSymbolsCount(), 13);

Expand Down
77 changes: 77 additions & 0 deletions src/test/test-files/ModuleInstantiator.test.1.v
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,80 @@ module azzer #(parameter SIZE = (2*1)+1,
assign c = tmp_c;

endmodule

// -------------------------------------------------------
// -- Example without parameters and with import
// -------------------------------------------------------

module abber import pa_Package::*; (
input clk,
input reset,
input [3:0] a,
// keep this single comment
input [3:0] b,
/* multiline comment should
be kept*/
input valid,
output [6:0] c
);

reg [6:0] tmp_c;

//Reset
always_ff @(posedge reset)
tmp_c <= pa_adder::RV_C;

`ifdef VERBOSE_RESET
always @(posedge reset) begin
wait(posedge reset);
$display("Reset asserted!")
end
`endif

// Waddition operation
always @(posedge clk)
if(valid) tmp_c <= a + b;

assign c = tmp_c;

endmodule

// -------------------------------------------------------
// -- Example with parameters and specific import
// -------------------------------------------------------

module affer import pa_Package::PARAMETER1; #(
parameter SIZE = PARAMETER1,
parameter SIZE_TWO
)(
input clk,
input reset,
input [3:0] a,
// keep this single comment
input [3:0] b,
/* multiline comment should
be kept*/
input valid,
output [6:0] c
);

reg [6:0] tmp_c;

//Reset
always_ff @(posedge reset)
tmp_c <= pa_adder::RV_C;

`ifdef VERBOSE_RESET
always @(posedge reset) begin
wait(posedge reset);
$display("Reset asserted!")
end
`endif

// Waddition operation
always @(posedge clk)
if(valid) tmp_c <= a + b;

assign c = tmp_c;

endmodule
36 changes: 36 additions & 0 deletions src/test/test-files/ModuleInstantiator.test.2.v
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,42 @@ azzer #(
.c (c)
);

// -------------------------------------------------------
// -- Example without parameters and with import
// -------------------------------------------------------

abber u_abber (
.clk (clk),
.reset (reset),
.a (a),
// keep this single comment
.b (b),
/* multiline comment should
be kept*/
.valid (valid),
.c (c)
);

// -------------------------------------------------------
// -- Example with parameters and specific import
// -------------------------------------------------------

affer #(
.SIZE (PARAMETER1),
.SIZE_TWO (SIZE_TWO)
) u_affer (
.clk (clk),
.reset (reset),
.a (a),
// keep this single comment
.b (b),
/* multiline comment should
be kept*/
.valid (valid),
.c (c)
);


// -------------------------------------------------------
// -- End file
// -------------------------------------------------------

0 comments on commit 93cf556

Please sign in to comment.