Skip to content

Commit

Permalink
contacts: fix %contact-action-1 JSON conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Oct 25, 2024
1 parent f2d8064 commit 505ceb8
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 28 deletions.
2 changes: 1 addition & 1 deletion desk/lib/contacts/json-1.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
::
=/ [type=@tas val=json]
%. jon
(ot text+(se %tas) value+json ~)
(ot type+(se %tas) value+json ~)
?+ type !!
%text %. val (ta %text so)
%numb %. val (ta %numb ni)
Expand Down
168 changes: 141 additions & 27 deletions desk/tests/lib/contacts-json-1.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,187 @@
|= [a=vase b=vase]
(expect-eq b a)
::
++ jen-equal
++ enjs-equal
|= [jon=json txt=@t]
%+ ex-equal
!> (en:json:html jon)
!> txt
::
++ dejs-equal
|* [saf=$-(json *) txt=@t data=*]
%+ ex-equal
!> (saf (need (de:json:html txt)))
!> data
::
++ test-ship
%+ jen-equal
(ship:enjs:j ~sampel-palnet)
'"~sampel-palnet"'
;: weld
%+ enjs-equal
(ship:enjs:j ~sampel-palnet)
'"~sampel-palnet"'
::
%^ dejs-equal ship:dejs:j
'"~sampel-palnet"'
~sampel-palnet
==
++ test-cid
%+ jen-equal
(cid:enjs:j 0v11abc)
'"0v11abc"'
;: weld
%+ enjs-equal
(cid:enjs:j 0v11abc)
'"0v11abc"'
::
%^ dejs-equal cid:dejs:j
'"0v11abc"'
0v11abc
==
++ test-kip
;: weld
%+ jen-equal
%+ enjs-equal
(kip:enjs:j ~sampel-palnet)
'"~sampel-palnet"'
::
%+ jen-equal
%+ enjs-equal
(kip:enjs:j id+0v11abc)
'"0v11abc"'
::
%^ dejs-equal kip:dejs:j
'"~sampel-palnet"'
~sampel-palnet
::
%^ dejs-equal kip:dejs:j
'"0v11abc"'
id+0v11abc
==
++ test-value
;: weld
::
%+ jen-equal
(value:enjs:j text+'the lazy fox')
%+ enjs-equal
(value:enjs:j text+'the lazy fox')
'{"type":"text","value":"the lazy fox"}'
::
%+ jen-equal
(value:enjs:j numb+42)
%^ dejs-equal value:dejs:j
'{"type":"text","value":"the lazy fox"}'
text+'the lazy fox'
::
%+ enjs-equal
(value:enjs:j numb+42)
'{"type":"numb","value":42}'
::
%+ jen-equal
%^ dejs-equal value:dejs:j
'{"type":"numb","value":42}'
numb+42
::
%+ enjs-equal
(value:enjs:j date+~2024.9.11)
'{"type":"date","value":"~2024.9.11"}'
::
%+ jen-equal
(value:enjs:j [%tint 0xcafe.babe])
%^ dejs-equal value:dejs:j
'{"type":"date","value":"~2024.9.11"}'
date+~2024.9.11
::
%+ enjs-equal
(value:enjs:j tint+0xcafe.babe)
'{"type":"tint","value":"cafe.babe"}'
::
%+ jen-equal
(value:enjs:j [%ship ~sampel-palnet])
%^ dejs-equal value:dejs:j
'{"type":"tint","value":"cafe.babe"}'
tint+0xcafe.babe
::
%+ enjs-equal
(value:enjs:j ship+~sampel-palnet)
'{"type":"ship","value":"~sampel-palnet"}'
::
%+ jen-equal
(value:enjs:j [%look 'https://ship.io/avatar.png'])
%^ dejs-equal value:dejs:j
'{"type":"ship","value":"~sampel-palnet"}'
ship+~sampel-palnet
::
%+ enjs-equal
(value:enjs:j look+'https://ship.io/avatar.png')
'{"type":"look","value":"https://ship.io/avatar.png"}'
::
%+ jen-equal
(value:enjs:j [%flag [~sampel-palnet %circle]])
%^ dejs-equal value:dejs:j
'{"type":"look","value":"https://ship.io/avatar.png"}'
look+'https://ship.io/avatar.png'
::
%+ enjs-equal
(value:enjs:j flag+[~sampel-palnet %circle])
'{"type":"flag","value":"~sampel-palnet/circle"}'
::
%+ jen-equal
%^ dejs-equal value:dejs:j
'{"type":"flag","value":"~sampel-palnet/circle"}'
flag+[~sampel-palnet %circle]
::
%+ enjs-equal
%- value:enjs:j
[%set (silt `(list value)`~[flag/[~sampel-palnet %circle] flag/[~sampel-pardux %square]])]
set+(silt `(list value)`~[flag/[~sampel-palnet %circle] flag/[~sampel-pardux %square]])
'{"type":"set","value":[{"type":"flag","value":"~sampel-palnet/circle"},{"type":"flag","value":"~sampel-pardux/square"}]}'
::
%^ dejs-equal value:dejs:j
'{"type":"set","value":[{"type":"flag","value":"~sampel-palnet/circle"},{"type":"flag","value":"~sampel-pardux/square"}]}'
set+(silt `(list value)`~[flag/[~sampel-palnet %circle] flag/[~sampel-pardux %square]])
==
++ test-contact
%+ jen-equal
%- contact:enjs:j
;: weld
%+ enjs-equal
%- contact:enjs:j
%- malt
^- (list [@tas value])
:~ name+text/'Sampel'
surname+text/'Palnet'
==
'{"name":{"type":"text","value":"Sampel"},"surname":{"type":"text","value":"Palnet"}}'
::
%^ dejs-equal contact:dejs:j
'{"name":{"type":"text","value":"Sampel"},"surname":{"type":"text","value":"Palnet"}}'
^- contact:c
%- malt
^- (list [@tas value])
:~ name+text/'Sampel'
surname+text/'Palnet'
==
'{"name":{"type":"text","value":"Sampel"},"surname":{"type":"text","value":"Palnet"}}'
==
++ test-action
=/ con=contact:c
%- malt
^- (list [@tas value])
:~ name+text/'Sampel'
==
=/ mod=contact:c
%- malt
^- (list [@tas value])
:~ surname+text/'Palnet'
==
::
;: weld
%^ dejs-equal action:dejs:j
'{"anon":null}'
[%anon ~]
::
%^ dejs-equal action:dejs:j
'{"self":{"name":{"type":"text","value":"Sampel"}}}'
[%self con]
::
%^ dejs-equal action:dejs:j
'{"page":{"kip":"0v1","contact":{"surname":{"type":"text","value":"Palnet"}}}}'
[%page id+0v1 mod]
::
%^ dejs-equal action:dejs:j
'{"page":{"kip":"~sampel-palnet","contact":{"surname":{"type":"text","value":"Palnet"}}}}'
[%page ~sampel-palnet mod]
::
%^ dejs-equal action:dejs:j
'{"wipe":["0v1", "0v2", "~sampel-palnet"]}'
[%wipe id+0v1 id+0v2 ~sampel-palnet ~]
::
%^ dejs-equal action:dejs:j
'{"meet":["~sampel-palnet", "~master-botnet"]}'
[%meet ~sampel-palnet ~master-botnet ~]
::
%^ dejs-equal action:dejs:j
'{"drop":["~sampel-palnet", "~master-botnet"]}'
[%drop ~sampel-palnet ~master-botnet ~]
::
%^ dejs-equal action:dejs:j
'{"snub":["~sampel-palnet", "~master-botnet"]}'
[%snub ~sampel-palnet ~master-botnet ~]
==
--

0 comments on commit 505ceb8

Please sign in to comment.