Merge tests into a larger file (part 2 of ∞) (#9335)
* merge controlflow tests * merge distinct tests * merge enum tests * merge fields tests * merge implicit tests * merge iter issues tests
This commit is contained in:
parent
ef820769a4
commit
3c9fcc4c30
40 changed files with 809 additions and 802 deletions
|
|
@ -1,21 +0,0 @@
|
|||
discard """
|
||||
output: '''
|
||||
A
|
||||
A
|
||||
'''
|
||||
"""
|
||||
|
||||
type
|
||||
A[T] = distinct T
|
||||
B[T] = distinct T
|
||||
|
||||
proc foo[T](x:A[T]) = echo "A"
|
||||
proc foo[T](x:B[T]) = echo "B"
|
||||
proc bar(x:A) = echo "A"
|
||||
proc bar(x:B) = echo "B"
|
||||
|
||||
var
|
||||
a:A[int]
|
||||
|
||||
foo(a) # fine
|
||||
bar(a) # testdistinct.nim(14, 4) Error: ambiguous call; both testdistinct.bar(x: A) and testdistinct.bar(x: B) match for: (A[system.int])
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
discard """
|
||||
exitcode: 0
|
||||
output: ''''''
|
||||
"""
|
||||
|
||||
# Snippet not defined as ```nim
|
||||
|
||||
type MyInt* = distinct int
|
||||
|
||||
proc `+`*(x: MyInt, y: MyInt): MyInt {.borrow.}
|
||||
proc `+=`*(x: var MyInt, y: MyInt) {.borrow.}
|
||||
proc `=`*(x: var MyInt, y: MyInt) {.borrow.}
|
||||
|
||||
var next: MyInt
|
||||
|
||||
proc getNext*() : MyInt =
|
||||
result = next
|
||||
next += 1.MyInt
|
||||
next = next + 1.MyInt
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
discard """
|
||||
output: '''
|
||||
25.0
|
||||
210.0
|
||||
'''
|
||||
"""
|
||||
|
||||
type
|
||||
Dollars = distinct float
|
||||
|
||||
proc `$`(d: Dollars): string {.borrow.}
|
||||
proc `*` *(a, b: Dollars): Dollars {.borrow.}
|
||||
proc `+` *(a, b: Dollars): Dollars {.borrow.}
|
||||
|
||||
var a = Dollars(20)
|
||||
a = Dollars(25.0)
|
||||
echo a
|
||||
a = 10.Dollars * (20.Dollars + 1.Dollars)
|
||||
echo a
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
discard """
|
||||
output: apr
|
||||
"""
|
||||
|
||||
type Fix = distinct string
|
||||
|
||||
proc `$`(f: Fix): string {.borrow.}
|
||||
|
||||
proc mystr(s: string) =
|
||||
echo s
|
||||
|
||||
mystr($Fix("apr"))
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
|
||||
type
|
||||
Foo = object
|
||||
a, b: int
|
||||
s: string
|
||||
|
||||
Bar {.borrow: `.`.} = distinct Foo
|
||||
|
||||
var bb: ref Bar
|
||||
new bb
|
||||
bb.a = 90
|
||||
bb.s = "abc"
|
||||
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
discard """
|
||||
file: "tcurrncy.nim"
|
||||
output: "25"
|
||||
"""
|
||||
template Additive(typ: untyped) =
|
||||
proc `+` *(x, y: typ): typ {.borrow.}
|
||||
proc `-` *(x, y: typ): typ {.borrow.}
|
||||
|
||||
# unary operators:
|
||||
proc `+` *(x: typ): typ {.borrow.}
|
||||
proc `-` *(x: typ): typ {.borrow.}
|
||||
|
||||
template Multiplicative(typ, base: untyped) =
|
||||
proc `*` *(x: typ, y: base): typ {.borrow.}
|
||||
proc `*` *(x: base, y: typ): typ {.borrow.}
|
||||
proc `div` *(x: typ, y: base): typ {.borrow.}
|
||||
proc `mod` *(x: typ, y: base): typ {.borrow.}
|
||||
|
||||
template Comparable(typ: untyped) =
|
||||
proc `<` * (x, y: typ): bool {.borrow.}
|
||||
proc `<=` * (x, y: typ): bool {.borrow.}
|
||||
proc `==` * (x, y: typ): bool {.borrow.}
|
||||
|
||||
template DefineCurrency(typ, base: untyped) =
|
||||
type
|
||||
typ* = distinct base
|
||||
Additive(typ)
|
||||
Multiplicative(typ, base)
|
||||
Comparable(typ)
|
||||
|
||||
proc `$` * (t: typ): string {.borrow.}
|
||||
|
||||
DefineCurrency(TDollar, int)
|
||||
DefineCurrency(TEuro, int)
|
||||
echo($( 12.TDollar + 13.TDollar )) #OUT 25
|
||||
|
||||
|
||||
|
||||
77
tests/distinct/tdistinct.nim
Normal file
77
tests/distinct/tdistinct.nim
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
discard """
|
||||
output: '''
|
||||
25
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
block tborrowdot:
|
||||
type
|
||||
Foo = object
|
||||
a, b: int
|
||||
s: string
|
||||
|
||||
Bar {.borrow: `.`.} = distinct Foo
|
||||
|
||||
var bb: ref Bar
|
||||
new bb
|
||||
bb.a = 90
|
||||
bb.s = "abc"
|
||||
|
||||
|
||||
|
||||
block tcurrncy:
|
||||
template Additive(typ: untyped) =
|
||||
proc `+`(x, y: typ): typ {.borrow.}
|
||||
proc `-`(x, y: typ): typ {.borrow.}
|
||||
|
||||
# unary operators:
|
||||
proc `+`(x: typ): typ {.borrow.}
|
||||
proc `-`(x: typ): typ {.borrow.}
|
||||
|
||||
template Multiplicative(typ, base: untyped) =
|
||||
proc `*`(x: typ, y: base): typ {.borrow.}
|
||||
proc `*`(x: base, y: typ): typ {.borrow.}
|
||||
proc `div`(x: typ, y: base): typ {.borrow.}
|
||||
proc `mod`(x: typ, y: base): typ {.borrow.}
|
||||
|
||||
template Comparable(typ: untyped) =
|
||||
proc `<`(x, y: typ): bool {.borrow.}
|
||||
proc `<=`(x, y: typ): bool {.borrow.}
|
||||
proc `==`(x, y: typ): bool {.borrow.}
|
||||
|
||||
template DefineCurrency(typ, base: untyped) =
|
||||
type
|
||||
typ = distinct base
|
||||
Additive(typ)
|
||||
Multiplicative(typ, base)
|
||||
Comparable(typ)
|
||||
|
||||
proc `$`(t: typ): string {.borrow.}
|
||||
|
||||
DefineCurrency(TDollar, int)
|
||||
DefineCurrency(TEuro, int)
|
||||
echo($( 12.TDollar + 13.TDollar )) #OUT 25
|
||||
|
||||
|
||||
|
||||
block tconsts:
|
||||
# bug #2641
|
||||
|
||||
type MyChar = distinct char
|
||||
const c:MyChar = MyChar('a')
|
||||
|
||||
type MyBool = distinct bool
|
||||
const b:MyBool = MyBool(true)
|
||||
|
||||
type MyBoolSet = distinct set[bool]
|
||||
const bs:MyBoolSet = MyBoolSet({true})
|
||||
|
||||
type MyCharSet= distinct set[char]
|
||||
const cs:MyCharSet = MyCharSet({'a'})
|
||||
|
||||
type MyBoolSeq = distinct seq[bool]
|
||||
const bseq:MyBoolSeq = MyBoolSeq(@[true, false])
|
||||
|
||||
type MyBoolArr = distinct array[3, bool]
|
||||
const barr:MyBoolArr = MyBoolArr([true, false, true])
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
# bug #2641
|
||||
|
||||
type MyChar = distinct char
|
||||
const c:MyChar = MyChar('a')
|
||||
|
||||
type MyBool = distinct bool
|
||||
const b:MyBool = MyBool(true)
|
||||
|
||||
type MyBoolSet = distinct set[bool]
|
||||
const bs:MyBoolSet = MyBoolSet({true})
|
||||
|
||||
type MyCharSet= distinct set[char]
|
||||
const cs:MyCharSet = MyCharSet({'a'})
|
||||
|
||||
type MyBoolSeq = distinct seq[bool]
|
||||
const bseq:MyBoolSeq = MyBoolSeq(@[true, false])
|
||||
|
||||
type MyBoolArr = distinct array[3, bool]
|
||||
const barr:MyBoolArr = MyBoolArr([true, false, true])
|
||||
67
tests/distinct/tissues.nim
Normal file
67
tests/distinct/tissues.nim
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
discard """
|
||||
output: '''
|
||||
A
|
||||
A
|
||||
25.0
|
||||
210.0
|
||||
apr
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
block t4435:
|
||||
type
|
||||
A[T] = distinct T
|
||||
B[T] = distinct T
|
||||
|
||||
proc foo[T](x:A[T]) = echo "A"
|
||||
proc foo[T](x:B[T]) = echo "B"
|
||||
proc bar(x:A) = echo "A"
|
||||
proc bar(x:B) = echo "B"
|
||||
|
||||
var
|
||||
a:A[int]
|
||||
|
||||
foo(a) # fine
|
||||
bar(a) # testdistinct.nim(14, 4) Error: ambiguous call; both testdistinct.bar(x: A) and testdistinct.bar(x: B) match for: (A[system.int])
|
||||
|
||||
|
||||
|
||||
block t7010:
|
||||
type MyInt = distinct int
|
||||
|
||||
proc `+`(x: MyInt, y: MyInt): MyInt {.borrow.}
|
||||
proc `+=`(x: var MyInt, y: MyInt) {.borrow.}
|
||||
proc `=`(x: var MyInt, y: MyInt) {.borrow.}
|
||||
|
||||
var next: MyInt
|
||||
|
||||
proc getNext() : MyInt =
|
||||
result = next
|
||||
next += 1.MyInt
|
||||
next = next + 1.MyInt
|
||||
|
||||
|
||||
|
||||
block t9079:
|
||||
type
|
||||
Dollars = distinct float
|
||||
|
||||
proc `$`(d: Dollars): string {.borrow.}
|
||||
proc `*`(a, b: Dollars): Dollars {.borrow.}
|
||||
proc `+`(a, b: Dollars): Dollars {.borrow.}
|
||||
|
||||
var a = Dollars(20)
|
||||
a = Dollars(25.0)
|
||||
echo a
|
||||
a = 10.Dollars * (20.Dollars + 1.Dollars)
|
||||
echo a
|
||||
|
||||
|
||||
|
||||
block t9322:
|
||||
type Fix = distinct string
|
||||
proc `$`(f: Fix): string {.borrow.}
|
||||
proc mystr(s: string) =
|
||||
echo s
|
||||
mystr($Fix("apr"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue