mirror of
https://github.com/zorp-corp/jock-lang.git
synced 2024-11-27 08:54:59 +03:00
WIP but commit version in issue #10
This commit is contained in:
parent
e3b3c342db
commit
14669384e8
Binary file not shown.
@ -1,47 +1,68 @@
|
||||
/+ jock
|
||||
::/* let-edit %jock /lib/tests/let-edit/jock
|
||||
::/* let-inner-exp %jock /lib/tests/let-inner-exp/jock
|
||||
::/* call %jock /lib/tests/call/jock
|
||||
::/* axis-call %jock /lib/tests/axis-call/jock
|
||||
::/* inline-lambda-call %jock /lib/tests/inline-lambda-call/jock
|
||||
::/* in-subj-call %jock /lib/tests/in-subj-call/jock
|
||||
::/* if-else %jock /lib/tests/if-else/jock
|
||||
::/* assert %jock /lib/tests/assert/jock
|
||||
::/* call-let-edit %jock /lib/tests/call-let-edit/jock
|
||||
::/* inline-point %jock /lib/tests/inline-point/jock
|
||||
::/* inline-lambda-no-arg %jock /lib/tests/inline-lambda-no-arg/jock
|
||||
::/* dec-jock %jock /lib/tests/dec/jock
|
||||
::/* eval %jock /lib/tests/eval/jock
|
||||
::/* multi-limb %jock /lib/tests/multi-limb/jock
|
||||
::/* compose %jock /lib/tests/compose/jock
|
||||
::/* compose-cores %jock /lib/tests/compose-cores/jock
|
||||
::/* baby %jock /lib/tests/baby/jock
|
||||
::/* comparator %jock /lib/tests/comparator/jock
|
||||
|%
|
||||
/* let-edit %jock /lib/tests/let-edit
|
||||
/* let-inner-exp %jock /lib/tests/let-inner-exp
|
||||
/* call %jock /lib/tests/call
|
||||
/* axis-call %jock /lib/tests/axis-call
|
||||
/* inline-lambda-call %jock /lib/tests/inline-lambda-call
|
||||
/* in-subj-call %jock /lib/tests/in-subj-call
|
||||
/* if-else %jock /lib/tests/if-else
|
||||
/* if-elseif-else %jock /lib/tests/if-elseif-else
|
||||
/* assert %jock /lib/tests/assert
|
||||
/* call-let-edit %jock /lib/tests/call-let-edit
|
||||
/* inline-point %jock /lib/tests/inline-point
|
||||
/* inline-lambda-no-arg %jock /lib/tests/inline-lambda-no-arg
|
||||
/* dec %jock /lib/tests/dec
|
||||
/* eval %jock /lib/tests/eval
|
||||
/* multi-limb %jock /lib/tests/multi-limb
|
||||
/* compose %jock /lib/tests/compose
|
||||
/* compose-cores %jock /lib/tests/compose-cores
|
||||
/* baby %jock /lib/tests/baby
|
||||
/* comparator %jock /lib/tests/comparator
|
||||
::
|
||||
/* test-let-edit %hoon /tests/lib/let-edit
|
||||
::
|
||||
|%
|
||||
++ list-jocks
|
||||
^- (list [term @t])
|
||||
:~ ex+''
|
||||
:~ [%let-edit q.let-edit]
|
||||
:: [%let-inner-exp q.let-inner-exp]
|
||||
:: [%call q.call]
|
||||
:: [%axis-call q.axis-call]
|
||||
:: [%inline-lambda-call q.inline-lambda-call]
|
||||
:: [%in-subj-call q.in-subj-call]
|
||||
:: [%if-else q.if-else]
|
||||
:: [%if-elseif-else q.if-elseif-else]
|
||||
:: [%assert q.assert]
|
||||
:: [%call-let-edit q.call-let-edit]
|
||||
:: [%inline-point q.inline-point]
|
||||
:: [%inline-lambda-no-arg q.inline-lambda-no-arg]
|
||||
:: [%dec q.dec]
|
||||
:: [%eval q.eval]
|
||||
:: [%multi-limb q.multi-limb]
|
||||
:: [%compose q.compose]
|
||||
:: [%compose-cores q.compose-cores]
|
||||
:: [%baby q.baby]
|
||||
:: [%comparator q.comparator]
|
||||
==
|
||||
::
|
||||
++ test-jocks
|
||||
^- (list [term @t])
|
||||
:~ [%test-let-edit test-let-edit]
|
||||
==
|
||||
:: :~ let-edit+let-edit
|
||||
:: let-inner-exp+let-inner-exp
|
||||
:: call+call
|
||||
:: axis-call+axis-call
|
||||
:: inline-lambda-call+inline-lambda-call
|
||||
:: in-subj-call+in-subj-call
|
||||
:: if-else+if-else
|
||||
:: assert+assert
|
||||
:: call-let-edit+call-let-edit
|
||||
:: inline-point+inline-point
|
||||
:: inline-lambda-no-arg+inline-lambda-no-arg
|
||||
:: dec-jock+dec-jock
|
||||
:: eval+eval
|
||||
:: multi-limb+multi-limb
|
||||
:: compose+compose
|
||||
:: compose-cores+compose-cores
|
||||
:: baby+baby
|
||||
:: ::comparator+comparator
|
||||
:: ==
|
||||
::
|
||||
++ parse
|
||||
|= i=@
|
||||
^- (list token:jock)
|
||||
=/ p (snag i list-jocks)
|
||||
~| -.p
|
||||
(rash +.p parse-tokens:jock)
|
||||
::
|
||||
++ parse-all
|
||||
^- (list (list token:jock))
|
||||
%+ turn list-jocks
|
||||
|= [=term t=@t]
|
||||
~| term
|
||||
(rash t parse-tokens:jock)
|
||||
::
|
||||
++ jeam
|
||||
|= i=@
|
||||
@ -71,6 +92,20 @@
|
||||
:- -.p
|
||||
(mint:jock +.p)
|
||||
::
|
||||
:: ++ test-all
|
||||
:: ^- (list *)
|
||||
:: %+ turn test-jocks
|
||||
:: |= [=term t=@t]
|
||||
:: ~| term
|
||||
:: (test t)
|
||||
:: ::
|
||||
:: ++ test
|
||||
:: |= i=@
|
||||
:: ^- [term *]
|
||||
:: =/ p (snag i test-jocks)
|
||||
:: ~& test-tokenize:p
|
||||
:: ~
|
||||
::
|
||||
++ exec
|
||||
|= i=@
|
||||
^- *
|
||||
|
103
hoon/lib/test.hoon
Normal file
103
hoon/lib/test.hoon
Normal file
@ -0,0 +1,103 @@
|
||||
:: testing utilities meant to be directly used from files in %/tests
|
||||
::
|
||||
|%
|
||||
:: +expect-eq: compares :expected and :actual and pretty-prints the result
|
||||
::
|
||||
++ expect-eq
|
||||
|= [expected=vase actual=vase]
|
||||
^- tang
|
||||
::
|
||||
=| result=tang
|
||||
::
|
||||
=? result !=(q.expected q.actual)
|
||||
%+ weld result
|
||||
^- tang
|
||||
:~ [%palm [": " ~ ~ ~] [leaf+"expected" (sell expected) ~]]
|
||||
[%palm [": " ~ ~ ~] [leaf+"actual " (sell actual) ~]]
|
||||
==
|
||||
::
|
||||
=? result !(~(nest ut p.actual) | p.expected)
|
||||
%+ weld result
|
||||
^- tang
|
||||
:~ :+ %palm [": " ~ ~ ~]
|
||||
:~ [%leaf "failed to nest"]
|
||||
(~(dunk ut p.actual) %actual)
|
||||
(~(dunk ut p.expected) %expected)
|
||||
== ==
|
||||
result
|
||||
:: +expect: compares :actual to %.y and pretty-prints anything else
|
||||
::
|
||||
++ expect
|
||||
|= actual=vase
|
||||
(expect-eq !>(%.y) actual)
|
||||
:: +expect-fail: kicks a trap, expecting crash. pretty-prints if succeeds
|
||||
::
|
||||
++ expect-fail
|
||||
|= a=(trap)
|
||||
^- tang
|
||||
=/ b (mule a)
|
||||
?- -.b
|
||||
%| ~
|
||||
%& ['expected failure - succeeded' ~]
|
||||
==
|
||||
:: +expect-success: kicks a trap, expecting success; returns trace on failure
|
||||
::
|
||||
++ expect-success
|
||||
|= a=(trap)
|
||||
^- tang
|
||||
=/ b (mule a)
|
||||
?- -.b
|
||||
%& ~
|
||||
%| ['expected success - failed' p.b]
|
||||
==
|
||||
::
|
||||
:: +expect-fail-message: kicks a trap, expecting crash, compares the resulting error message
|
||||
++ expect-fail-message
|
||||
|= [msg=@t a=(trap)]
|
||||
^- tang
|
||||
=/ b (mule a)
|
||||
?- -.b
|
||||
%| |^
|
||||
=/ =tang (flatten +.b)
|
||||
?: ?=(^ (find (trip msg) tang))
|
||||
~
|
||||
['expected error message - not found' ~]
|
||||
++ flatten
|
||||
|= tang=(list tank)
|
||||
=| res=tape
|
||||
|- ^- tape
|
||||
?~ tang res
|
||||
$(tang t.tang, res (weld ~(ram re i.tang) res))
|
||||
--
|
||||
%& ['expected failure - succeeded' ~]
|
||||
==
|
||||
:: $a-test-chain: a sequence of tests to be run
|
||||
::
|
||||
:: NB: arms shouldn't start with `test-` so that `-test % ~` runs
|
||||
::
|
||||
+$ a-test-chain
|
||||
$_
|
||||
|?
|
||||
?: =(0 0)
|
||||
[%& p=*tang]
|
||||
[%| p=[tang=*tang next=^?(..$)]]
|
||||
:: +run-chain: run a sequence of tests, stopping at first failure
|
||||
::
|
||||
++ run-chain
|
||||
|= seq=a-test-chain
|
||||
^- tang
|
||||
=/ res $:seq
|
||||
?- -.res
|
||||
%& p.res
|
||||
%| ?. =(~ tang.p.res)
|
||||
tang.p.res
|
||||
$(seq next.p.res)
|
||||
==
|
||||
:: +category: prepends a name to an error result; passes successes unchanged
|
||||
::
|
||||
++ category
|
||||
|= [a=tape b=tang] ^- tang
|
||||
?: =(~ b) ~ :: test OK
|
||||
:- leaf+"in: '{a}'"
|
||||
(turn b |=(c=tank rose+[~ " " ~]^~[c]))
|
||||
--
|
9
hoon/lib/tests/if-elseif-else.jock
Normal file
9
hoon/lib/tests/if-elseif-else.jock
Normal file
@ -0,0 +1,9 @@
|
||||
let a: @ = 3;
|
||||
|
||||
if a == 3 {
|
||||
72
|
||||
} else if a == 5 {
|
||||
17
|
||||
} else {
|
||||
15
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
/+ *wrapper, test-jock
|
||||
/+ jock,
|
||||
test-jock,
|
||||
*wrapper
|
||||
=>
|
||||
|%
|
||||
+$ test-state ~
|
||||
@ -36,6 +38,11 @@
|
||||
?~ soft-cau
|
||||
~& "could not mold poke type: {<dat>}" !!
|
||||
=/ c=cause u.soft-cau
|
||||
~& exec-all:test-jock
|
||||
~& parse-all:test-jock
|
||||
~& jeam-all:test-jock
|
||||
~& mint-all:test-jock
|
||||
~& test-all:test-jock
|
||||
?- -.c
|
||||
%test-n [~ k]
|
||||
%test-all [~ k]
|
||||
|
21
hoon/tests/lib/let-edit.hoon
Normal file
21
hoon/tests/lib/let-edit.hoon
Normal file
@ -0,0 +1,21 @@
|
||||
/+ jock,
|
||||
test
|
||||
::
|
||||
|%
|
||||
++ text
|
||||
'let a:? = true;\0aa = false;\0aa'
|
||||
++ test-tokenize
|
||||
%+ expect-eq:test
|
||||
!> ~[[%keyword %let] [%name %a] [%punctuator %':'] [%punctuator %'?'] [%punctuator %'='] [%literal [%loobean %.y]] [%punctuator %';'] [%name %a] [%punctuator %'='] [%literal [%loobean %.n]] [%punctuator %';'] [%name %a]]
|
||||
!> (rash text parse-tokens:jock)
|
||||
::
|
||||
++ test-jeam
|
||||
%+ expect-eq:test
|
||||
!> ~[%let type=[p=[%atom p=%loobean] name=%a] val=[%atom p=[%loobean %.y]] next=[%edit limb=~[[%name p=%a]] val=[%atom p=[%loobean %.n]] next=[%limb p=~[[%name p=%a]]]]]
|
||||
!> (jeam:jock txt)
|
||||
::
|
||||
++ test-mint
|
||||
%+ expect-eq:test
|
||||
!> [8 [1 0] 7 [10 [2 1 1] 0 1] 0 2]
|
||||
!> (mint:jock txt)
|
||||
--
|
Loading…
Reference in New Issue
Block a user