some test cleanups & category reorganization (#22010)

* clean up some test categories

* mention exact slice issue

* magics into system

* move trangechecks into overflow

* move tmemory to system

* try fix CI

* try fix CI

* final CI fix
This commit is contained in:
metagn
2023-06-06 07:54:07 +03:00
committed by GitHub
parent 2ab948ce53
commit b97d603cd0
134 changed files with 189 additions and 374 deletions

View File

@@ -1,7 +0,0 @@
proc fooBar4*(a: int) = discard
var fooBar9* = 0
var fooCar* = 0
type FooBar* = int
type FooCar* = int
type GooBa* = int

View File

@@ -1,19 +0,0 @@
discard """
output: '''
1
2
'''
"""
proc p(a, b: int, c: proc ()) =
c()
when false:
# language spec changed:
p(1, 3):
echo 1
echo 3
p(1, 1, proc() =
echo 1
echo 2)

View File

@@ -1,15 +0,0 @@
discard """
output: "509"
"""
# Test the new ``emit`` pragma:
{.emit: """
static int cvariable = 420;
""".}
proc embedsC() =
var nimVar = 89
{.emit: """printf("%d\n", cvariable + (int)`nimVar`);""".}
embedsC()

View File

@@ -1,6 +0,0 @@
discard """
output: "\n"
"""
echo()

View File

@@ -1,6 +0,0 @@
discard """
cmd: "nim c --gc:regions $file"
"""
# issue #12597
# it just tests that --gc:regions compiles. Nothing else. :'(

View File

@@ -1,31 +0,0 @@
discard """
errormsg: "cannot instantiate T2"
file: "tgenconstraints.nim"
line: 25
disabled: true
"""
type
T1[T: int|string] = object
x: T
T2[T: Ordinal] = object
x: T
var x1: T1[int]
var x2: T1[string]
var x3: T2[int]
proc foo[T](x: T): T2[T] {.discardable.} =
var o: T1[T]
foo(10)
# XXX: allow type intersections in situation like this
proc bar(x: int|TNumber): T1[type(x)] {.discardable.} =
when type(x) is TNumber:
var o: T2[type(x)]
bar "test"
bar 100
bar 1.1

View File

@@ -1,4 +0,0 @@
discard """
matrix: "--hints:off"
"""
doAssert true

View File

@@ -1,31 +0,0 @@
type
Hash*[bits: static[int]] = object
data*: array[bits div 8, uint8]
{.emit: """
void sha_256(void* input, int input_len, void* output, int output_len) {}
void sha_512(void* input, int input_len, void* output, int output_len) {}
void keccak_256(void* input, int input_len, void* output, int output_len) {}
void keccak_512(void* input, int input_len, void* output, int output_len) {}
""".}
template defineKeccak(bits: untyped) =
proc `extKeccak bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "keccak_" & astToStr(bits).}
template defineSha(bits: static[int]) =
proc `extSha bits`(output: pointer, outSize: csize_t, input: pointer, inputSize: csize_t) {.nodecl, importc: "sha_" & astToStr(bits).}
template defineHashProcs(bits) =
defineSha(bits)
defineKeccak(bits)
defineHashProcs(256)
defineHashProcs(512)
extSha256(nil, 0, nil, 0)
extSha512(nil, 0, nil, 0)
extKeccak256(nil, 0, nil, 0)
extKeccak512(nil, 0, nil, 0)

View File

@@ -1,8 +0,0 @@
discard """
errormsg: "type mismatch: got <int>"
file: "tinc.nim"
line: 8
"""
var x = 0
inc(x+1)

View File

@@ -1,97 +0,0 @@
discard """
matrix: "; --backend:js --jsbigint64:off; --backend:js --jsbigint64:on"
output: '''
0 0
0 0
Success'''
"""
# Test the different integer operations
import std/private/jsutils
var testNumber = 0
template test(opr, a, b, c: untyped): untyped =
# test the expression at compile and runtime
block:
const constExpr = opr(a, b)
when constExpr != c:
{.error: "Test failed " & $constExpr & " " & $c.}
inc(testNumber)
#Echo("Test: " & $testNumber)
var aa = a
var bb = b
var varExpr = opr(aa, bb)
assert(varExpr == c)
test(`+`, 12'i8, -13'i16, -1'i16)
test(`shl`, 0b11, 0b100, 0b110000)
whenJsNoBigInt64: discard
do:
test(`shl`, 0b11'i64, 0b100'i64, 0b110000'i64)
when not defined(js):
# mixed type shr needlessly complicates codegen with bigint
# and thus is not yet supported in JS for 64 bit ints
test(`shl`, 0b11'i32, 0b100'i64, 0b110000'i64)
test(`shl`, 0b11'i32, 0b100'i32, 0b110000'i32)
test(`or`, 0xf0f0'i16, 0x0d0d'i16, 0xfdfd'i16)
test(`and`, 0xf0f0'i16, 0xfdfd'i16, 0xf0f0'i16)
whenJsNoBigInt64: discard
do:
test(`shr`, 0xffffffffffffffff'i64, 0x4'i64, 0xffffffffffffffff'i64)
test(`shr`, 0xffff'i16, 0x4'i16, 0xffff'i16)
test(`shr`, 0xff'i8, 0x4'i8, 0xff'i8)
whenJsNoBigInt64: discard
do:
test(`shr`, 0xffffffff'i64, 0x4'i64, 0x0fffffff'i64)
test(`shr`, 0xffffffff'i32, 0x4'i32, 0xffffffff'i32)
whenJsNoBigInt64: discard
do:
test(`shl`, 0xffffffffffffffff'i64, 0x4'i64, 0xfffffffffffffff0'i64)
test(`shl`, 0xffff'i16, 0x4'i16, 0xfff0'i16)
test(`shl`, 0xff'i8, 0x4'i8, 0xf0'i8)
whenJsNoBigInt64: discard
do:
test(`shl`, 0xffffffff'i64, 0x4'i64, 0xffffffff0'i64)
test(`shl`, 0xffffffff'i32, 0x4'i32, 0xfffffff0'i32)
# bug #916
proc unc(a: float): float =
return a
echo int(unc(0.5)), " ", int(unc(-0.5))
echo int(0.5), " ", int(-0.5)
block: # Casts to uint
template testCast(fromValue: typed, toType: typed, expectedResult: typed) =
let src = fromValue
let dst = cast[toType](src)
if dst != expectedResult:
echo "Casting ", astToStr(fromValue), " to ", astToStr(toType), " = ", dst.int, " instead of ", astToStr(expectedResult)
doAssert(dst == expectedResult)
testCast(-1'i16, uint16, 0xffff'u16)
testCast(0xffff'u16, int16, -1'i16)
testCast(0xff'u16, uint8, 0xff'u8)
testCast(0xffff'u16, uint8, 0xff'u8)
testCast(-1'i16, uint32, 0xffffffff'u32)
testCast(0xffffffff'u32, int32, -1)
testCast(0xfffffffe'u32, int32, -2'i32)
testCast(0xffffff'u32, int16, -1'i32)
testCast(-5'i32, uint8, 251'u8)
# issue #7174
let c = 1'u
let val = c > 0
doAssert val
echo("Success") #OUT Success

View File

@@ -1,21 +0,0 @@
discard """
errormsg: "index 2 not in 0 .. 1"
line: 18
"""
block:
try:
let a = @[1,2]
echo a[3]
except Exception as e:
doAssert e.msg == "index 3 not in 0 .. 1"
# note: this is not being tested, because the CT error happens before
block:
type TTestArr = array[0..1, int16]
var f: TTestArr
f[0] = 30
f[1] = 40
f[2] = 50
f[3] = 60
echo(repr(f))

View File

@@ -1,10 +0,0 @@
discard """
errormsg: "index 3 not in 0 .. 1"
line: 9
"""
# Note: merge in tinvalidarrayaccess.nim pending https://github.com/nim-lang/Nim/issues/9906
let a = [1,2]
echo a[3]

View File

@@ -1,78 +0,0 @@
discard """
output: '''
issue #11812
issue #10899
123
issue #11367
event consumed!
'''
"""
echo "issue #11812"
proc run(a: proc()) = a()
proc main() =
var test: int
run(proc() = test = 0)
run do:
test = 0
main()
echo "issue #10899"
proc foo(x: proc {.closure.}) =
x()
proc bar =
var x = 123
# foo proc = echo x #[ ok ]#
foo: echo x #[ SIGSEGV: Illegal storage access. (Attempt to read from nil?) ]#
bar()
echo "issue #11367"
type
EventCB = proc()
Emitter = object
cb: EventCB
Subscriber = object
discard
proc newEmitter(): Emitter =
result
proc on_event(self: var Emitter, cb: EventCB) =
self.cb = cb
proc emit(self: Emitter) =
self.cb()
proc newSubscriber(): Subscriber =
result
proc consume(self: Subscriber) =
echo "event consumed!"
proc main2() =
var emitter = newEmitter()
var subscriber = newSubscriber()
proc foo() =
subscriber.consume()
emitter.on_event() do ():
subscriber.consume()
# this works
# emitter.on_event(foo)
emitter.emit()
main2()

View File

@@ -1,76 +0,0 @@
discard """
matrix: "--mm:refc; --mm:orc"
output: '''(x: "string here", a: 1)
b is 5
x is 12'''
"""
proc simple[T](a: T) =
var
x = "string here"
echo locals()
simple(1)
type Foo2[T]=object
a2: T
proc numFields*(T: typedesc[tuple|object]): int=
var t:T
for _ in t.fields: inc result
proc test(baz: int, qux: var int): int =
var foo: Foo2[int]
let bar = "abc"
let c1 = locals()
doAssert numFields(c1.foo.type) == 1
doAssert c1.bar == "abc"
doAssert c1.baz == 123
doAssert c1.result == 0
doAssert c1.qux == 456
var x1 = 456
discard test(123, x1)
# bug #11958
proc foo() =
var a = 5
proc bar() {.nimcall.} =
var b = 5
for k, v in fieldpairs(locals()):
echo k, " is ", v
bar()
foo()
proc foo2() =
var a = 5
proc bar2() {.nimcall.} =
for k, v in fieldpairs(locals()):
echo k, " is ", v
bar2()
foo2()
proc foo3[T](y: T) =
var a = 5
proc bar2[T](x: T) {.nimcall.} =
for k, v in fieldpairs(locals()):
echo k, " is ", v
bar2(y)
foo3(12)
block: # bug #12682
template foo(): untyped =
var c1 = locals()
1
proc testAll()=
doAssert foo() == 1
let c2=locals()
testAll()

View File

@@ -1,32 +0,0 @@
discard """
action: run
output: '''
18446744073709551615
9223372036854775807
4294967295
0
0
'''
"""
var x: range[-1'f32..1'f32]
doAssert x.low == -1'f32
doAssert x.high == 1'f32
doAssert x.type.low == -1'f32
doAssert x.type.high == 1'f32
var y: range[-1'f64..1'f64]
doAssert y.low == -1'f64
doAssert y.high == 1'f64
doAssert y.type.low == -1'f64
doAssert y.type.high == 1'f64
# bug #11972
var num: uint8
doAssert num.high.float == 255.0
echo high(uint64)
echo high(int64)
echo high(uint32)
echo low(uint64)
echo low(uint32)

View File

@@ -1,59 +0,0 @@
discard """
matrix: "--mm:refc"
outputsub: '''
Simple tree node allocation worked!
Simple cycle allocation worked!
'''
joinable: false
"""
# Test the implementation of the new operator
# and the code generation for gc walkers
# (and the garbage collector):
## todo fixme it doesn't work for ORC
type
PNode = ref TNode
TNode = object
data: int
str: string
le, ri: PNode
TStressTest = ref array[0..45, array[1..45, TNode]]
proc finalizer(n: PNode) =
write(stdout, n.data)
write(stdout, " is now freed\n")
proc newNode(data: int, le, ri: PNode): PNode =
new(result, finalizer)
result.le = le
result.ri = ri
result.data = data
# now loop and build a tree
proc main() =
var
i = 0
p: TStressTest
while i < 1000:
var n: PNode
n = newNode(i, nil, newNode(i + 10000, nil, nil))
inc(i)
new(p)
write(stdout, "Simple tree node allocation worked!\n")
i = 0
while i < 1000:
var m = newNode(i + 20000, nil, nil)
var k = newNode(i + 30000, nil, nil)
m.le = m
m.ri = k
k.le = m
k.ri = k
inc(i)
write(stdout, "Simple cycle allocation worked!\n")
main()

View File

@@ -1,11 +0,0 @@
discard """
output: 3
"""
var x: ref int
new(x)
x[] = 3
echo x[]

View File

@@ -1,6 +0,0 @@
# new test for sets:
const elem = ' '
var s: set[char] = {elem}
assert(elem in s and 'a' not_in s and 'c' not_in s )

View File

@@ -1,12 +0,0 @@
discard """
nimout: '''
found 'a' [var declared in tnoop.nim(10, 3)]
'''
file: "tnoop.nim"
errormsg: "attempting to call routine: 'a'"
"""
var
a: int
a()

View File

@@ -1,19 +0,0 @@
discard """
errormsg: "type mismatch"
file: "tnot.nim"
line: 14
"""
# BUG: following compiles, but should not:
proc nodeOfDegree(x: int): bool =
result = false
proc main =
for j in 0..2:
for i in 0..10:
if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch
echo "Yes"
else:
echo "No"
main()

View File

@@ -1,120 +0,0 @@
discard """
output: '''
@[1, 2, 3]@[1, 2, 3]
a
a
1
3 is an int
2 is an int
miau is a string
f1 1 1 1
f1 2 3 3
f1 10 20 30
f2 100 100 100
f2 200 300 300
f2 300 400 400
f3 10 10 20
f3 10 15 25
true true
false true
world
typedescDefault
'''
"""
template reject(x) =
assert(not compiles(x))
block:
# https://github.com/nim-lang/Nim/issues/7756
proc foo[T](x: seq[T], y: seq[T] = x) =
echo x, y
let a = @[1, 2, 3]
foo(a)
block:
# https://github.com/nim-lang/Nim/issues/1201
proc issue1201(x: char|int = 'a') = echo x
issue1201()
issue1201('a')
issue1201(1)
# https://github.com/nim-lang/Nim/issues/7000
proc test(a: int|string = 2) =
when a is int:
echo a, " is an int"
elif a is string:
echo a, " is a string"
test(3) # works
test() # works
test("miau")
block:
# https://github.com/nim-lang/Nim/issues/3002 and similar
proc f1(a: int, b = a, c = b) =
echo "f1 ", a, " ", b, " ", c
proc f2(a: int, b = a, c: int = b) =
echo "f2 ", a, " ", b, " ", c
proc f3(a: int, b = a, c = a + b) =
echo "f3 ", a, " ", b, " ", c
f1 1
f1(2, 3)
f1 10, 20, 30
100.f2
200.f2 300
300.f2(400)
10.f3()
10.f3(15)
reject:
# This is a type mismatch error:
proc f4(a: int, b = a, c: float = b) = discard
reject:
# undeclared identifier
proc f5(a: int, b = c, c = 10) = discard
reject:
# undeclared identifier
proc f6(a: int, b = b) = discard
reject:
# undeclared identifier
proc f7(a = a) = discard
block:
proc f(a: var int, b: ptr int, c = addr(a)) =
echo addr(a) == b, " ", b == c
var x = 10
f(x, addr(x))
f(x, nil, nil)
block:
# https://github.com/nim-lang/Nim/issues/1046
proc pySubstr(s: string, start: int, endd = s.len()): string =
var
revStart = start
revEnd = endd
if start < 0:
revStart = s.len() + start
if endd < 0:
revEnd = s.len() + endd
return s[revStart .. revEnd-1]
echo pySubstr("Hello world", -5)
# bug #11660
func typedescDefault(T: typedesc; arg: T = 0) = debugEcho "typedescDefault"
typedescDefault(int)

View File

@@ -1,18 +0,0 @@
discard """
joinable: false
"""
{.warningAsError[ProveInit]:on.}
template main() =
proc fn(): var int =
discard
discard fn()
doAssert not compiles(main())
# bug #9901
import std/[sequtils, times]
proc parseMyDates(line: string): DateTime =
result = parse(line, "yyyy-MM-dd")
var dateStrings = @["2018-12-01", "2018-12-02", "2018-12-03"]
var parsed = dateStrings.map(parseMyDates)
discard parsed

View File

@@ -1,48 +0,0 @@
discard """
output: '''10
10
1
1
true'''
"""
# bug #1344
var expected: int
var x: range[1..10] = 10
try:
x += 1
echo x
except OverflowDefect, RangeDefect:
expected += 1
echo x
try:
inc x
echo x
except OverflowDefect, RangeDefect:
expected += 1
echo x
x = 1
try:
x -= 1
echo x
except OverflowDefect, RangeDefect:
expected += 1
echo x
try:
dec x
echo x
except OverflowDefect, RangeDefect:
expected += 1
echo x
echo expected == 4
# bug #13698
var
x45 = "hello".cstring
p = x45.len.int32

View File

@@ -1,10 +0,0 @@
discard """
errormsg: "closing \" expected"
file: "trawstr.nim"
line: 10
"""
# Test the new raw strings:
const
xxx = r"This is a raw string!"
yyy = "This not\" #ERROR

View File

@@ -1,21 +0,0 @@
discard """
output: '''
test the improved readline handling that does not care whether its
Macintosh, Unix or Windows text format.
'''
"""
# test the improved readline handling that does not care whether its
# Macintosh, Unix or Windows text format.
var
inp: File
line: string
if open(inp, "tests/misc/treadln.nim"):
while not endOfFile(inp):
line = readLine(inp)
if line.len >= 2 and line[0] == '#' and line[1] == ' ':
echo line[2..^1]
close(inp)

View File

@@ -1,39 +0,0 @@
discard """
targets: "c cpp"
"""
import macros
macro make_test_type(idents: varargs[untyped]): untyped =
result = nnkStmtList.newTree()
var ident_defs: seq[NimNode] = @[]
for i in idents:
ident_defs.add newIdentDefs(i, ident("int"))
result.add newTree(nnkTypeSection,
newTree(nnkTypeDef,
ident("TestType"),
newEmptyNode(),
newTree(nnkObjectTy,
newEmptyNode(),
newEmptyNode(),
newTree(nnkRecList,
ident_defs
)
)
)
)
make_test_type(
auto, bool, catch, char, class, compl, const_cast, default, delete, double,
dynamic_cast, explicit, extern, false, float, friend, goto, int, long,
mutable, namespace, new, operator, private, protected, public, register,
reinterpret_cast, restrict, short, signed, sizeof, static_cast, struct, switch,
this, throw, true, typedef, typeid, typeof, typename, union, packed, unsigned,
virtual, void, volatile, wchar_t, alignas, alignof, constexpr, decltype, nullptr,
noexcept, thread_local, static_assert, char16_t, char32_t
)
# Make sure the type makes it to codegen.
var test_instance: TestType

View File

@@ -1,27 +0,0 @@
# test for https://github.com/nim-lang/RFCs/issues/341
import std/json
import std/jsonutils
import std/macros
macro fn1(a: untyped): string = newLit a.lispRepr
doAssert fn1(a.?b.c) == """(DotExpr (Infix (Ident ".?") (Ident "a") (Ident "b")) (Ident "c"))"""
template `.?`(a: JsonNode, b: untyped{ident}): JsonNode =
a[astToStr(b)]
proc identity[T](a: T): T = a
proc timesTwo[T](a: T): T = a * 2
template main =
let a = (a1: 1, a2: "abc", a3: (a4: 2.5))
let j = a.toJson
doAssert j.?a1.getInt == 1
doAssert j.?a3.?a4.getFloat == 2.5
doAssert j.?a3.?a4.getFloat.timesTwo == 5.0
doAssert j.?a3.identity.?a4.getFloat.timesTwo == 5.0
doAssert j.identity.?a3.identity.?a4.identity.getFloat.timesTwo == 5.0
doAssert j.identity.?a3.?a4.identity.getFloat.timesTwo == 5.0
static: main()
main()

View File

@@ -404,7 +404,7 @@ running: v2
block: # UnusedImport
proc fn(opt: string, expected: string) =
let output = runNimCmdChk("pragmas/mused3.nim", fmt"--warning:all:off --warning:UnusedImport --hint:DuplicateModuleImport {opt}")
let output = runNimCmdChk("msgs/mused3.nim", fmt"--warning:all:off --warning:UnusedImport --hint:DuplicateModuleImport {opt}")
doAssert output == expected, opt & "\noutput:\n" & output & "expected:\n" & expected
fn("-d:case1"): """
mused3.nim(13, 8) Warning: imported and not used: 'mused3b' [UnusedImport]

View File

@@ -1,10 +0,0 @@
discard """
errormsg: "type mismatch: got <bool> but expected \'string\'"
file: "tsimtych.nim"
line: 10
"""
# Test 2
# Simple type checking
var a: string
a = false #ERROR

View File

@@ -1,59 +0,0 @@
discard """
output: '''
456456
456456
456456
Zugr5nd
egerichtetd
verichtetd
'''
"""
# Test the new slices.
var mystr = "Abgrund"
# mystr[..1] = "Zu" # deprecated
mystr[0..1] = "Zu"
mystr[4..4] = "5"
type
TEnum = enum e1, e2, e3, e4, e5, e6
var myarr: array[TEnum, int] = [1, 2, 3, 4, 5, 6]
myarr[e1..e3] = myarr[e4..e6]
# myarr[..e3] = myarr[e4..e6] # deprecated
myarr[0..e3] = myarr[e4..e6]
for x in items(myarr): stdout.write(x)
echo()
var myarr2: array[0..5, int] = [1, 2, 3, 4, 5, 6]
myarr2[0..2] = myarr2[3..5]
for x in items(myarr2): stdout.write(x)
echo()
var myseq = @[1, 2, 3, 4, 5, 6]
myseq[0..2] = myseq[^3 .. ^1]
for x in items(myseq): stdout.write(x)
echo()
echo mystr
mystr[4..4] = "u"
# test full replacement
# mystr[.. ^2] = "egerichtet" # deprecated
mystr[0 .. ^2] = "egerichtet"
echo mystr
mystr[0..2] = "ve"
echo mystr
var s = "abcdef"
s[1 .. ^2] = "xyz"
assert s == "axyzf"

View File

@@ -1,45 +0,0 @@
discard """
matrix: "--spellsuggest:15 --hints:off"
action: "reject"
nimout: '''
tspellsuggest.nim(45, 13) Error: undeclared identifier: 'fooBar'
candidates (edit distance, scope distance); see '--spellSuggest':
(1, 0): 'fooBar8'
(1, 1): 'fooBar7'
(1, 3): 'fooBar1'
(1, 3): 'fooBar2'
(1, 3): 'fooBar3'
(1, 3): 'fooBar4'
(1, 3): 'fooBar5'
(1, 3): 'fooBar6'
(1, 5): 'FooBar'
(1, 5): 'fooBar4'
(1, 5): 'fooBar9'
(1, 5): 'fooCar'
(2, 5): 'FooCar'
(2, 5): 'GooBa'
(3, 0): 'fooBarBaz'
'''
"""
# tests `--spellsuggest:num`
# line 30
import ./mspellsuggest
var fooBar1 = 0
let fooBar2 = 0
const fooBar3 = 0
proc fooBar4() = discard
template fooBar5() = discard
macro fooBar6() = discard
proc main =
var fooBar7 = 0
block:
var fooBar8 = 0
const fooBarBaz = 0
let x = fooBar

View File

@@ -1,45 +0,0 @@
discard """
matrix: "--spellsuggest:12 --hints:off"
action: "reject"
nimout: '''
tspellsuggest2.nim(45, 13) Error: undeclared identifier: 'fooBar'
candidates (edit distance, scope distance); see '--spellSuggest':
(1, 0): 'fooBar8'
(1, 1): 'fooBar7'
(1, 3): 'fooBar1'
(1, 3): 'fooBar2'
(1, 3): 'fooBar3'
(1, 3): 'fooBar4'
(1, 3): 'fooBar5'
(1, 3): 'fooBar6'
(1, 5): 'FooBar'
(1, 5): 'fooBar4'
(1, 5): 'fooBar9'
(1, 5): 'fooCar'
'''
"""
# tests `--spellsuggest`
# line 30
import ./mspellsuggest
var fooBar1 = 0
let fooBar2 = 0
const fooBar3 = 0
proc fooBar4() = discard
template fooBar5() = discard
macro fooBar6() = discard
proc main =
var fooBar7 = 0
block:
var fooBar8 = 0
const fooBarBaz = 0
let x = fooBar

View File

@@ -1,21 +0,0 @@
discard """
matrix: "--spellsuggest:4 --hints:off"
action: "reject"
nimout: '''
tspellsuggest3.nim(21, 1) Error: undeclared identifier: 'fooBar'
candidates (edit distance, scope distance); see '--spellSuggest':
(1, 2): 'FooBar'
(1, 2): 'fooBar4'
(1, 2): 'fooBar9'
(1, 2): 'fooCar'
'''
"""
import ./mspellsuggest
import ./mspellsuggest
import ./mspellsuggest
import ./mspellsuggest
fooBar

View File

@@ -1,20 +0,0 @@
discard """
targets: "c cpp js"
"""
import std/strtabs
proc fun()=
let ret = newStringTable(modeCaseSensitive)
ret["foo"] = "bar"
doAssert $ret == "{foo: bar}"
let b = ret["foo"]
doAssert b == "bar"
proc main()=
static: fun()
fun()
main()

View File

@@ -1,24 +0,0 @@
# bug #1638
let v1 = 7
let v2 = 7'u64
let t1 = v1 mod 2 # works
let t2 = 7'u64 mod 2'u64 # works
let t3 = v2 mod 2'u64 # Error: invalid type: 'range 0..1(uint64)
let t4 = (v2 mod 2'u64).uint64 # works
# bug #2550
var x: uint # doesn't work
doAssert x mod 2 == 0
var y: uint64 # doesn't work
doAssert y mod 2 == 0
var z: uint32 # works
doAssert z mod 2 == 0
var a: int # works
doAssert a mod 2 == 0

View File

@@ -1,43 +0,0 @@
discard """
output: '''true
true
true
5
4
3
2
1
0
it should stop now
18446744073709551615
4294967295
'''
"""
# bug 1420
var x = 40'u32
var y = 30'u32
echo x > y # works
echo((40'i32) > (30'i32))
echo((40'u32) > (30'u32)) # Error: ordinal type expected
# bug #4220
const count: uint = 5
var stop_me = false
for i in countdown(count, 0):
echo i
if stop_me: break
if i == 0:
echo "it should stop now"
stop_me = true
# bug #3985
const
HIGHEST_64BIT_UINT = 0xFFFFFFFFFFFFFFFF'u
HIGHEST_32BIT_UINT = 0xFFFFFFFF'u
echo($HIGHEST_64BIT_UINT)
echo($HIGHEST_32BIT_UINT)

View File

@@ -1,136 +0,0 @@
discard """
output: ''''''
disabled: "true"
"""
# All operations involving uint64 are commented out
# as they're not yet supported.
# All other operations are handled by implicit conversions from uints to ints
# uint64 could be supported but would need special implementation of the operators
# unsigned < signed
doAssert 10'u8 < 20'i8
doAssert 10'u8 < 20'i16
doAssert 10'u8 < 20'i32
doAssert 10'u8 < 20'i64
doAssert 10'u16 < 20'i8
doAssert 10'u16 < 20'i16
doAssert 10'u16 < 20'i32
doAssert 10'u16 < 20'i64
doAssert 10'u32 < 20'i8
doAssert 10'u32 < 20'i16
doAssert 10'u32 < 20'i32
doAssert 10'u32 < 20'i64
# doAssert 10'u64 < 20'i8
# doAssert 10'u64 < 20'i16
# doAssert 10'u64 < 20'i32
# doAssert 10'u64 < 20'i64
# signed < unsigned
doAssert 10'i8 < 20'u8
doAssert 10'i8 < 20'u16
doAssert 10'i8 < 20'u32
# doAssert 10'i8 < 20'u64
doAssert 10'i16 < 20'u8
doAssert 10'i16 < 20'u16
doAssert 10'i16 < 20'u32
# doAssert 10'i16 < 20'u64
doAssert 10'i32 < 20'u8
doAssert 10'i32 < 20'u16
doAssert 10'i32 < 20'u32
# doAssert 10'i32 < 20'u64
doAssert 10'i64 < 20'u8
doAssert 10'i64 < 20'u16
doAssert 10'i64 < 20'u32
# doAssert 10'i64 < 20'u64
# unsigned <= signed
doAssert 10'u8 <= 20'i8
doAssert 10'u8 <= 20'i16
doAssert 10'u8 <= 20'i32
doAssert 10'u8 <= 20'i64
doAssert 10'u16 <= 20'i8
doAssert 10'u16 <= 20'i16
doAssert 10'u16 <= 20'i32
doAssert 10'u16 <= 20'i64
doAssert 10'u32 <= 20'i8
doAssert 10'u32 <= 20'i16
doAssert 10'u32 <= 20'i32
doAssert 10'u32 <= 20'i64
# doAssert 10'u64 <= 20'i8
# doAssert 10'u64 <= 20'i16
# doAssert 10'u64 <= 20'i32
# doAssert 10'u64 <= 20'i64
# signed <= unsigned
doAssert 10'i8 <= 20'u8
doAssert 10'i8 <= 20'u16
doAssert 10'i8 <= 20'u32
# doAssert 10'i8 <= 20'u64
doAssert 10'i16 <= 20'u8
doAssert 10'i16 <= 20'u16
doAssert 10'i16 <= 20'u32
# doAssert 10'i16 <= 20'u64
doAssert 10'i32 <= 20'u8
doAssert 10'i32 <= 20'u16
doAssert 10'i32 <= 20'u32
# doAssert 10'i32 <= 20'u64
doAssert 10'i64 <= 20'u8
doAssert 10'i64 <= 20'u16
doAssert 10'i64 <= 20'u32
# doAssert 10'i64 <= 20'u64
# signed == unsigned
doAssert 10'i8 == 10'u8
doAssert 10'i8 == 10'u16
doAssert 10'i8 == 10'u32
# doAssert 10'i8 == 10'u64
doAssert 10'i16 == 10'u8
doAssert 10'i16 == 10'u16
doAssert 10'i16 == 10'u32
# doAssert 10'i16 == 10'u64
doAssert 10'i32 == 10'u8
doAssert 10'i32 == 10'u16
doAssert 10'i32 == 10'u32
# doAssert 10'i32 == 10'u64
doAssert 10'i64 == 10'u8
doAssert 10'i64 == 10'u16
doAssert 10'i64 == 10'u32
# doAssert 10'i64 == 10'u64
# unsigned == signed
doAssert 10'u8 == 10'i8
doAssert 10'u8 == 10'i16
doAssert 10'u8 == 10'i32
# doAssert 10'u8 == 10'i64
doAssert 10'u16 == 10'i8
doAssert 10'u16 == 10'i16
doAssert 10'u16 == 10'i32
# doAssert 10'u16 == 10'i64
doAssert 10'u32 == 10'i8
doAssert 10'u32 == 10'i16
doAssert 10'u32 == 10'i32
# doAssert 10'u32 == 10'i64
# doAssert 10'u64 == 10'i8
# doAssert 10'u64 == 10'i16
# doAssert 10'u64 == 10'i32
# doAssert 10'u64 == 10'i64

View File

@@ -1,97 +0,0 @@
# Tests unsigned literals and implicit conversion between uints and ints
var h8:uint8 = 128
var h16:uint16 = 32768
var h32:uint32 = 2147483648'u32
var h64:uint64 = 9223372036854775808'u64
var foobar:uint64 = 9223372036854775813'u64 # Issue 728
var v8:uint8 = 10
var v16:uint16 = 10
var v32:uint32 = 10
var v64:uint64 = 10
# u8 + literal produces u8:
var a8: uint8 = v8 + 10
var a16: uint16 = v16 + 10
when false:
var d8 = v8 + 10'i8
var d16 = v8 + 10'i16
var d32 = v8 + 10'i32
when false:
# these don't work yet because unsigned.nim is stupid. XXX We need to fix this.
var f8 = v16 + 10'u8
var f16 = v16 + 10'u16
var f32 = v16 + 10'u32
var g8 = v32 + 10'u8
var g16 = v32 + 10'u16
var g32 = v32 + 10'u32
var ar: array[0..20, int]
var n8 = ar[v8]
var n16 = ar[v16]
var n32 = ar[v32]
var n64 = ar[v64]
block t4176:
var yyy: uint8 = 0
yyy = yyy - 127
doAssert type(yyy) is uint8
# bug #13661
proc fun(): uint = cast[uint](-1)
const x0 = fun()
doAssert typeof(x0) is uint
discard $x0
# bug #13671
const x1 = cast[uint](-1)
discard $(x1,)
# bug #13698
let n2: csize_t = 1
doAssert $n2.int32 == "1"
# bug #14616
let limit = 1'u64
let rangeVar = 0'u64 ..< limit
when not defined(gcRefc):
doAssert repr(rangeVar) == """0 .. 0""", repr(rangeVar)
# bug #15210
let a3 = not 0'u64
var success = false
try:
discard a3.int64
except RangeDefect:
success = true
doAssert success, "conversion should fail at runtime"
template main() =
# xxx move all tests under here so it gets tested in CT and RT
block: # bug #17572
type T = distinct uint64
func f(x: uint64): auto =
let a = T(x)
(x, a.uint64)
const x = 1'u64 shl 63 or 7
const b = T(x)
doAssert b.uint64 == 9223372036854775815'u64
doAssert $b.uint64 == "9223372036854775815"
doAssert f(x) == (9223372036854775815'u64, 9223372036854775815'u64)
static: main()
main()

View File

@@ -1,34 +0,0 @@
block: # bug #2427
var x = 0'u8
dec x # OverflowDefect
x -= 1 # OverflowDefect
x = x - 1 # No error
doAssert(x == 253'u8)
block:
var x = 130'u8
x += 130'u8
doAssert(x == 4'u8)
block:
var x = 40000'u16
x = x + 40000'u16
doAssert(x == 14464'u16)
block:
var x = 4000000000'u32
x = x + 4000000000'u32
doAssert(x == 3705032704'u32)
block:
var x = 123'u16
x -= 125
doAssert(x == 65534'u16)
block t4175:
let i = 0u - 1u
const j = 0u - 1u
doAssert i == j
doAssert j + 1u == 0u

View File

@@ -1,66 +0,0 @@
discard """
errormsg: "number out of range: '0x123'u8'"
"""
# Bug #1179
# Unsigneds
# 8 bit
let ref1 = 128'u8 shr 7
let hex1 = 0x80'u8 shr 7
let oct1 = 0o200'u8 shr 7
let dig1 = 0b10000000'u8 shr 7
doAssert(ref1 == 1)
doAssert(ref1 == hex1)
doAssert(ref1 == oct1)
doAssert(ref1 == dig1)
# 16 bit
let ref2 = 32768'u16 shr 15
let hex2 = 0x8000'u16 shr 15
let oct2 = 0o100000'u16 shr 15
let dig2 = 0b1000000000000000'u16 shr 15
doAssert(ref2 == 1)
doAssert(ref2 == hex2)
doAssert(ref2 == oct2)
doAssert(ref2 == dig2)
# 32 bit
let ref3 = 2147483648'u32 shr 31
let hex3 = 0x80000000'u32 shr 31
let oct3 = 0o20000000000'u32 shr 31
let dig3 = 0b10000000000000000000000000000000'u32 shr 31
doAssert(ref3 == 1)
doAssert(ref3 == hex3)
doAssert(ref3 == oct3)
doAssert(ref3 == dig3)
# Below doesn't work for lexer stage errors...
# doAssert(compiles(0xFF'u8) == true)
# doAssert(compiles(0xFFF'u16) == true)
# doAssert(compiles(0x7FFF'i16) == true)
# doAssert(compiles(0x123'u8) == false)
# doAssert(compiles(0x123'i8) == false)
# doAssert(compiles(0x123123'u16) == false)
# doAssert(compiles(0x123123'i16) == false)
# Should compile #
let boundOkHex1 = 0xFF'u8
let boundOkHex2 = 0xFFFF'u16
let boundOkHex3 = 0x7FFF'i16
let boundOkHex4 = 0x80'i8
let boundOkHex5 = 0xFF'i8
let boundOkHex6 = 0xFFFF'i16
let boundOkHex7 = 0x7FFF'i16
# Should _not_ compile #
let boundBreakingHex1 = 0x123'u8
let boundBreakingHex2 = 0x123'i8
let boundBreakingHex3 = 0x123123'u16
let boundBreakingHex4 = 0x123123'i16

View File

@@ -1,35 +0,0 @@
discard """
joinable: false
"""
#[
tests: hintAsError, warningAsError
]#
template fn1 =
{.hintAsError[ConvFromXtoItselfNotNeeded]:on.}
proc fn(a: string) = discard a.string
{.hintAsError[ConvFromXtoItselfNotNeeded]:off.}
template fn2 =
{.hintAsError[ConvFromXtoItselfNotNeeded]:on.}
proc fn(a: string) = discard a
{.hintAsError[ConvFromXtoItselfNotNeeded]:off.}
template gn1 =
{.warningAsError[ProveInit]:on.}
proc fn(): var int = discard
discard fn()
{.warningAsError[ProveInit]:off.}
template gn2 =
{.warningAsError[ProveInit]:on.}
proc fn(): int = discard
discard fn()
{.warningAsError[ProveInit]:off.}
doAssert not compiles(fn1())
doAssert compiles(fn2())
doAssert not compiles(gn1())
doAssert compiles(gn2())