Tests fixed for new structure

This commit is contained in:
perro tuerto 2023-03-16 14:58:56 -07:00
parent f95db9f9f3
commit 841e1733d4
13 changed files with 326 additions and 214 deletions

View File

@ -1,20 +0,0 @@
# Declarations
-- fn1(x)
#x + 2 + 3
# Invalid Declarations
-- fn0 not declared: fn3(x)
#fn0 * #x
-- infinite loop: fn3(x)
#fn3(1) * #x
# Invalid Calls
- fn1(1, $action: "foo") has invalid rkwarg value
- fn1(1, $act: "shift") has invalid rkwarg
- fn1(fn4()); \fn4() is not declared
Invalid calls and declarations generate and collects errors.

126
tests/fail.lit.errors.md Normal file
View File

@ -0,0 +1,126 @@
# Invalid Blocks
All errors should be collected, printed and exit with 1.
Malformed YAML:
---
id: fn1
fail
...
1 + 2 + 3
Empty YAML:
---
...
1 + 2 + 3
Empty code:
---
id: fn1
...
Misses arg:
---
id: fn1
...
#a + #b
Misses id:
---
identifier: fn1
...
1 + 2 + 3
Wrong id (doesn't starts with `%a`):
---
id: 1
...
1 + 2 + 3
Wrong id (doesn't follows with `%w`):
---
id: f-1
...
1 + 2 + 3
Wrong id (more than 1 word):
---
id: f n1
...
1 + 2 + 3
Uknown cmd:
---
id: fn1
cmd: pyton -E -X utf8
args:
n: 2
...
#n + #n
Unknown key:
---
id: fn1
language: fennel
args:
a: 1
b: 2
...
(* #a #b)
Invalid value:
---
id: fn1
shift: "true"
...
"The literate block is shifted by its eval result."
Invalid code:
---
id: fn1
...
false + false
Infinite loop:
---
id: fn1
args:
x: 1
...
#fn1(2) * #x
# Blocks for Invalid Inserts:
---
id: fn1
typed: true
args:
a: 1
b: 2
...
#a * #b
# Invalid Inserts
- `fn1(` never end
- `fn1(invalid arg)`
- `fn1()` misses args
- `fn1(1)` less args
- `fn1(1, 2, 3)` extra args
- `fn1(x: 3, y: 4)` wrong kwargs
- `fn1(1, a: 2)` mixed arg and kwarg
- `fn1(a: 1.0, b: 2.0)` misses type
- `fn2()` not declared

View File

@ -1,38 +0,0 @@
# Declarations
-- fn1()
1 + 2 + 3
-- fn2(n)
#n .. " " .. #n)
-- fn3(a, b)
#a * #b
# Invalid Declarations
-- misses end: fn4(
1 + 2 + 3
-- fn5(invalid arg)
4 + 5 + 6
-- misses arg: fn6()
#n .. " " .. #n
-- misses separator: fn7(a b)
#a * #b
# Invalid Calls
- fn1(1) adds arg
- fn1( never end
- fn1(invalid arg)
- fn2() misses arg
- fn2(a: 3) wrong kwarg
- fn3(1 2) misses separator
- fn3(1, 2, 3) wrong args number
- fn3(1, b: 2) mixed arg and kwarg
- fn4() fn5() not declared
Invalid calls and declarations generate and collects errors.

View File

@ -1,42 +0,0 @@
# Declarations
-- fn1()
print("I am in stdout")
"Wipes it"
-- fn2()
1 + 2 + 3
-- fn3(n)
#n .. " " .. #n
-- fn4(a, b)
#a * #b
# Recursive Declarations
-- fn5(x)
#fn2() * x
-- fn6(y, z)
#y + #fn2($action: "quote") + #z
-- fn7(a)
#a + #fn4(#a, #fn2())
# Calls
Valid calls:
- fn1($results: "value") gets value of the last expression as result; it is the default setting.
- fn1($results: "output") gets stdout as result.
- fn2($action: "shift") shifts call for result.
- fn2($action: "quote") quotes it instead of calling it.
- fn3(4, $action: "shift") has arg and rkwarg.
- fn3($action: "shift", 5) has rkwarg and arg.
- fn4($action: "shift", a: 1, b: 2) has rkwarg and kwargs.
- fn4(a: 1, $action: "shift", b: 2) has kwarg, rkwarg and kwarg.
- fn4(a: 1, b: 2, $action: "shift") has kwargs and rkwarg.
- fn5(10) calls another function inside.
- fn6(9, 8) calls another quoted function inside.
- fn7(fn7(1)) calls several functions.

View File

@ -1 +0,0 @@
{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["declarations",[],[]],[{"t":"Str","c":"Declarations"}]]},{"t":"CodeBlock","c":[["",[],[]],"-- fn1()\nprint(\"I am in stdout\")\n\"Wipes it\"\n\n-- fn2()\n1 + 2 + 3\n\n-- fn3(n)\n#n .. \" \" .. #n\n\n-- fn4(a, b)\n#a * #b"]},{"t":"Header","c":[1,["recursive-declarations",[],[]],[{"t":"Str","c":"Recursive"},{"t":"Space"},{"t":"Str","c":"Declarations"}]]},{"t":"CodeBlock","c":[["",[],[]],"-- fn5(x)\n#fn2() * x\n\n-- fn6(y, z)\n#y + #fn2($action: \"quote\") + #z\n\n-- fn7(a) \n#a + #fn4(#a, #fn2())"]},{"t":"Header","c":[1,["calls",[],[]],[{"t":"Str","c":"Calls"}]]},{"t":"Para","c":[{"t":"Str","c":"Valid"},{"t":"Space"},{"t":"Str","c":"calls:"}]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Str","c":"fn1($results:"},{"t":"Space"},{"t":"Str","c":"\"value\""},{"t":"Str","c":")"},{"t":"Space"},{"t":"Str","c":"gets"},{"t":"Space"},{"t":"Str","c":"value"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"last"},{"t":"Space"},{"t":"Str","c":"expression"},{"t":"Space"},{"t":"Str","c":"as"},{"t":"Space"},{"t":"Str","c":"result;"},{"t":"Space"},{"t":"Str","c":"it"},{"t":"Space"},{"t":"Str","c":"is"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"default"},{"t":"Space"},{"t":"Str","c":"setting."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn1($results:"},{"t":"Space"},{"t":"Str","c":"\"output\""},{"t":"Str","c":")"},{"t":"Space"},{"t":"Str","c":"gets"},{"t":"Space"},{"t":"Str","c":"stdout"},{"t":"Space"},{"t":"Str","c":"as"},{"t":"Space"},{"t":"Str","c":"result."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn2($action:"},{"t":"Space"},{"t":"Str","c":"\"shift\""},{"t":"Str","c":")"},{"t":"Space"},{"t":"Str","c":"shifts"},{"t":"Space"},{"t":"Str","c":"call"},{"t":"Space"},{"t":"Str","c":"for"},{"t":"Space"},{"t":"Str","c":"result."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn2($action:"},{"t":"Space"},{"t":"Str","c":"\"quote\""},{"t":"Str","c":")"},{"t":"Space"},{"t":"Str","c":"quotes"},{"t":"Space"},{"t":"Str","c":"it"},{"t":"Space"},{"t":"Str","c":"instead"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"calling"},{"t":"Space"},{"t":"Str","c":"it."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn3(4,"},{"t":"Space"},{"t":"Str","c":"$action:"},{"t":"Space"},{"t":"Str","c":"\"shift\""},{"t":"Str","c":")"},{"t":"Space"},{"t":"Str","c":"has"},{"t":"Space"},{"t":"Str","c":"arg"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"rkwarg."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn3($action:"},{"t":"Space"},{"t":"Str","c":"\"shift\""},{"t":"Str","c":","},{"t":"Space"},{"t":"Str","c":"5)"},{"t":"Space"},{"t":"Str","c":"has"},{"t":"Space"},{"t":"Str","c":"rkwarg"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"arg."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn4($action:"},{"t":"Space"},{"t":"Str","c":"\"shift\""},{"t":"Str","c":","},{"t":"Space"},{"t":"Str","c":"a:"},{"t":"Space"},{"t":"Str","c":"1,"},{"t":"Space"},{"t":"Str","c":"b:"},{"t":"Space"},{"t":"Str","c":"2)"},{"t":"Space"},{"t":"Str","c":"has"},{"t":"Space"},{"t":"Str","c":"rkwarg"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"kwargs."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn4(a:"},{"t":"Space"},{"t":"Str","c":"1,"},{"t":"Space"},{"t":"Str","c":"$action:"},{"t":"Space"},{"t":"Str","c":"\"shift\""},{"t":"Str","c":","},{"t":"Space"},{"t":"Str","c":"b:"},{"t":"Space"},{"t":"Str","c":"2)"},{"t":"Space"},{"t":"Str","c":"has"},{"t":"Space"},{"t":"Str","c":"kwarg,"},{"t":"Space"},{"t":"Str","c":"rkwarg"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"kwarg."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn4(a:"},{"t":"Space"},{"t":"Str","c":"1,"},{"t":"Space"},{"t":"Str","c":"b:"},{"t":"Space"},{"t":"Str","c":"2,"},{"t":"Space"},{"t":"Str","c":"$action:"},{"t":"Space"},{"t":"Str","c":"\"shift\""},{"t":"Str","c":")"},{"t":"Space"},{"t":"Str","c":"has"},{"t":"Space"},{"t":"Str","c":"kwargs"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"rkwarg."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn5(10)"},{"t":"Space"},{"t":"Str","c":"calls"},{"t":"Space"},{"t":"Str","c":"another"},{"t":"Space"},{"t":"Str","c":"function"},{"t":"Space"},{"t":"Str","c":"inside."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn6(9,"},{"t":"Space"},{"t":"Str","c":"8)"},{"t":"Space"},{"t":"Str","c":"calls"},{"t":"Space"},{"t":"Str","c":"another"},{"t":"Space"},{"t":"Str","c":"quoted"},{"t":"Space"},{"t":"Str","c":"function"},{"t":"Space"},{"t":"Str","c":"inside."}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn7(fn7(1))"},{"t":"Space"},{"t":"Str","c":"calls"},{"t":"Space"},{"t":"Str","c":"several"},{"t":"Space"},{"t":"Str","c":"functions."}]}]]}]}

View File

@ -1,28 +0,0 @@
# Not declarations
-- skipped: \fn1()
1 + 2
-- doesn't starts with `%a` because of the space: fn 2()
1 + 2
-- doesn't continue with `%w`: fn-3()
1 + 2
-- space before `(`: fn4 ()
1 + 2
-- misses `(`: fn5)
1 + 2
-- misses `()`: fn6
1 + 2
# Not calls
- \fn1() skipped
- fn 2() doesn't starts with `%a` because of the space
- fn-3() doesn't continue with `%w`
- fn4 () space before `(`
- fn5) misses `(`
- fn6 misses `()`

View File

@ -1 +0,0 @@
{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["not-declarations",[],[]],[{"t":"Str","c":"Not"},{"t":"Space"},{"t":"Str","c":"declarations"}]]},{"t":"CodeBlock","c":[["",[],[]],"-- skipped: \\fn1()\n1 + 2\n\n-- doesn't starts with `%a` because of the space: fn 2()\n1 + 2\n\n-- doesn't continue with `%w`: fn-3()\n1 + 2\n\n-- space before `(`: fn4 ()\n1 + 2\n\n-- misses `(`: fn5) \n1 + 2\n\n-- misses `()`: fn6 \n1 + 2"]},{"t":"Header","c":[1,["not-calls",[],[]],[{"t":"Str","c":"Not"},{"t":"Space"},{"t":"Str","c":"calls"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"RawInline","c":["tex","\\fn1"]},{"t":"Str","c":"()"},{"t":"Space"},{"t":"Str","c":"skipped"}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn"},{"t":"Space"},{"t":"Str","c":"2()"},{"t":"Space"},{"t":"Str","c":"doesnt"},{"t":"Space"},{"t":"Str","c":"starts"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"%a"]},{"t":"Space"},{"t":"Str","c":"because"},{"t":"Space"},{"t":"Str","c":"of"},{"t":"Space"},{"t":"Str","c":"the"},{"t":"Space"},{"t":"Str","c":"space"}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn-3()"},{"t":"Space"},{"t":"Str","c":"doesnt"},{"t":"Space"},{"t":"Str","c":"continue"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"%w"]}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn4"},{"t":"Space"},{"t":"Str","c":"()"},{"t":"Space"},{"t":"Str","c":"space"},{"t":"Space"},{"t":"Str","c":"before"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"("]}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn5)"},{"t":"Space"},{"t":"Str","c":"misses"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"("]}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn6"},{"t":"Space"},{"t":"Str","c":"misses"},{"t":"Space"},{"t":"Code","c":[["",[],[]],"()"]}]}]]}]}

168
tests/pass.lit.infos.md Normal file
View File

@ -0,0 +1,168 @@
# Inserts Before Blocks
- `fn1()``fn2()`
- `fn3(true)`
- `fn4(2.0, 3.1)`
- `fn3(n: false)`
- `fn4(b: 4, a: 5)`
# Blocks
All literate blocks should be print on `--verbose`.
Minimal (Lua by default):
---
id: fn1
...
1 + 2 + 3
With scape:
---
id: fn2
...
"\#x"
With arg:
---
id: fn3
args:
n: str
...
#n == #n
With lang and args:
---
id: fn4
lang: fennel
args:
a: 1
b: 2
...
(* #a #b)
With cmd (ignores lang):
---
id: fn5
cmd: python -E -X utf8
args:
n: 2
...
#n + #n
With shift (nil by default):
---
id: fn6
shift: true
...
"The literate block is shifted by its eval result."
With wipe (nil by default):
---
id: fn7
wipe: true
...
"This evals but it is wipe from doc."
With typed (nil by default):
---
id: fn4
typed: true
args:
a: 1
b: 2
...
#a * #b
With link (nil by default) and alt (optional):
---
id: fn8
lang: graphviz
link: ./graph.png
alt: A graph.
...
digraph G {
a -> b;
b -> c
c -> a;
}
With img (nil by default) and alt (optional):
---
id: fn9
lang: graphviz
img: ./graph.png
alt: A graph.
...
digraph G {
a -> b;
b -> c
c -> a;
}
With inner function:
---
id: fn10
args:
x: 2
...
#fn1() * x
With inner function with args:
---
id: fn11
args:
y: 1
z: 2
...
#y + #fn4(3, 4) + #z
With inner inner function:
---
id: fn12
args:
a: 1
...
#a + #fn4(#a, #fn1())
# Inserts and Data Types
- `fn3(true)`
- `fn3(false)`
- `fn3([])`
- `fn3([0, 1])`
- `fn3({})`
- `fn3({"k1": 1, "k2": 2})`
- `fn4(3)`
- `fn5(1.0)`
- `fn5("str")`
# Messy Inserts
- `fn1( )`
- `fn3("\"str\"")`
- `fn3( 4)`
- `fn3(5 )`
- `fn3( 6 )`
- `fn3( n: 7)`
- `fn3(n: 8 )`
- `fn3( n: 9 )`
- `fn3(n:10)`
- `fn4( a: 6, b: 7)`
- `fn4( a: 8 , b: 9)`
- `fn4( a: 10 , b: 11)`
- `fn4( a: 12 , b: 13)`
- `fn4( a: 14 , b: 15 )`
- `fn4(a:16,b:17)`

File diff suppressed because one or more lines are too long

View File

@ -1,69 +0,0 @@
# Calls Before Declarations
- A common call: fn1(). All calls results should be print on `--verbose`.
- fn1() another common call.
- fn1()
- Two calls: fn1() and fn1().
- Two consecutive calls: fn1() fn1().
- A call with one arg: fn2(1).
- A call with two args: fn3(2, 3).
- A call with args as kwargs: fn2(n: 2) and fn3(b: 4, a: 5).
# Declarations
A declaration:
-- fn1()
1 + 2 + 3
All declarations should be print on `--verbose`.
A declaration with one arg:
-- Also valid, Lua is the default: fn2(n)
#n .. " " .. #n
A declaration with two args:
; Changed lang and no space:fn3(a, b) -> fennel
(* #a #b)
A declaration with lang options:
# fn4(n) -> python -E -X utf8
#n * #n
A declaration with arg and scaped:
-- fn5(x)
#x .. "\#x"
# Calls and Data Types
- fn2(3); integer
- fn2(1_000); integer with separator
- fn4(1.0); float
- fn5("str"); string
- fn5(true)
- fn5(false)
- fn2([]); empty array / list / sequential table
- fn2([0, 1]); array / list / sequential table
- fn2({}); empty dict / table
- fn2({"k1": 1, "k2": 2}); dict / table
# Messy Calls
- fn1( )
- fn2( 4)
- fn2(5 )
- fn2( 6 )
- fn2( n: 7)
- fn2(n: 8 )
- fn2( n: 9 )
- fn2(n:10)
- fn3( a: 6, b: 7)
- fn3( a: 8 , b: 9)
- fn3( a: 10 , b: 11)
- fn3( a: 12 , b: 13)
- fn3( a: 14 , b: 15 )
- fn3(a:16,b:17)

File diff suppressed because one or more lines are too long

View File

@ -1,22 +1,39 @@
# Declaration Override
# Block Override
-- fn1()
---
id: fn1
...
1 + 2 + 3
-- fn1()
---
id: fn1
...
4 + 5 + 6
# Unused Declaration
# Block with Unused Argument
-- fn2(n)
#n .. " " .. #n
# Declaration with Unused Argument
-- fn3(a)
---
id: fn3
args:
- a: 1
...
7 + 8 + 9
# Calls
# Block with Language and Command
- fn1()
- fn3(1)
---
id: fn4
lang: python
cmd: python -E -X utf8
args:
- n: 2
...
#n * #n
# Block with Unknown Language
---
id: fn5
lang: echo
...
"Lang becomes cmd."

View File

@ -1 +1 @@
{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["declaration-override",[],[]],[{"t":"Str","c":"Declaration"},{"t":"Space"},{"t":"Str","c":"Override"}]]},{"t":"CodeBlock","c":[["",[],[]],"-- fn1()\n1 + 2 + 3\n\n-- fn1()\n4 + 5 + 6"]},{"t":"Header","c":[1,["unused-declaration",[],[]],[{"t":"Str","c":"Unused"},{"t":"Space"},{"t":"Str","c":"Declaration"}]]},{"t":"CodeBlock","c":[["",[],[]],"-- fn2(n)\n#n .. \" \" .. #n"]},{"t":"Header","c":[1,["declaration-with-unused-argument",[],[]],[{"t":"Str","c":"Declaration"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Unused"},{"t":"Space"},{"t":"Str","c":"Argument"}]]},{"t":"CodeBlock","c":[["",[],[]],"-- fn3(a)\n7 + 8 + 9"]},{"t":"Header","c":[1,["calls",[],[]],[{"t":"Str","c":"Calls"}]]},{"t":"BulletList","c":[[{"t":"Plain","c":[{"t":"Str","c":"fn1()"}]}],[{"t":"Plain","c":[{"t":"Str","c":"fn3(1)"}]}]]}]}
{"pandoc-api-version":[1,23],"meta":{},"blocks":[{"t":"Header","c":[1,["block-override",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"Override"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn1\n...\n1 + 2 + 3\n\n---\nid: fn1\n...\n4 + 5 + 6"]},{"t":"Header","c":[1,["block-with-unused-argument",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Unused"},{"t":"Space"},{"t":"Str","c":"Argument"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn3\nargs:\n- a: 1\n...\n7 + 8 + 9"]},{"t":"Header","c":[1,["block-with-language-and-command",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Language"},{"t":"Space"},{"t":"Str","c":"and"},{"t":"Space"},{"t":"Str","c":"Command"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn4\nlang: python\ncmd: python -E -X utf8\nargs:\n- n: 2\n...\n#n * #n"]},{"t":"Header","c":[1,["block-with-unknown-language",[],[]],[{"t":"Str","c":"Block"},{"t":"Space"},{"t":"Str","c":"with"},{"t":"Space"},{"t":"Str","c":"Unknown"},{"t":"Space"},{"t":"Str","c":"Language"}]]},{"t":"CodeBlock","c":[["",[],[]],"---\nid: fn5\nlang: echo\n...\n\"Lang becomes cmd.\""]}]}