activated more tests, allow input in test spec
This commit is contained in:
parent
e012eb1001
commit
9c2365d5c2
26 changed files with 223 additions and 124 deletions
|
|
@ -1,85 +0,0 @@
|
|||
# tests for the interpreter
|
||||
|
||||
proc loops(a: var int) =
|
||||
discard
|
||||
#var
|
||||
# b: int
|
||||
#b = glob
|
||||
#while b != 0:
|
||||
# b = b + 1
|
||||
#a = b
|
||||
|
||||
proc mymax(a, b: int): int =
|
||||
#loops(result)
|
||||
result = a
|
||||
if b > a: result = b
|
||||
|
||||
proc test(a, b: int) =
|
||||
var
|
||||
x, y: int
|
||||
x = 0
|
||||
y = 7
|
||||
if x == a + b * 3 - 7 or
|
||||
x == 8 or
|
||||
x == y and y > -56 and y < 699:
|
||||
y = 0
|
||||
elif y == 78 and x == 0:
|
||||
y = 1
|
||||
elif y == 0 and x == 0:
|
||||
y = 2
|
||||
else:
|
||||
y = 3
|
||||
|
||||
type
|
||||
TTokType = enum
|
||||
tkNil, tkType, tkConst, tkVar, tkSymbol, tkIf,
|
||||
tkWhile, tkFor, tkLoop, tkCase, tkLabel, tkGoto
|
||||
|
||||
proc testCase(t: TTokType): int =
|
||||
case t
|
||||
of tkNil, tkType, tkConst: result = 0
|
||||
of tkVar: result = 1
|
||||
of tkSymbol: result = 2
|
||||
of tkIf..tkFor: result = 3
|
||||
of tkLoop: result = 56
|
||||
else: result = -1
|
||||
test(0, 9) # test the call
|
||||
|
||||
proc TestLoops() =
|
||||
var
|
||||
i, j: int
|
||||
|
||||
while i >= 0:
|
||||
if i mod 3 == 0:
|
||||
break
|
||||
i = i + 1
|
||||
while j == 13:
|
||||
j = 13
|
||||
break
|
||||
break
|
||||
|
||||
while true:
|
||||
break
|
||||
|
||||
|
||||
var
|
||||
glob: int
|
||||
a: array[0..5, int]
|
||||
|
||||
proc main() =
|
||||
#glob = 0
|
||||
#loops( glob )
|
||||
var
|
||||
res: int
|
||||
s: string
|
||||
#write(stdout, mymax(23, 45))
|
||||
write(stdout, "Hallo! Wie heisst du? ")
|
||||
s = readLine(stdin)
|
||||
# test the case statement
|
||||
case s
|
||||
of "Andreas": write(stdout, "Du bist mein Meister!\n")
|
||||
of "Rumpf": write(stdout, "Du bist in der Familie meines Meisters!\n")
|
||||
else: write(stdout, "ich kenne dich nicht!\n")
|
||||
write(stdout, "Du heisst " & s & "\n")
|
||||
|
||||
main()
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
discard """
|
||||
file: "tmemfiles1.nim"
|
||||
outputsub: ""
|
||||
"""
|
||||
import memfiles, os
|
||||
var
|
||||
|
|
@ -8,5 +9,5 @@ var
|
|||
# Create a new file
|
||||
mm = memfiles.open(fn, mode = fmReadWrite, newFileSize = 20)
|
||||
mm.close()
|
||||
mm.close()
|
||||
# mm.close()
|
||||
if fileExists(fn): removeFile(fn)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import memfiles
|
||||
var inp = memfiles.open("tests/stdlib/tmemlines.nim")
|
||||
for line in lines(inp):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
discard """
|
||||
outputsub: "rlwuiadtrnzb"
|
||||
"""
|
||||
|
||||
# chatever the sub pattern it will find itself
|
||||
|
||||
import memfiles
|
||||
var inp = memfiles.open("tests/stdlib/tmemslices.nim")
|
||||
for mem in memSlices(inp):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import net, nativesockets
|
||||
import unittest
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
outputsub: "SUCCESS"
|
||||
"""
|
||||
|
||||
import os, osproc
|
||||
|
||||
when defined(Windows):
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
# Test Posix interface
|
||||
|
||||
when not defined(windows):
|
||||
|
|
@ -13,4 +17,3 @@ when not defined(windows):
|
|||
writeLine(stdout, u.nodename)
|
||||
writeLine(stdout, u.release)
|
||||
writeLine(stdout, u.machine)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
discard """
|
||||
output: '''
|
||||
just exiting...
|
||||
'''
|
||||
"""
|
||||
|
||||
# Test the new beforeQuit variable:
|
||||
|
||||
proc myExit() {.noconv.} =
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
# output not testable because repr prints pointer adresses
|
||||
# test the new "repr" built-in proc
|
||||
|
||||
type
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
# tests for rstgen module.
|
||||
|
||||
import ../../lib/packages/docutils/rstgen
|
||||
|
|
@ -27,7 +31,7 @@ suite "YAML syntax highlighting":
|
|||
<span class="Punctuation">?</span> <span class="StringLit">key</span>
|
||||
<span class="Punctuation">:</span> <span class="StringLit">value</span>
|
||||
<span class="Keyword">...</span></pre>"""
|
||||
|
||||
|
||||
test "Block scalars":
|
||||
let input = """.. code-block:: yaml
|
||||
a literal block scalar: |
|
||||
|
|
@ -55,7 +59,7 @@ suite "YAML syntax highlighting":
|
|||
<span class="StringLit">another literal block scalar</span><span class="Punctuation">:</span>
|
||||
<span class="Command">|+</span> <span class="Comment"># comment after header</span><span class="LongStringLit">
|
||||
allowed, since more indented than parent</span></pre>"""
|
||||
|
||||
|
||||
test "Directives":
|
||||
let input = """.. code-block:: yaml
|
||||
%YAML 1.2
|
||||
|
|
@ -97,7 +101,7 @@ suite "YAML syntax highlighting":
|
|||
<span class="StringLit">more numbers</span><span class="Punctuation">:</span> <span class="Punctuation">[</span><span class="DecNumber">-783</span><span class="Punctuation">,</span> <span class="FloatNumber">11e78</span><span class="Punctuation">]</span><span class="Punctuation">,</span>
|
||||
<span class="StringLit">not numbers</span><span class="Punctuation">:</span> <span class="Punctuation">[</span> <span class="StringLit">42e</span><span class="Punctuation">,</span> <span class="StringLit">0023</span><span class="Punctuation">,</span> <span class="StringLit">+32.37</span><span class="Punctuation">,</span> <span class="StringLit">8 ball</span><span class="Punctuation">]</span>
|
||||
<span class="Punctuation">}</span></pre>"""
|
||||
|
||||
|
||||
test "Anchors, Aliases, Tags":
|
||||
let input = """.. code-block:: yaml
|
||||
--- !!map
|
||||
|
|
@ -136,4 +140,4 @@ suite "YAML syntax highlighting":
|
|||
<span class="DecNumber">-3</span>
|
||||
<span class="DecNumber">-4</span>
|
||||
<span class="StringLit">example.com/not/a#comment</span><span class="Punctuation">:</span>
|
||||
<span class="StringLit">?not a map key</span></pre>"""
|
||||
<span class="StringLit">?not a map key</span></pre>"""
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
discard """
|
||||
outputsub: ""
|
||||
"""
|
||||
|
||||
import algorithm
|
||||
import unittest
|
||||
|
||||
|
|
@ -40,7 +44,7 @@ suite "test sort, sorted, and isSorted procs":
|
|||
test "test the shortcut versions with descending sort order":
|
||||
check(not unSortedIntSeq.isSorted(SortOrder.Descending))
|
||||
check sorted(unSortedIntSeq, SortOrder.Descending) == reversed sortedIntSeq
|
||||
check sorted(unSortedIntSeq).isSorted(SortOrder.Descending)
|
||||
check sorted(unSortedIntSeq).isSorted(SortOrder.Ascending)
|
||||
|
||||
unSortedIntSeq.sort(SortOrder.Descending)
|
||||
check unSortedIntSeq == reversed sortedIntSeq
|
||||
|
|
|
|||
|
|
@ -1,12 +1,24 @@
|
|||
discard """
|
||||
input: "Arne"
|
||||
output: '''
|
||||
Hello! What is your name?
|
||||
Nice name: Arne
|
||||
fs is: nil
|
||||
|
||||
threw exception
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
import streams
|
||||
|
||||
|
||||
block tstreams:
|
||||
var outp = newFileStream(stdout)
|
||||
var inp = newFileStream(stdin)
|
||||
write(outp, "Hello! What is your name?")
|
||||
writeLine(outp, "Hello! What is your name?")
|
||||
var line = readLine(inp)
|
||||
write(outp, "Nice name: " & line)
|
||||
writeLine(outp, "Nice name: " & line)
|
||||
|
||||
|
||||
block tstreams2:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,92 @@
|
|||
discard """
|
||||
sortoutput: true
|
||||
output: '''
|
||||
key1: value1
|
||||
key2: value2
|
||||
key_0: value0
|
||||
key_10: value10
|
||||
key_11: value11
|
||||
key_12: value12
|
||||
key_13: value13
|
||||
key_14: value14
|
||||
key_15: value15
|
||||
key_16: value16
|
||||
key_17: value17
|
||||
key_18: value18
|
||||
key_19: value19
|
||||
key_20: value20
|
||||
key_21: value21
|
||||
key_22: value22
|
||||
key_23: value23
|
||||
key_24: value24
|
||||
key_25: value25
|
||||
key_26: value26
|
||||
key_27: value27
|
||||
key_28: value28
|
||||
key_29: value29
|
||||
key_30: value30
|
||||
key_31: value31
|
||||
key_32: value32
|
||||
key_33: value33
|
||||
key_34: value34
|
||||
key_35: value35
|
||||
key_36: value36
|
||||
key_37: value37
|
||||
key_38: value38
|
||||
key_39: value39
|
||||
key_3: value3
|
||||
key_40: value40
|
||||
key_41: value41
|
||||
key_42: value42
|
||||
key_43: value43
|
||||
key_44: value44
|
||||
key_45: value45
|
||||
key_46: value46
|
||||
key_47: value47
|
||||
key_48: value48
|
||||
key_49: value49
|
||||
key_4: value4
|
||||
key_50: value50
|
||||
key_51: value51
|
||||
key_52: value52
|
||||
key_53: value53
|
||||
key_54: value54
|
||||
key_55: value55
|
||||
key_56: value56
|
||||
key_57: value57
|
||||
key_58: value58
|
||||
key_59: value59
|
||||
key_5: value5
|
||||
key_60: value60
|
||||
key_61: value61
|
||||
key_62: value62
|
||||
key_63: value63
|
||||
key_64: value64
|
||||
key_65: value65
|
||||
key_66: value66
|
||||
key_67: value67
|
||||
key_68: value68
|
||||
key_69: value69
|
||||
key_6: value6
|
||||
key_70: value70
|
||||
key_71: value71
|
||||
key_72: value72
|
||||
key_73: value73
|
||||
key_74: value74
|
||||
key_75: value75
|
||||
key_76: value76
|
||||
key_77: value77
|
||||
key_78: value78
|
||||
key_79: value79
|
||||
key_7: value7
|
||||
key_80: value80
|
||||
key_8: value8
|
||||
key_9: value9
|
||||
length of table 81
|
||||
value1 = value2
|
||||
'''
|
||||
"""
|
||||
|
||||
import strtabs
|
||||
|
||||
var tab = newStringTable({"key1": "val1", "key2": "val2"},
|
||||
|
|
@ -9,4 +98,4 @@ for key, val in pairs(tab):
|
|||
writeLine(stdout, key, ": ", val)
|
||||
writeLine(stdout, "length of table ", $tab.len)
|
||||
|
||||
writeLine(stdout, `%`("$key1 = $key2; ${PATH}", tab, {useEnvironment}))
|
||||
writeLine(stdout, `%`("$key1 = $key2", tab, {useEnvironment}))
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
# iterate over all files with a given filter:
|
||||
|
||||
import
|
||||
"../../lib/pure/os.nim", ../../ lib / pure / times
|
||||
|
||||
proc main(filter: string) =
|
||||
for filename in walkFiles(filter):
|
||||
writeLine(stdout, filename)
|
||||
|
||||
for key, val in envPairs():
|
||||
writeLine(stdout, key & '=' & val)
|
||||
|
||||
main("*.nim")
|
||||
Loading…
Add table
Add a link
Reference in a new issue