Skip to content

Commit

Permalink
[display] add a test for #7877
Browse files Browse the repository at this point in the history
(or at least the part of it that's fixed)
  • Loading branch information
Gama11 committed Feb 26, 2019
1 parent 08791f5 commit b20cb70
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/display/build.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
--main Main
--interp
-D use-rtti-doc
# -D test=Issue7326
# -D test=Issue7877
29 changes: 29 additions & 0 deletions tests/display/src/Diagnostic.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// from vshaxe

import haxe.display.Position.Range;

enum abstract UnresolvedIdentifierSuggestion(Int) {
var UISImport;
var UISTypo;
}

enum abstract DiagnosticKind<T>(Int) from Int to Int {
var DKUnusedImport:DiagnosticKind<Void>;
var DKUnresolvedIdentifier:DiagnosticKind<Array<{kind:UnresolvedIdentifierSuggestion, name:String}>>;
var DKCompilerError:DiagnosticKind<String>;
var DKRemovableCode:DiagnosticKind<{description:String, range:Range}>;
}

enum abstract DiagnosticSeverity(Int) {
var Error = 1;
var Warning;
var Information;
var Hint;
}

typedef Diagnostic<T> = {
var kind:DiagnosticKind<T>;
var range:Range;
var severity:DiagnosticSeverity;
var args:T;
}
7 changes: 4 additions & 3 deletions tests/display/src/DisplayTestCase.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class DisplayTestCase {
inline function range(pos1, pos2) return ctx.range(pos1, pos2);
inline function signature(pos1) return ctx.signature(pos1);
inline function metadataDoc(pos1) return ctx.metadataDoc(pos1);
inline function diagnostics() return ctx.diagnostics();

inline function noCompletionPoint(f) return ctx.noCompletionPoint(f);

Expand All @@ -35,20 +36,20 @@ class DisplayTestCase {
}
}

function arrayEq(expected:Array<String>, actual:Array<String>, ?pos:haxe.PosInfos) {
function arrayEq<T>(expected:Array<T>, actual:Array<T>, ?pos:haxe.PosInfos) {
numTests++;
var leftover = expected.copy();
for (actual in actual) {
if (!leftover.remove(actual)) {
numFailures++;
report("Result not part of expected Array:", pos);
report(actual, pos);
report(Std.string(actual), pos);
}
}
for (leftover in leftover) {
numFailures++;
report("Expected result was not part of actual Array:", pos);
report(leftover, pos);
report(Std.string(leftover), pos);
return;
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/display/src/DisplayTestContext.hx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class DisplayTestContext {
return extractMetadata(callHaxe('$pos@type'));
}

public function diagnostics():Array<Diagnostic<Any>> {
var result = haxe.Json.parse(callHaxe('0@diagnostics'))[0];
return if (result == null) [] else result.diagnostics;
}

public function noCompletionPoint(f:Void -> Void):Bool {
return try {
f();
Expand Down
15 changes: 15 additions & 0 deletions tests/display/src/cases/Issue7877.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cases;

class Issue7877 extends DisplayTestCase {
/**
class Main {
public static function main() {
new misc.issue7877.ProcessedClass(false);
new misc.issue7877.ProcessedClass(true);
}
}
**/
function test() {
arrayEq([], diagnostics());
}
}
40 changes: 40 additions & 0 deletions tests/display/src/misc/issue7877/ProcessMacro.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package misc.issue7877;

import haxe.macro.Expr;
import haxe.macro.Context;

class ProcessMacro {
public static macro function build():Array<Field> {
var fields = Context.getBuildFields();
var toInit = [
for (field in fields) {
switch (field) {
case {name: name, kind: FVar(t, e), access: [AFinal]}:
{name: name, type: t, def: e};
case _:
continue;
}
}
];

var args:Array<FunctionArg> = [];
var exprs = [];
for (init in toInit) {
args.push({
name: init.name,
opt: init.def != null,
type: init.type,
value: init.def
});
var n = init.name;
exprs.push(macro this.$n = $i{n});
}
fields.push({
pos: Context.currentPos(),
name: 'new',
access: [APublic],
kind: FFun({ret: null, args: args, expr: {pos: Context.currentPos(), expr: EBlock(exprs)}})
});
return fields;
}
}
9 changes: 9 additions & 0 deletions tests/display/src/misc/issue7877/ProcessedClass.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package misc.issue7877;

@:build(misc.issue7877.ProcessMacro.build()) class ProcessedClass {
final foo:Bool; // = false;

function bar() {
trace(foo);
}
}

0 comments on commit b20cb70

Please sign in to comment.