Merge tests into a larger file (part 5 of ∞) (#9368)
* merge magics * merge metatype tests * merge method tests * merge objects tests * change `import future` to `import sugar` Nim in Action tests are left with `import future`, to ensure compatibility. * merge overload tests * merge proc tests * merge procvar tests * merge range tests * merge seq tests * merge sets tests * remove wrong assert from `tsets3` * fix `jsTests` * better fix
This commit is contained in:
parent
f04c93b5dd
commit
749dbce4c6
96 changed files with 1763 additions and 1815 deletions
72
tests/method/tmultimjs.nim
Normal file
72
tests/method/tmultimjs.nim
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
discard """
|
||||
output: '''
|
||||
7
|
||||
Hi derived!
|
||||
hello
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
# tmultim1
|
||||
type
|
||||
Expression = ref object {.inheritable.}
|
||||
Literal = ref object of Expression
|
||||
x: int
|
||||
PlusExpr = ref object of Expression
|
||||
a, b: Expression
|
||||
|
||||
method eval(e: Expression): int {.base.} = quit "to override!"
|
||||
method eval(e: Literal): int = return e.x
|
||||
method eval(e: PlusExpr): int = return eval(e.a) + eval(e.b)
|
||||
|
||||
proc newLit(x: int): Literal =
|
||||
new(result)
|
||||
result.x = x
|
||||
|
||||
proc newPlus(a, b: Expression): PlusExpr =
|
||||
new(result)
|
||||
result.a = a
|
||||
result.b = b
|
||||
|
||||
echo eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) #OUT 7
|
||||
|
||||
|
||||
|
||||
# tmultim3
|
||||
import mmultim3
|
||||
|
||||
type TBObj* = object of TObj
|
||||
|
||||
method test123(a : ref TBObj) =
|
||||
echo("Hi derived!")
|
||||
|
||||
var aa: ref TBObj
|
||||
new(aa)
|
||||
myObj = aa
|
||||
testMyObj()
|
||||
|
||||
|
||||
|
||||
# tmultim4
|
||||
type Test = object of RootObj
|
||||
|
||||
method doMethod(a: ref RootObj) {.base, raises: [IoError].} =
|
||||
quit "override"
|
||||
|
||||
method doMethod(a: ref Test) =
|
||||
echo "hello"
|
||||
if a == nil:
|
||||
raise newException(IoError, "arg")
|
||||
|
||||
proc doProc(a: ref Test) =
|
||||
echo "hello"
|
||||
|
||||
proc newTest(): ref Test =
|
||||
new(result)
|
||||
|
||||
var s:ref Test = newTest()
|
||||
|
||||
#doesn't work
|
||||
for z in 1..4:
|
||||
s.doMethod()
|
||||
break
|
||||
Loading…
Add table
Add a link
Reference in a new issue