Skip to content

Commit

Permalink
More test updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
EliotVU committed May 17, 2024
1 parent 8718c1b commit 1842187
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 57 deletions.
26 changes: 6 additions & 20 deletions server/src/UC/Symbols/ArchetypeSymbol.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { UCDocument } from '../document';
import { UCDocument } from 'UC/document';
import { Name } from '../name';
import { NAME_NONE } from '../names';
import { SymbolWalker } from '../symbolWalker';
import {
addHashedSymbol,
ModifierFlags,
ObjectsTable,
UCFieldSymbol,
UCObjectSymbol,
UCStructSymbol,
Expand Down Expand Up @@ -37,32 +34,21 @@ export class UCArchetypeSymbol extends UCStructSymbol {
if (!this.extendsType) {
text.push(`(override)`);
}
text.push(`class=${this.super?.getPath()}`);
text.push(`Class=${this.super?.getPath()}`);
}
text.push(`name=${this.getPath()}`);
text.push(`Name=${this.getPath()}`);
return text.filter(s => s).join(' ');
}

override findSuperSymbol<T extends UCFieldSymbol>(id: Name, kind?: UCSymbolKind) {
const symbol = this.super?.findSuperSymbol<T>(id, kind);
return symbol;
return this.super?.findSuperSymbol<T>(id, kind);
}

override index(document: UCDocument, context: UCStructSymbol) {
super.index(document, context);
// Lookup the inherited archetype, if it exists.
if (!this.extendsType && !this.super) {
const inheritedArchetype = ObjectsTable.getSymbol<UCArchetypeSymbol>(this.id.name, UCSymbolKind.Archetype);
this.super = inheritedArchetype?.super;
}

// Note: It is crucial to hash the object POST @index()
if (this.id.name !== NAME_NONE) {
addHashedSymbol(this);
}
this.indexSuper(document, context);
}

override accept<Result>(visitor: SymbolWalker<Result>): Result | void {
return visitor.visitArchetypeSymbol(this);
}
}
}
7 changes: 6 additions & 1 deletion server/src/UC/test/UnrealScriptTests/Classes/Object.uc
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
class Object;
class Object
native;

var native name Name;
var native Class Class;
var native Object Outer;
5 changes: 4 additions & 1 deletion server/src/UC/test/archetype/ArchetypeTemplate.uc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class ArchetypeTemplate extends Object;

const TemplateConst = "test";

var name MyName;
var name MyName2;

delegate MyDelegate(name param1, bool param2);
delegate MyDelegate(name param1, bool param2);
11 changes: 8 additions & 3 deletions server/src/UC/test/archetype/ArchetypeTest.uc
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
class ArchetypeTest;
class ArchetypeTest extends Object;

const ArchetypeConst = "test";

var ArchetypeTemplate MyArchetype;

defaultproperties
{
begin object class=ArchetypeTemplate name=ArchetypeTemplate0
MyName=ArchetypeTemplateExample
// Test for lookup of TemplateConst in subobject class 'ArchetypeTemplate'
MyName=TemplateConst
// Test for lookup of ArchetypeConst in document class 'ArchetypeTest'
MyName2=ArchetypeConst
end object
MyArchetype=ArchetypeTemplate0
}
}
54 changes: 33 additions & 21 deletions server/src/UC/test/archetype/archetype.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import { expect } from 'chai';
import { queueIndexDocument } from "../../indexer";
import { usingDocuments } from "../utils/utils";
import { assertDocumentValidSymbolAnalysis } from "../utils/diagnosticUtils";

import { queueIndexDocument } from '../../indexer';
import { toName } from '../../name';
import { ObjectsTable, UCArchetypeSymbol } from '../../Symbols';
import { usingDocuments } from '../utils/utils';
describe("Archetype", () => {
it("should have no problems", () => {
usingDocuments(
__dirname,
[
"ArchetypeTemplate.uc",
"ArchetypeTest.uc",
"ArchetypeOverrideTest.uc",
],
([
archetypeTemplateDoc,
archetypeTestDoc,
archetypeOverrideTestDoc,
]) => {
queueIndexDocument(archetypeOverrideTestDoc);

describe('Archetype', () => {
usingDocuments(__dirname, ['ArchetypeTemplate.uc', 'ArchetypeTest.uc', 'ArchetypeOverrideTest.uc'], ([
, archetypeTestDoc, archetypeOverrideTestDoc
]) => {
it('should override base archetype', () => {
queueIndexDocument(archetypeTestDoc);
const subSymbol = ObjectsTable.getSymbol<UCArchetypeSymbol>(toName('ArchetypeTemplate0'));
expect(subSymbol)
.to.not.be.undefined;

queueIndexDocument(archetypeOverrideTestDoc);
const subOverrideSymbol = ObjectsTable.getSymbol<UCArchetypeSymbol>(toName('ArchetypeTemplate0'));
expect(subOverrideSymbol)
.to.not.be.undefined;
});
assertDocumentValidSymbolAnalysis(
archetypeTemplateDoc,
archetypeTemplateDoc.class
);
assertDocumentValidSymbolAnalysis(
archetypeTestDoc,
archetypeTestDoc.class
);
assertDocumentValidSymbolAnalysis(
archetypeOverrideTestDoc,
archetypeOverrideTestDoc.class
);
}
);
});
});
});
6 changes: 2 additions & 4 deletions server/src/UC/test/array/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { assertDocumentInvalidFieldsAnalysis, assertDocumentValidFieldsAnalysis
import { usingDocuments } from '../utils/utils';

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

it('should have no problems', () => {
it('should have no problems', () => {
usingDocuments(__dirname, ['ArrayTest.uc'], ([testDocument]) => {
queueIndexDocument(testDocument);
assertDocumentValidFieldsAnalysis(testDocument, /\bShould(?!BeInvalid)/i);
assertDocumentInvalidFieldsAnalysis(testDocument, /\bInvalid/);
Expand Down
2 changes: 2 additions & 0 deletions server/src/UC/test/casting/CastingTest.uc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ function ShouldBeValidAssignmentTest()
local CastingTest c;
local Object obj;

c = new (none) Class'CastingTest';
c = new (self) Class'CastingTest';
c = new (none) Class'CastingDerivative';
obj = Class'Object';
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/UC/test/casting/casting.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { queueIndexDocument } from '../../indexer';
import { usingDocuments } from '../utils/utils';
import { assertDocumentValidFieldsAnalysis, assertDocumentInvalidFieldsAnalysis, assertDocumentValidFieldAnalysis } from '../utils/diagnosticUtils';
import { assertDocumentValidFieldsAnalysis, assertDocumentInvalidFieldsAnalysis, assertDocumentValidSymbolAnalysis } from '../utils/diagnosticUtils';
import { toName } from '../../name';

describe('Casting', () => {
Expand All @@ -10,7 +10,7 @@ describe('Casting', () => {
assertDocumentValidFieldsAnalysis(castingTestDocument, /\bShould(?!BeInvalid)/i);
assertDocumentInvalidFieldsAnalysis(castingTestDocument, /\bShouldBeInvalid/i);

assertDocumentValidFieldAnalysis(castingTestDocument, castingTestDocument.class!.getSymbol(toName('defaultproperties')));
assertDocumentValidSymbolAnalysis(castingTestDocument, castingTestDocument.class!.getSymbol(toName('defaultproperties')));
});
});
});
2 changes: 1 addition & 1 deletion server/src/UC/test/struct/StructTest.uc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Custom
static final operator(16) Vector * (float A, Vector B);
static final operator(16) Vector * (Vector A, float B);

function ShouldProduceNoProblems()
function ShouldBeValidStructTest()
{
local Vector vector;
local Plane plane;
Expand Down
3 changes: 2 additions & 1 deletion server/src/UC/test/struct/struct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ describe('Struct usage', () => {
it('should have no problems', () => {
usingDocuments(__dirname, ['StructTest.uc'], ([testDocument]) => {
queueIndexDocument(testDocument);
assertDocumentValidFieldsAnalysis(testDocument);

assertDocumentValidFieldsAnalysis(testDocument, /\bShould(?!BeInvalid)/i);
});
});
});
6 changes: 3 additions & 3 deletions server/src/UC/test/utils/diagnosticUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assert, expect } from 'chai';
import { rangeToString } from '../../diagnostics/diagnostic';
import { DocumentAnalyzer } from '../../diagnostics/documentAnalyzer';
import { UCDocument } from '../../document';
import { UCFieldSymbol, isFunction } from '../../Symbols';
import { ISymbol, UCFieldSymbol, isFunction } from '../../Symbols';
import { Range, TextDocument } from 'vscode-languageserver-textdocument';

/** Runs the document's declared fields through the DocumentAnalyzer, and asserts the count of diagnostic problems that have been produced. */
Expand Down Expand Up @@ -35,13 +35,13 @@ export function assertDocumentValidFieldsAnalysis(document: UCDocument, pattern?
}

/** Runs the document's declared fields through the DocumentAnalyzer, and asserts the count of diagnostic problems that have been produced. */
export function assertDocumentValidFieldAnalysis(document: UCDocument, field: UCFieldSymbol) {
export function assertDocumentValidSymbolAnalysis(document: UCDocument, symbol: ISymbol) {
expect(document.class, 'class').to.not.be.undefined;
expect(document.class.children, 'children').to.not.be.undefined;

const diagnoser = new DocumentAnalyzer(document);

field.accept(diagnoser);
symbol.accept(diagnoser);
assertDocumentDiagnoser(diagnoser).to.equal(0, diagnoser.getDiagnostics().toDiagnostic().map(d => d.message).join('\n'));
}

Expand Down

0 comments on commit 1842187

Please sign in to comment.