new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
12
tests/lexer/thexlit.nim
Normal file
12
tests/lexer/thexlit.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
discard """
|
||||
file: "thexlit.nim"
|
||||
output: "equal"
|
||||
"""
|
||||
|
||||
var t=0x950412DE
|
||||
|
||||
if t==0x950412DE:
|
||||
echo "equal"
|
||||
else:
|
||||
echo "not equal"
|
||||
|
||||
8
tests/lexer/thexrange.nim
Normal file
8
tests/lexer/thexrange.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
type
|
||||
TArray = array[0x0012..0x0013, int]
|
||||
|
||||
var a: TArray
|
||||
|
||||
echo a[0x0012] #OUT 0
|
||||
|
||||
22
tests/lexer/tident.nim
Normal file
22
tests/lexer/tident.nim
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
type
|
||||
TIdObj* = object of TObject
|
||||
id*: int # unique id; use this for comparisons and not the pointers
|
||||
|
||||
PIdObj* = ref TIdObj
|
||||
PIdent* = ref TIdent
|
||||
TIdent*{.acyclic.} = object
|
||||
s*: string
|
||||
|
||||
proc myNewString(L: int): string {.inline.} =
|
||||
result = newString(L)
|
||||
if result.len == L: echo("Length correct")
|
||||
else: echo("bug")
|
||||
for i in 0..L-1:
|
||||
if result[i] == '\0':
|
||||
echo("Correct")
|
||||
else:
|
||||
echo("Wrong")
|
||||
|
||||
var s = myNewString(8)
|
||||
|
||||
27
tests/lexer/tind1.nim
Normal file
27
tests/lexer/tind1.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
discard """
|
||||
line: 24
|
||||
errormsg: "expression expected, but found 'keyword else'"
|
||||
"""
|
||||
|
||||
import macros
|
||||
|
||||
# finally optional indentation in 'if' expressions :-):
|
||||
var x = if 4 != 5:
|
||||
"yes"
|
||||
else:
|
||||
"no"
|
||||
|
||||
macro mymacro(n: expr): stmt {.immediate.} = nil
|
||||
|
||||
mymacro:
|
||||
echo "test"
|
||||
else:
|
||||
echo "else part"
|
||||
|
||||
|
||||
if 4 == 3:
|
||||
echo "bug"
|
||||
else:
|
||||
echo "no bug"
|
||||
|
||||
|
||||
42
tests/lexer/tindent1.nim
Normal file
42
tests/lexer/tindent1.nim
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
discard """
|
||||
output: '''Success'''
|
||||
"""
|
||||
|
||||
const romanNumbers1 =
|
||||
[
|
||||
("M", 1000), ("D", 500), ("C", 100),
|
||||
("L", 50), ("X", 10), ("V", 5), ("I", 1) ]
|
||||
|
||||
const romanNumbers2 =
|
||||
[
|
||||
("M", 1000), ("D", 500), ("C", 100),
|
||||
("L", 50), ("X", 10), ("V", 5), ("I", 1)
|
||||
]
|
||||
|
||||
const romanNumbers3 =
|
||||
[
|
||||
("M", 1000), ("D", 500), ("C", 100),
|
||||
("L", 50), ("X", 10), ("V", 5), ("I", 1)
|
||||
]
|
||||
|
||||
const romanNumbers4 = [
|
||||
("M", 1000), ("D", 500), ("C", 100),
|
||||
("L", 50), ("X", 10), ("V", 5), ("I", 1)
|
||||
]
|
||||
|
||||
|
||||
proc main =
|
||||
var j = 0
|
||||
while j < 10:
|
||||
inc(j);
|
||||
|
||||
if j == 5: doAssert false
|
||||
|
||||
var j = 0
|
||||
while j < 10:
|
||||
inc(j);
|
||||
|
||||
if j == 5: doAssert false
|
||||
|
||||
main()
|
||||
echo "Success"
|
||||
60
tests/lexer/tlexer.nim
Normal file
60
tests/lexer/tlexer.nim
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
discard """
|
||||
disabled: true
|
||||
"""
|
||||
|
||||
# We start with a comment
|
||||
# This is the same comment
|
||||
|
||||
# This is a new one!
|
||||
|
||||
import
|
||||
lexbase, os, strutils
|
||||
|
||||
type
|
||||
TMyRec {.final.} = object
|
||||
x, y: int # coordinates
|
||||
c: char # a character
|
||||
a: int32 # an integer
|
||||
|
||||
PMyRec = ref TMyRec # a reference to `TMyRec`
|
||||
|
||||
proc splitText(txt: string): seq[string] # splits a text into several lines
|
||||
# the comment continues here
|
||||
# this is not easy to parse!
|
||||
|
||||
proc anotherSplit(txt: string): seq[string] =
|
||||
# the comment should belong to `anotherSplit`!
|
||||
# another problem: comments are statements!
|
||||
|
||||
const
|
||||
x = 0B0_10001110100_0000101001000111101011101111111011000101001101001001'f64 # x ~~ 1.72826e35
|
||||
myNan = 0B01111111100000101100000000001000'f32 # NAN
|
||||
y = """
|
||||
a rather long text.
|
||||
Over many
|
||||
lines.
|
||||
"""
|
||||
s = "\xff"
|
||||
a = {0..234}
|
||||
b = {0..high(int)}
|
||||
v = 0'i32
|
||||
z = 6767566'f32
|
||||
|
||||
# small test program for lexbase
|
||||
|
||||
proc main*(infile: string, a, b: int, someverylongnamewithtype = 0,
|
||||
anotherlongthingie = 3) =
|
||||
var
|
||||
myInt: int = 0
|
||||
s: seq[string]
|
||||
# this should be an error!
|
||||
if initBaseLexer(L, infile, 30): nil
|
||||
else:
|
||||
writeln(stdout, "could not open: " & infile)
|
||||
writeln(stdout, "Success!")
|
||||
call(3, # we use 3
|
||||
12, # we use 12
|
||||
43) # we use 43
|
||||
|
||||
|
||||
main(ParamStr(1), 9, 0)
|
||||
10
tests/lexer/tmissingnl.nim
Normal file
10
tests/lexer/tmissingnl.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
discard """
|
||||
file: "tmissingnl.nim"
|
||||
line: 7
|
||||
errormsg: "invalid indentation"
|
||||
"""
|
||||
|
||||
import strutils var s: seq[int] = @[0, 1, 2, 3, 4, 5, 6]
|
||||
|
||||
#s[1..3] = @[]
|
||||
|
||||
20
tests/lexer/tstrlits.nim
Normal file
20
tests/lexer/tstrlits.nim
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
discard """
|
||||
file: "tstrlits.nim"
|
||||
output: "a\"\"long string\"\"\"\"\"abc\"def"
|
||||
"""
|
||||
# Test the new different string literals
|
||||
|
||||
const
|
||||
tripleEmpty = """"long string"""""""" # "long string """""
|
||||
|
||||
rawQuote = r"a"""
|
||||
|
||||
raw = r"abc""def"
|
||||
|
||||
stdout.write(rawQuote)
|
||||
stdout.write(tripleEmpty)
|
||||
stdout.write(raw)
|
||||
#OUT a""long string"""""abc"def
|
||||
|
||||
|
||||
|
||||
14
tests/lexer/tunderscores.nim
Normal file
14
tests/lexer/tunderscores.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
discard """
|
||||
file: "tunderscores.nim"
|
||||
line: 8
|
||||
errormsg: "invalid token: _"
|
||||
"""
|
||||
# Bug #502670
|
||||
|
||||
var ef_ = 3 #ERROR_MSG invalid token: _
|
||||
var a__b = 1
|
||||
var c___d = 2
|
||||
echo(ab, cd, ef_)
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue