test update

This commit is contained in:
jackfoxy 2024-01-13 15:08:56 -08:00
parent 23d6f3bf2c
commit 3a5887e3da
2 changed files with 176 additions and 146 deletions

89
urql/lib/test.hoon Executable file → Normal file
View File

@ -1,28 +1,73 @@
:: testing utilities meant to be directly used from files in %/tests
::
|%
::
:: +vary: pretty-print diff between two vases using +sell.
::
++ vary
|= [vax=vase vas=vase]
^- (pair tank tank)
~| %vary
=. p.vas (wipe p.vas)
=. p.vas (~(redo ut p.vas) p.vax)
[(sell vax) (sell vas)]
::
:: +dunt: pretty-print diff between two types using +dunk.
::
++ dunt
|= [ref=[p=term q=type] sut=[p=term q=type]]
^- (pair tank tank)
=. q.ref (wipe q.ref)
=. q.ref (~(redo ut q.ref) q.sut)
[(~(dunk ut q.ref) p.ref) (~(dunk ut q.sut) p.sut)]
::
:: +wipe: clear type faces.
::
++ wipe
|= sut=type
^- type
=+ gil=*(set type)
|-
?+ sut sut
[%cell *] [%cell $(sut p.sut) $(sut q.sut)]
[%face *] $(sut q.sut)
[%fork *] (fork (turn ~(tap in p.sut) |=(=type ^$(sut type))))
[%hint *] (hint p.sut $(sut q.sut))
[%hold *]
?: (~(has in gil) sut) sut
$(gil (~(put in gil) sut), sut ~(repo ut sut))
==
::
--
|%
:: +expect-eq: compares :expected and :actual and pretty-prints the result
::
++ expect-eq
|= [expected=vase actual=vase]
^- tang
::
::~& "expected: {<q.expected>}"
::~& ""
::~& "actual: {<q.actual>}"
::
=| result=tang
::
=? result !=(q.expected q.actual)
=/ diff=(pair tank tank) (vary [expected actual])
%+ weld result
^- tang
:~ [%palm [": " ~ ~ ~] [leaf+"expected" (sell expected) ~]]
[%palm [": " ~ ~ ~] [leaf+"actual " (sell actual) ~]]
:~ [%palm [": " ~ ~ ~] [leaf+"expected" p.diff ~]]
[%palm [": " ~ ~ ~] [leaf+"actual " q.diff ~]]
==
::
=? result !(~(nest ut p.actual) | p.expected)
=/ diff=(pair tank tank) (dunt [[%actual p.actual] [%expected p.expected]])
%+ weld result
^- tang
:~ :+ %palm [": " ~ ~ ~]
:~ [%leaf "failed to nest"]
(~(dunk ut p.actual) %actual)
(~(dunk ut p.expected) %expected)
p.diff
q.diff
== ==
result
:: +expect: compares :actual to %.y and pretty-prints anything else
@ -38,7 +83,39 @@
=/ b (mule a)
?- -.b
%| ~
%& [leaf+"expected failure - succeeded" ~]
%& ['expected failure - succeeded' ~]
==
:: +expect-runs: kicks a trap, expecting success; returns trace on failure
::
++ expect-success
|= a=(trap)
^- tang
=/ b (mule a)
?- -.b
%& ~
%| ['expected success - failed' p.b]
==
:: $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
::
@ -47,4 +124,4 @@
?: =(~ b) ~ :: test OK
:- leaf+"in: '{a}'"
(turn b |=(c=tank rose+[~ " " ~]^~[c]))
--
--

View File

@ -2,155 +2,108 @@
/+ parse, *test
|%
++ column-foo [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foo'] column='foo' alias=~]
++ column-bar [%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='bar'] column='bar' alias=~]
++ all-columns [%qualified-object ship=~ database='ALL' namespace='ALL' name='ALL']
++ select-all-columns [%select top=~ bottom=~ columns=~[all-columns]]
++ col1
[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='col1'] column='col1' alias=~]
++ col2
[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='col2'] column='col2' alias=~]
++ col3
[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='col3'] column='col3' alias=~]
++ col4
[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='col4'] column='col4' alias=~]
++ delete-pred
`[%eq [column-foo ~ ~] [column-bar ~ ~]]
++ cte-t1
[%cte name='t1' [%query ~ scalars=~ predicate=~ group-by=~ having=~ selection=select-all-columns ~]]
++ cte-foobar
[%cte name='foobar' [%query [~ [%from object=[%table-set object=[%qualified-object ship=~ database='db1' namespace='dbo' name='foobar'] alias=~] joins=~]] scalars=~ `[%eq [col1 ~ ~] [[value-type=%ud value=2] ~ ~]] group-by=~ having=~ [%select top=~ bottom=~ columns=~[col3 col4]] ~]]
++ cte-bar
[%cte name='bar' [%query [~ [%from object=[%table-set object=[%qualified-object ship=~ database='db1' namespace='dbo' name='bar'] alias=~] joins=~]] scalars=~ `[%eq [col1 ~ ~] [col2 ~ ~]] group-by=~ having=~ [%select top=~ bottom=~ columns=~[col2]] ~]]
++ foo-table
[%qualified-object ship=~ database='db1' namespace='dbo' name='foo']
++ update-pred
[%and one-eq-1 [%eq [col2 ~ ~] [[value-type=%ud value=4] ~ ~]]]
++ one-eq-1
[%eq [literal-1 ~ ~] [literal-1 ~ ~]]
++ literal-1 [value-type=%ud value=1]
::@@@@@@@@@@@@@@@@@@@@@@@@@
:: re-used components
++ all-columns [%qualified-object ship=~ database='ALL' namespace='ALL' name='ALL']
++ select-all-columns [%select top=~ bottom=~ columns=~[all-columns]]
++ foo
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo'] 'foo' ~] ~ ~]
++ t1-foo
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo' ~] ~ ~]
++ foo2
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo2'] 'foo2' ~] ~ ~]
++ t1-foo2
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo2' ~] ~ ~]
++ foo3
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo3'] 'foo3' ~] ~ ~]
++ t1-foo3
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T1'] 'foo3' ~] ~ ~]
++ foo4
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo4'] 'foo4' ~] ~ ~]
++ foo5
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo5'] 'foo5' ~] ~ ~]
++ foo6
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo6'] 'foo6' ~] ~ ~]
++ foo7
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foo7'] 'foo7' ~] ~ ~]
++ bar
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'bar'] 'bar' ~] ~ ~]
++ t2-bar
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'T2'] 'bar' ~] ~ ~]
++ foobar
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN-OR-CTE' 'foobar'] 'foobar' ~] ~ ~]
++ a1-adoption-email
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'adoption-email' ~] ~ ~]
++ a2-adoption-email
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'adoption-email' ~] ~ ~]
++ a1-adoption-date
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'adoption-date' ~] ~ ~]
++ a2-adoption-date
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'adoption-date' ~] ~ ~]
++ a1-name
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'name' ~] ~ ~]
++ a2-name
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'name' ~] ~ ~]
++ a1-species
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A1'] 'species' ~] ~ ~]
++ a2-species
[[%qualified-column [%qualified-object ~ 'UNKNOWN' 'COLUMN' 'A2'] 'species' ~] ~ ~]
++ value-literals [[%value-literals %ud '3;2;1'] ~ ~]
++ aggregate-count-foobar
[%aggregate function='count' source=[%qualified-column qualifier=[%qualified-object ship=~ database='UNKNOWN' namespace='COLUMN-OR-CTE' name='foobar'] column='foobar' alias=~]]
++ literal-10 [[%ud 10] ~ ~]
::
:: drop namespace
:: re-used simple predicates
++ foobar-gte-foo [%gte foobar foo]
++ foobar-lte-bar [%lte foobar bar]
++ foo-eq-1 [%eq foo [[%ud 1] ~ ~]]
++ t1-foo-gt-foo2 [%gt t1-foo foo2]
++ t2-bar-in-list [%in t2-bar value-literals]
++ t1-foo2-eq-zod [%eq t1-foo2 [[%p 0] ~ ~]]
++ t1-foo3-lt-any-list [%lt t1-foo3 [%any value-literals ~]]
::
:: tests 1, 2, 3, 5, and extra whitespace characters, force db.name, name
++ test-drop-namespace-00
=/ expected1 [%drop-namespace database-name='db' name='name' force=%.n as-of=~]
=/ expected2 [%drop-namespace database-name='other-db' name='name' force=%.y as-of=~]
%+ expect-eq
!> ~[expected1 expected2]
!> (parse:parse(default-database 'other-db') "droP Namespace db.name;droP \0d\09 Namespace FORce \0a name")
:: re-used predicates with conjunctions
++ and-fb-gte-f--fb-lte-b [%and foobar-gte-foo foobar-lte-bar]
++ and-fb-gte-f--t1f2-eq-z [%and foobar-gte-foo t1-foo2-eq-zod]
++ and-f-eq-1--t1f3-lt-any [%and foo-eq-1 t1-foo3-lt-any-list]
++ and-and [%and and-fb-gte-f--fb-lte-b t1-foo2-eq-zod]
++ and-and-or [%or and-and t2-bar-in-list]
++ and-and-or-and [%or and-and and-fb-gte-f--t1f2-eq-z]
++ and-and-or-and-or-and [%or and-and-or-and and-f-eq-1--t1f3-lt-any]
::
:: leading and trailing whitespace characters, end delimiter not required on single, force name
++ test-drop-namespace-01
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='name' force=%.y as-of=~]]
!> (parse:parse(default-database 'other-db') " \09drOp\0d\09 naMespace\0a force name ")
::
:: db.name
++ test-drop-namespace-02
%+ expect-eq
!> ~[[%drop-namespace database-name='db' name='name' force=%.n as-of=~]]
!> (parse:parse(default-database 'other-db') "drop namespace db.name")
::
:: name, as of now
++ test-drop-namespace-03
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='ns1' force=%.n as-of=~]]
!> (parse:parse(default-database 'other-db') "drop namespace ns1 as of now")
::
:: name, as of date
++ test-drop-namespace-04
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='ns1' force=%.n as-of=[~ [%da ~2023.12.25..7.15.0..1ef5]]]]
!> (parse:parse(default-database 'other-db') "drop namespace ns1 as of ~2023.12.25..7.15.0..1ef5")
::
:: name, as of 5 seconds ago
++ test-drop-namespace-05
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='ns1' force=%.n as-of=[~ [%as-of-offset 5 %seconds]]]]
!> (parse:parse(default-database 'other-db') "drop namespace ns1 as of 5 seconds ago")
::
:: force name as of now
++ test-drop-namespace-06
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='ns1' force=%.y as-of=~]]
!> (parse:parse(default-database 'other-db') "drop namespace force ns1 as of now")
::
:: force name as of date
++ test-drop-namespace-07
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='ns1' force=%.y as-of=[~ [%da ~2023.12.25..7.15.0..1ef5]]]]
!> (parse:parse(default-database 'other-db') "drop namespace force ns1 as of ~2023.12.25..7.15.0..1ef5")
::
:: force name as of 5 seconds ago
++ test-drop-namespace-08
%+ expect-eq
!> ~[[%drop-namespace database-name='other-db' name='ns1' force=%.y as-of=[~ [%as-of-offset 5 %seconds]]]]
!> (parse:parse(default-database 'other-db') "drop namespace force ns1 as of 5 seconds ago")
::
:: db name as of now
++ test-drop-namespace-09
%+ expect-eq
!> ~[[%drop-namespace database-name='db1' name='ns1' force=%.n as-of=~]]
!> (parse:parse(default-database 'other-db') "drop namespace db1.ns1 as of now")
::
:: db name as of date
++ test-drop-namespace-10
%+ expect-eq
!> ~[[%drop-namespace database-name='db1' name='ns1' force=%.n as-of=[~ [%da ~2023.12.25..7.15.0..1ef5]]]]
!> (parse:parse(default-database 'other-db') "drop namespace db1.ns1 as of ~2023.12.25..7.15.0..1ef5")
::
:: db name as of 5 seconds ago
++ test-drop-namespace-11
%+ expect-eq
!> ~[[%drop-namespace database-name='db1' name='ns1' force=%.n as-of=[~ [%as-of-offset 5 %seconds]]]]
!> (parse:parse(default-database 'other-db') "drop namespace db1.ns1 as of 5 seconds ago")
::
:: force db name as of
++ test-drop-namespace-12
%+ expect-eq
!> ~[[%drop-namespace database-name='db1' name='ns1' force=%.y as-of=~]]
!> (parse:parse(default-database 'other-db') "drop namespace force db1.ns1 as of now")
::
:: force db name as of
++ test-drop-namespace-13
%+ expect-eq
!> ~[[%drop-namespace database-name='db1' name='ns1' force=%.y as-of=[~ [%da ~2023.12.25..7.15.0..1ef5]]]]
!> (parse:parse(default-database 'other-db') "drop namespace force db1.ns1 as of ~2023.12.25..7.15.0..1ef5")
::
:: force db name as of
++ test-drop-namespace-14
%+ expect-eq
!> ~[[%drop-namespace database-name='db1' name='ns1' force=%.y as-of=[~ [%as-of-offset 15 %minutes]]]]
!> (parse:parse(default-database 'other-db') "drop namespace force db1.ns1 as of 15 minutes ago")
::
:: fail when database qualifier is not a term
++ test-fail-drop-namespace-15
%- expect-fail
|. (parse:parse(default-database 'other-db') "DROP NAMESPACE Db.name")
::
:: fail when namespace is not a term
++ test-fail-drop-namespace-16
%- expect-fail
|. (parse:parse(default-database 'other-db') "DROP NAMESPACE nAme")
:: predicates with conjunctions and nesting
++ and-fb-gt-f--fb-lt-b [%and [%gt foobar foo] [%lt foobar bar]]
++ and-t1f-gt-f2--t2b-in-l [%and t1-foo-gt-foo2 t2-bar-in-list]
++ or2 [%and [%and t1-foo3-lt-any-list t1-foo2-eq-zod] foo-eq-1]
++ or3 [%and [%eq foo3 foo4] [%eq foo5 foo6]]
++ big-or [%or [%or [%or and-t1f-gt-f2--t2b-in-l or2] or3] [%eq foo4 foo5]]
++ big-and [%and and-fb-gt-f--fb-lt-b big-or]
++ a-a-l-a-o-l-a-a-r-o-r-a-l-o-r-a
[%and big-and [%eq foo6 foo7]]
++ first-or [%or [%gt foobar foo] [%lt foobar bar]]
++ last-or [%or t1-foo3-lt-any-list [%and t1-foo2-eq-zod foo-eq-1]]
++ first-and [%and first-or t1-foo-gt-foo2]
++ second-and [%and first-and t2-bar-in-list]
++ king-and [%and [second-and] last-or]
::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
::
:: expected/actual match
::++ test-predicate-26
:: =/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
:: " WHERE foobar >=foo And foobar<=bar ".
:: " and T1.foo2 = ~zod ".
:: " SELECT *"
:: =/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
:: =/ pred=(tree predicate-component:ast) and-and
:: =/ expected=simple-query:ast
:: [%simple-query [~ [%from object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%query-object object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] scalars=~ `pred group-by=~ having=~ select-all-columns ~]
:: %+ expect-eq
:: !> ~[expected]
:: !> (parse:parse(current-database 'db1') query)
++ test-predicate-26
=/ query "FROM adoptions AS T1 JOIN adoptions AS T2 ON T1.foo = T2.bar ".
" WHERE foobar >=foo And foobar<=bar ".
" and T1.foo2 = ~zod ".
" SELECT *"
=/ joinpred=(tree predicate-component:ast) [%eq t1-foo t2-bar]
=/ pred=(tree predicate-component:ast) and-and
=/ expected
[%transform ctes=~ [[%query [~ [%from object=[%table-set object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T1']] joins=~[[%joined-object join=%join object=[%table-set object=[%qualified-object ship=~ database='db1' namespace='dbo' name='adoptions'] alias=[~ 'T2']] predicate=`joinpred]]]] scalars=~ `pred group-by=~ having=~ select-all-columns ~] ~ ~]]
%+ expect-eq
!> ~[expected]
!> (parse:parse(default-database 'db1') query)
--