diff options
author | Araq <rumpf_a@web.de> | 2014-01-13 02:10:03 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-01-13 02:10:03 +0100 |
commit | 20b5f31c03fb556ec0aa2428a40adbac004d8987 (patch) | |
tree | 58086941e7d6bb8f480ca1173a95722ada9435b2 /tests/lexer | |
parent | 51ee524109cf7e3e86c676bc1676063a01bfd979 (diff) | |
download | Nim-20b5f31c03fb556ec0aa2428a40adbac004d8987.tar.gz |
new tester; all tests categorized
Diffstat (limited to 'tests/lexer')
-rw-r--r-- | tests/lexer/thexlit.nim | 12 | ||||
-rw-r--r-- | tests/lexer/thexrange.nim | 8 | ||||
-rw-r--r-- | tests/lexer/tident.nim | 22 | ||||
-rw-r--r-- | tests/lexer/tind1.nim | 27 | ||||
-rw-r--r-- | tests/lexer/tindent1.nim | 42 | ||||
-rw-r--r-- | tests/lexer/tlexer.nim | 60 | ||||
-rw-r--r-- | tests/lexer/tmissingnl.nim | 10 | ||||
-rw-r--r-- | tests/lexer/tstrlits.nim | 20 | ||||
-rw-r--r-- | tests/lexer/tunderscores.nim | 14 |
9 files changed, 215 insertions, 0 deletions
diff --git a/tests/lexer/thexlit.nim b/tests/lexer/thexlit.nim new file mode 100644 index 000000000..04a530c9c --- /dev/null +++ b/tests/lexer/thexlit.nim @@ -0,0 +1,12 @@ +discard """ + file: "thexlit.nim" + output: "equal" +""" + +var t=0x950412DE + +if t==0x950412DE: + echo "equal" +else: + echo "not equal" + diff --git a/tests/lexer/thexrange.nim b/tests/lexer/thexrange.nim new file mode 100644 index 000000000..e5e4c10c6 --- /dev/null +++ b/tests/lexer/thexrange.nim @@ -0,0 +1,8 @@ + +type + TArray = array[0x0012..0x0013, int] + +var a: TArray + +echo a[0x0012] #OUT 0 + diff --git a/tests/lexer/tident.nim b/tests/lexer/tident.nim new file mode 100644 index 000000000..1ed9894c6 --- /dev/null +++ b/tests/lexer/tident.nim @@ -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) + diff --git a/tests/lexer/tind1.nim b/tests/lexer/tind1.nim new file mode 100644 index 000000000..f3fd952cc --- /dev/null +++ b/tests/lexer/tind1.nim @@ -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" + + diff --git a/tests/lexer/tindent1.nim b/tests/lexer/tindent1.nim new file mode 100644 index 000000000..78a303783 --- /dev/null +++ b/tests/lexer/tindent1.nim @@ -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" diff --git a/tests/lexer/tlexer.nim b/tests/lexer/tlexer.nim new file mode 100644 index 000000000..10a8ab51d --- /dev/null +++ b/tests/lexer/tlexer.nim @@ -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) diff --git a/tests/lexer/tmissingnl.nim b/tests/lexer/tmissingnl.nim new file mode 100644 index 000000000..33b7debf1 --- /dev/null +++ b/tests/lexer/tmissingnl.nim @@ -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] = @[] + diff --git a/tests/lexer/tstrlits.nim b/tests/lexer/tstrlits.nim new file mode 100644 index 000000000..1cd43975a --- /dev/null +++ b/tests/lexer/tstrlits.nim @@ -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 + + + diff --git a/tests/lexer/tunderscores.nim b/tests/lexer/tunderscores.nim new file mode 100644 index 000000000..8075fdae4 --- /dev/null +++ b/tests/lexer/tunderscores.nim @@ -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_) + + + |