Skip to content

Commit

Permalink
Add test for toString of nullable abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
tobil4sk committed Feb 18, 2025
1 parent fefe7c1 commit 83915ec
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/unit/src/unit/issues/Issue12019.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package unit.issues;

private abstract MyStringA(Null<String>) from Null<String> {
function toString() {
if (this == null)
return "EMPTY";
return this;
}
}

private typedef NullableString = Null<String>;

private abstract MyStringB(NullableString) from NullableString {
function toString() {
if (this == null)
return "EMPTY";
return this;
}
}

class Issue12019 extends unit.Test {
final a:MyStringA = null;
final b:MyStringB = null;

var oldTrace:(Dynamic, ?Null<haxe.PosInfos>) -> Void;

function setup() {
oldTrace = haxe.Log.trace;
}

function teardown() {
haxe.Log.trace = oldTrace;
}

function testTrace() {
haxe.Log.trace = function(v, ?infos) {
eq("EMPTY", v);
};

trace(a);
trace(b);
}

function testConcatenate() {
eq("Concatenated: EMPTY", "Concatenated: " + a);
eq("Concatenated: EMPTY", "Concatenated: " + b);
}
}

0 comments on commit 83915ec

Please sign in to comment.