-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constructor inheritance, also app.nim now contains an actually sort o…
…f sensible test
- Loading branch information
Showing
3 changed files
with
79 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,40 @@ | ||
import tsGlue | ||
|
||
let two* {.exportc.} = QTALKTOME | ||
let twoString* {.exportc.} = QTALKTOME2 | ||
# POST | ||
|
||
let three* {.exportc.} = QADDONE(QTALKTOME) | ||
var failed = false | ||
try: | ||
testAssert(false, "Expecting to fail") | ||
except: | ||
failed = true | ||
testAssert(failed, "Self-test of test script") | ||
|
||
QCONSOLELOG("two plus one is " & $three) | ||
# Actual tests | ||
|
||
QDEKZ.ONE = 3 | ||
QCONSOLELOG("three plus two is " & $QDEKZ.FUNC(QDEKZ.ONE)) | ||
let QBbackflow* {.exportc.} = 543 | ||
|
||
let four : QDEK1 = newQDEK1() | ||
let five : QDEK2 = newQDEK2("Concat ") | ||
testAssert(QBnumber == 2, "Number variable") | ||
testAssert(QBstring == "OK", "String variable") | ||
|
||
QCONSOLELOG("two plus three is " & $four.FUNC(3)) | ||
testAssert(QFaddone(5) == 6, "Call function") | ||
|
||
QCONSOLELOG(five.FUNC2("working")) | ||
testAssert(QIchild.num3 == 3, "Check instance") | ||
|
||
QIchild.num3 = 11 | ||
testAssert(QIchild.num3 == 11, "Write instance") | ||
|
||
QIChild.addNum(5) | ||
testAssert(QIchild.num3 == 16, "Read instance 2") | ||
|
||
let inst1 : QCbase = newQCbase() | ||
let inst2 : QCbase = newQCchild("glow") | ||
let inst3 : QCgrand = newQCgrand("black") | ||
let inst4 = newQCorder() | ||
|
||
testAssert(inst1.add2(17) == 19, "Call method") | ||
testAssert(inst2.add2(19) == 21, "Call method 2") | ||
testAssert(inst3.addStr("light") == "blacklight", "Inherit constructor") | ||
testAssert(inst4.grand.addStr("fish") == "silverfish", "Inherit constructor 2") | ||
|
||
# TODO: Needs function-typed variables | ||
# testAssert(QFbackflow() == 543, "Exportc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,66 @@ | ||
function testAssert(condition: boolean, message:string) { | ||
if (!condition) | ||
throw new Error("Test failed: " + message) | ||
} | ||
|
||
let QTALKTOME = 2 | ||
let QTALKTOME2 = "OK" | ||
let QBnumber = 2 | ||
let QBstring = "OK" | ||
|
||
function QADDONE(x:number) { | ||
function QFaddone(x:number) { | ||
return x + 1 | ||
} | ||
|
||
class QDEK1 { | ||
ONE:number | ||
TWO:string | ||
class QCorder { | ||
grand: QCgrand | ||
constructor() { | ||
this.grand = new QCgrand("silver") | ||
} | ||
} | ||
|
||
class QCbase { | ||
num1:number | ||
str2:string | ||
|
||
FUNC(x:number) { return x + 2 } | ||
add2(x:number) { return x + 2 } | ||
} | ||
|
||
class QDEK2 extends QDEK1 { | ||
THREE:number | ||
FOUR:string | ||
class QCchild extends QCbase { | ||
num3:number | ||
str4:string | ||
constructor(ok:string) { | ||
super() | ||
this.THREE = 3 | ||
this.FOUR = ok | ||
this.num3 = 3 | ||
this.str4 = ok | ||
} | ||
FUNC2(y:string) { return this.FOUR + y } | ||
addNum(y:number) { this.num3 += y } | ||
} | ||
|
||
let QDEKZ = new QDEK2("3") | ||
|
||
function QCONSOLELOG(s:string) { | ||
console.log(s) | ||
class QCgrand extends QCchild { | ||
addStr(y:string) { return this.str4 + y } | ||
} | ||
|
||
let XGY : QDEK1[] | ||
let QIchild = new QCchild("3") | ||
|
||
let QAarray : QCbase[] | ||
|
||
class XQ1<T> { | ||
class QCgeneric<T> { | ||
x: T | ||
} | ||
|
||
let XQ2 : XQ1<number> | ||
let QIgeneric : QCgeneric<number> | ||
|
||
class XREC1 { | ||
a1: XREC2 | ||
class QCrecursive1 { | ||
a1: QCrecursive2 | ||
} | ||
|
||
class XREC2 { | ||
constructor(public a2 : XREC1) { | ||
class QCrecursive2 { | ||
constructor(public a2 : QCrecursive1) { | ||
a2.a1 = this | ||
} | ||
} | ||
|
||
// TODO: Right now we erase mutually exclusive types, but pass through variables typed as one of the erased types | ||
// let XR = new XREC2(new XREC1()) | ||
|
||
// Ugly way to access global variable | ||
let QFbackflow = () : number => (<any>this).QBbackflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters