mirror of https://github.com/japl-lang/japl.git
Added printErr, tests to test the test suite
This commit is contained in:
parent
6ff9577f66
commit
0a7db3ec0c
|
@ -28,14 +28,10 @@ import strformat
|
|||
import parseutils
|
||||
import strutils
|
||||
|
||||
|
||||
|
||||
proc natPrint*(args: seq[ptr Obj]): tuple[kind: retNative, result: ptr Obj] =
|
||||
## Native function print
|
||||
## Prints an object representation
|
||||
## to stdout. If more than one argument
|
||||
## is passed, they will be printed separated
|
||||
## by a space
|
||||
template join(args: seq[ptr Obj]): string =
|
||||
## A template that returns the string
|
||||
## representation of all args separated
|
||||
## by a space.
|
||||
var res = ""
|
||||
for i in countup(0, args.high()):
|
||||
let arg = args[i]
|
||||
|
@ -43,12 +39,29 @@ proc natPrint*(args: seq[ptr Obj]): tuple[kind: retNative, result: ptr Obj] =
|
|||
res = res & arg.stringify() & " "
|
||||
else:
|
||||
res = res & arg.stringify()
|
||||
echo res
|
||||
res
|
||||
|
||||
proc natPrint*(args: seq[ptr Obj]): tuple[kind: retNative, result: ptr Obj] =
|
||||
## Native function print
|
||||
## Prints an object representation
|
||||
## to stdout. If more than one argument
|
||||
## is passed, they will be printed separated
|
||||
## by a space
|
||||
# Note: we return nil and not asNil() because
|
||||
# the VM will later use its own cached pointer
|
||||
# to nil
|
||||
echo join(args)
|
||||
return (kind: retNative.Nil, result: nil)
|
||||
|
||||
proc natPrintErr*(args: seq[ptr Obj]): tuple[kind:
|
||||
retNative, result: ptr Obj] =
|
||||
## Native function printErr
|
||||
## Prints an object representation
|
||||
## to stderr. If more than one argument
|
||||
## is passed, they will be printed separated
|
||||
## by a space
|
||||
writeLine stderr, join(args)
|
||||
return (kind: retNative.Nil, result: nil)
|
||||
|
||||
proc natReadline*(args: seq[ptr Obj]): tuple[kind: retNative, result: ptr Obj] =
|
||||
## Native function readline
|
||||
|
|
|
@ -715,6 +715,7 @@ proc initStdlib*(vm: VM) =
|
|||
when DEBUG_TRACE_VM:
|
||||
echo "DEBUG - VM: Initializing stdlib"
|
||||
vm.defineGlobal("print", newNative("print", natPrint, -1))
|
||||
vm.defineGlobal("printErr", newNative("printErr", natPrintErr, -1))
|
||||
vm.defineGlobal("clock", newNative("clock", natClock, 0))
|
||||
vm.defineGlobal("round", newNative("round", natRound, -1))
|
||||
vm.defineGlobal("toInt", newNative("toInt", natToInt, 1))
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
[; This is a comment
|
||||
|
||||
This is a comment as well.
|
||||
|
||||
[[ This is a comment too
|
||||
|
||||
[test]
|
||||
|
||||
This is a comment as well.
|
||||
An empty test should not crash, but it should pass.
|
||||
[; more comments
|
||||
[[ even more comments
|
||||
|
||||
Also note, a test without a name should not crash
|
||||
the test builder, but it should be a test with
|
||||
the name "".
|
||||
|
||||
[end]
|
|
@ -0,0 +1,19 @@
|
|||
[test: mixed]
|
||||
[source: mixed]
|
||||
print("Hello", readLine());
|
||||
//stdout:Hello world
|
||||
//stdin:world
|
||||
|
||||
print("aaaaaa");
|
||||
//stdoutre:a*
|
||||
|
||||
printErr("Hello", readLine());
|
||||
//stderr:Hello error
|
||||
//stdin:error
|
||||
|
||||
printErr("bbbbbb");
|
||||
//stderrre:b*
|
||||
[end]
|
||||
[end]
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
[Test: nw]
|
||||
[source]
|
||||
print("hey");
|
||||
print("second line");
|
||||
printErr("hey there");
|
||||
print("abcde");
|
||||
printErr("12345");
|
||||
printErr("0123456789.");
|
||||
[end]
|
||||
[stdout: nw]
|
||||
hey
|
||||
second line
|
||||
[end]
|
||||
[stdout: nwre]
|
||||
[a-z]*
|
||||
[end]
|
||||
[stderr: nw]
|
||||
hey there
|
||||
[end]
|
||||
[stderr: nwre]
|
||||
[[0-9]*
|
||||
[0-9]*.
|
||||
[end]
|
||||
[end]
|
|
@ -0,0 +1,25 @@
|
|||
[Test: raw]
|
||||
[source: raw]
|
||||
print("Hi", readLine());
|
||||
print("aaaaaaa");
|
||||
printErr("Bye", readLine());
|
||||
printErr("bbbbbbb");
|
||||
//stdout:This is not a part of the expected output
|
||||
[end]
|
||||
[stdin]
|
||||
person
|
||||
very important person
|
||||
[end]
|
||||
[stdout]
|
||||
Hi person
|
||||
[end]
|
||||
[stdout: re]
|
||||
a*
|
||||
[end]
|
||||
[stderr]
|
||||
Bye very important person
|
||||
[end]
|
||||
[stderr: re]
|
||||
b*
|
||||
[end]
|
||||
[end]
|
|
@ -0,0 +1,7 @@
|
|||
[test: skipped]
|
||||
[skip]
|
||||
|
||||
[stdout]
|
||||
Hello this text won't be matched.
|
||||
[end]
|
||||
[end]
|
|
@ -25,6 +25,12 @@ It can stay in this state during parsing, can leave
|
|||
it by entering another mode and can
|
||||
return to it, by leaving any mode it has entered.
|
||||
|
||||
## Test files
|
||||
|
||||
Must be utf-8 (for now only ascii was tested).
|
||||
Must not contain a BOM. Line endings must be a single
|
||||
`\n`. Please configure your editor to support this.
|
||||
|
||||
## Syntax
|
||||
|
||||
### Mode syntax
|
||||
|
|
Loading…
Reference in New Issue