Skip to content

Commit

Permalink
Add some tests for type "Array".
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed May 16, 2024
1 parent dc0aaba commit 3e1866c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
40 changes: 40 additions & 0 deletions server/src/UC/test/array/ArrayTest.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class ArrayTest;

var array<string> array;

function ShouldBeValidArrayIteratorTest()
{
local string s;
local int i;

// ! UC3 "Type 'Array' cannot be iterated. Expected an iterator function."
foreach array(s, i);

array[0] = "";
array[0.0] = "";
}

function ShouldBeInvalidArrayIteratorTest()
{
local string s;
local int i;

// #if UC2
// // ! UC2 "Type 'Array' cannot be iterated. Expected an iterator function."
// foreach array(s, i);
// #endif

// ! Expected "Missing iterator arguments."
foreach array();

// Wrong order
foreach array(i, s);

// ! "An element access expression should take an argument."
array[];

// ! "Type of 'None.ArrayTest.ShouldBeInvalidArrayIteratorTest.B' is not a valid array."
b[0];

b[""];
}
15 changes: 15 additions & 0 deletions server/src/UC/test/array/array.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { queueIndexDocument } from '../../indexer';
import { assertDocumentInvalidFieldsAnalysis, assertDocumentValidFieldsAnalysis } from '../utils/diagnosticUtils';
import { usingDocuments } from '../utils/utils';

describe('Array usage', () => {
usingDocuments(__dirname, ['ArrayTest.uc'], ([testDocument]) => {
queueIndexDocument(testDocument);

it('should have no problems', () => {
queueIndexDocument(testDocument);
assertDocumentValidFieldsAnalysis(testDocument, /\bShould(?!BeInvalid)/i);
assertDocumentInvalidFieldsAnalysis(testDocument, /\bInvalid/);
});
});
});
4 changes: 3 additions & 1 deletion server/src/UC/test/utils/diagnosticUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { rangeToString } from '../../diagnostics/diagnostic';
import { DocumentAnalyzer } from '../../diagnostics/documentAnalyzer';
import { UCDocument } from '../../document';
Expand Down Expand Up @@ -51,6 +51,8 @@ export function assertDocumentInvalidFieldsAnalysis(document: UCDocument, patter
stm.accept(diagnoser);
if (diagnostics.count() === 0) {
expect.fail(`Missing problem in statement "${textDocument.getText(stm.getRange())}" of '${field.getPath()}' at ${rangeToString(stm.getRange())}`);
} else {
console.debug(`Validated problem in statement "${textDocument.getText(stm.getRange())}" of '${field.getPath()}' at ${rangeToString(stm.getRange())}`);
}
}
}
Expand Down

0 comments on commit 3e1866c

Please sign in to comment.