merge devel
This commit is contained in:
commit
3e5c94664d
25 changed files with 408 additions and 243 deletions
51
tests/array/tarraycons_ptr_generic.nim
Normal file
51
tests/array/tarraycons_ptr_generic.nim
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
discard """
|
||||
output: '''apple
|
||||
banana
|
||||
Fruit
|
||||
2
|
||||
4
|
||||
3
|
||||
none
|
||||
skin
|
||||
paper
|
||||
'''
|
||||
"""
|
||||
type
|
||||
Fruit = object of RootObj
|
||||
name: string
|
||||
Apple = object of Fruit
|
||||
Banana = object of Fruit
|
||||
|
||||
var
|
||||
ir = Fruit(name: "Fruit")
|
||||
ia = Apple(name: "apple")
|
||||
ib = Banana(name: "banana")
|
||||
|
||||
let x = [ia.addr, ib.addr, ir.addr]
|
||||
for c in x: echo c.name
|
||||
|
||||
type
|
||||
Vehicle[T] = object of RootObj
|
||||
tire: T
|
||||
Car[T] = object of Vehicle[T]
|
||||
Bike[T] = object of Vehicle[T]
|
||||
|
||||
var v = Vehicle[int](tire: 3)
|
||||
var c = Car[int](tire: 4)
|
||||
var b = Bike[int](tire: 2)
|
||||
|
||||
let y = [b.addr, c.addr, v.addr]
|
||||
for c in y: echo c.tire
|
||||
|
||||
type
|
||||
Book[T] = ref object of RootObj
|
||||
cover: T
|
||||
Hard[T] = ref object of Book[T]
|
||||
Soft[T] = ref object of Book[T]
|
||||
|
||||
var bn = Book[string](cover: "none")
|
||||
var hs = Hard[string](cover: "skin")
|
||||
var bp = Soft[string](cover: "paper")
|
||||
|
||||
let z = [bn, hs, bp]
|
||||
for c in z: echo c.cover
|
||||
17
tests/array/tarraycons_ptr_generic2.nim
Normal file
17
tests/array/tarraycons_ptr_generic2.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
file: "tarraycons_ptr_generic2.nim"
|
||||
line: 17
|
||||
errormsg: "type mismatch: got <ptr Hard[system.string]> but expected 'Book[system.string]'"
|
||||
"""
|
||||
|
||||
type
|
||||
Book[T] = ref object of RootObj
|
||||
cover: T
|
||||
Hard[T] = ref object of Book[T]
|
||||
Soft[T] = ref object of Book[T]
|
||||
|
||||
var bn = Book[string](cover: "none")
|
||||
var hs = Hard[string](cover: "skin")
|
||||
var bp = Soft[string](cover: "paper")
|
||||
|
||||
let z = [bn, hs.addr, bp]
|
||||
|
|
@ -3,7 +3,7 @@ discard """
|
|||
exitcode: 1
|
||||
"""
|
||||
|
||||
proc returnsNil(): string = return nil
|
||||
proc returnsNil(): ref int = return nil
|
||||
|
||||
iterator fields*(a, b: int): int =
|
||||
if a == b:
|
||||
|
|
@ -17,6 +17,6 @@ proc main(): string =
|
|||
result = ""
|
||||
for i in fields(0, 1):
|
||||
let x = returnsNil()
|
||||
result &= "string literal " & $x
|
||||
result &= "string literal " & $x[]
|
||||
|
||||
echo main()
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ proc `$`*(data: Tcommandline_results): string =
|
|||
|
||||
# - Parse code
|
||||
|
||||
template raise_or_quit(exception, message: expr): stmt {.immediate.} =
|
||||
template raise_or_quit(exception, message: untyped) =
|
||||
## Avoids repeating if check based on the default quit_on_failure variable.
|
||||
##
|
||||
## As a special case, if message has a zero length the call to quit won't
|
||||
|
|
@ -230,15 +230,15 @@ template run_custom_proc(parsed_parameter: Tparsed_parameter,
|
|||
##
|
||||
## Pass in the string of the parameter triggering the call. If the
|
||||
if not custom_validator.isNil:
|
||||
try:
|
||||
let message = custom_validator(parameter, parsed_parameter)
|
||||
if not message.isNil and message.len > 0:
|
||||
raise_or_quit(ValueError, ("Failed to validate value for " &
|
||||
"parameter $1:\n$2" % [escape(parameter), message]))
|
||||
except:
|
||||
raise_or_quit(ValueError, ("Couldn't run custom proc for " &
|
||||
"parameter $1:\n$2" % [escape(parameter),
|
||||
getCurrentExceptionMsg()]))
|
||||
let message = custom_validator(parameter, parsed_parameter)
|
||||
if not message.isNil and message.len > 0:
|
||||
raise_or_quit(ValueError, ("Failed to validate value for " &
|
||||
"parameter $1:\n$2" % [escape(parameter), message]))
|
||||
|
||||
|
||||
proc parse_parameter(quit_on_failure: bool, param, value: string,
|
||||
param_kind: Tparam_kind): Tparsed_parameter =
|
||||
|
|
|
|||
25
tests/system/tnilconcats.nim
Normal file
25
tests/system/tnilconcats.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
discard """
|
||||
output: '''@[nil, nil, nil, nil, nil, nil, nil, "meh"]'''
|
||||
exitcode: "0"
|
||||
"""
|
||||
|
||||
when true:
|
||||
var ab: string
|
||||
ab &= "more"
|
||||
|
||||
doAssert ab == "more"
|
||||
|
||||
var x: seq[string]
|
||||
|
||||
setLen(x, 7)
|
||||
|
||||
x.add "meh"
|
||||
|
||||
var s: string
|
||||
var z = "abc"
|
||||
var zz: string
|
||||
s &= "foo" & z & zz
|
||||
|
||||
doAssert s == "fooabc"
|
||||
|
||||
echo x
|
||||
|
|
@ -51,3 +51,59 @@ import strutils
|
|||
let arr = ['H','e','l','l','o',' ','W','o','r','l','d','!','\0']
|
||||
doAssert $arr == "['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!', '\\x00']"
|
||||
doAssert $cstring(unsafeAddr arr) == "Hello World!"
|
||||
|
||||
proc takes(c: cstring) =
|
||||
doAssert c == ""
|
||||
|
||||
proc testm() =
|
||||
var x: string
|
||||
# nil is mapped to "":
|
||||
takes(x)
|
||||
|
||||
testm()
|
||||
|
||||
# nil tests
|
||||
var xx: seq[string]
|
||||
var yy: string
|
||||
doAssert xx == @[]
|
||||
doAssert yy == ""
|
||||
|
||||
proc bar(arg: cstring): void =
|
||||
doAssert arg[0] == '\0'
|
||||
|
||||
proc baz(arg: openarray[char]): void =
|
||||
doAssert arg.len == 0
|
||||
|
||||
proc stringCompare(): void =
|
||||
var a,b,c,d,e,f,g: string
|
||||
a.add 'a'
|
||||
doAssert a == "a"
|
||||
b.add "bee"
|
||||
doAssert b == "bee"
|
||||
b.add g
|
||||
doAssert b == "bee"
|
||||
c.add 123.456
|
||||
doAssert c == "123.456"
|
||||
d.add 123456
|
||||
doAssert d == "123456"
|
||||
|
||||
doAssert e == ""
|
||||
doAssert "" == e
|
||||
doAssert nil == e
|
||||
doAssert e == nil
|
||||
doAssert f == g
|
||||
doAssert "" == ""
|
||||
doAssert "" == nil
|
||||
doAssert nil == ""
|
||||
|
||||
g.setLen(10)
|
||||
doAssert g == "\0\0\0\0\0\0\0\0\0\0"
|
||||
doAssert "" != "\0\0\0\0\0\0\0\0\0\0"
|
||||
|
||||
var nilstring: string
|
||||
bar(nilstring)
|
||||
baz(nilstring)
|
||||
|
||||
stringCompare()
|
||||
static:
|
||||
stringCompare()
|
||||
18
tests/typerel/t7600_1.nim
Normal file
18
tests/typerel/t7600_1.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
discard """
|
||||
errormsg: "type mismatch: got <Thin[system.int]>"
|
||||
nimout: '''t7600_1.nim(18, 6) Error: type mismatch: got <Thin[system.int]>
|
||||
but expected one of:
|
||||
proc test[T](x: Paper[T])
|
||||
|
||||
expression: test tn'''
|
||||
"""
|
||||
|
||||
type
|
||||
Paper[T] = ref object of RootObj
|
||||
thickness: T
|
||||
Thin[T] = object of Paper[T]
|
||||
|
||||
proc test[T](x: Paper[T]) = discard
|
||||
|
||||
var tn = Thin[int]()
|
||||
test tn
|
||||
17
tests/typerel/t7600_2.nim
Normal file
17
tests/typerel/t7600_2.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
errormsg: "type mismatch: got <Thin>"
|
||||
nimout: '''t7600_2.nim(17, 6) Error: type mismatch: got <Thin>
|
||||
but expected one of:
|
||||
proc test(x: Paper)
|
||||
|
||||
expression: test tn'''
|
||||
"""
|
||||
|
||||
type
|
||||
Paper = ref object of RootObj
|
||||
Thin = object of Paper
|
||||
|
||||
proc test(x: Paper) = discard
|
||||
|
||||
var tn = Thin()
|
||||
test tn
|
||||
Loading…
Add table
Add a link
Reference in a new issue