Skip to content

Commit

Permalink
contacts: implement number field type %quot
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolajpp committed Sep 19, 2024
1 parent fbda123 commit 90c93f5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
6 changes: 6 additions & 0 deletions desk/lib/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
~| "{<typ>} expected at {<key>}"
?- typ
%text ?>(?=(%text -.u.val) (some p.u.val))
%quot ?>(?=(%quot -.u.val) (some p.u.val))
%date ?>(?=(%date -.u.val) (some p.u.val))
%tint ?>(?=(%tint -.u.val) (some p.u.val))
%ship ?>(?=(%ship -.u.val) (some p.u.val))
Expand All @@ -35,6 +36,7 @@
%- ~(run in p.u.val)
?- typ
%text |=(v=value ?>(?=(%text -.v) v))
%quot |=(v=value ?>(?=(%quot -.v) v))
%date |=(v=value ?>(?=(%date -.v) v))
%tint |=(v=value ?>(?=(%tint -.v) v))
%ship |=(v=value ?>(?=(%ship -.v) v))
Expand All @@ -53,6 +55,7 @@
%- ~(run in p.val)
?- typ
%text |=(v=value ?>(?=(%text -.v) v))
%quot |=(v=value ?>(?=(%quot -.v) v))
%date |=(v=value ?>(?=(%date -.v) v))
%tint |=(v=value ?>(?=(%tint -.v) v))
%ship |=(v=value ?>(?=(%ship -.v) v))
Expand All @@ -71,6 +74,7 @@
~| "{<-.def>} expected at {<key>}"
?- -.val
%text ?>(?=(%text -.def) p.val)
%quot ?>(?=(%quot -.def) p.val)
%date ?>(?=(%date -.def) p.val)
%tint ?>(?=(%tint -.def) p.val)
%ship ?>(?=(%ship -.def) p.val)
Expand All @@ -87,6 +91,7 @@
?~ val
?+ typ !!
%text *@t
%quot *@ud
%date *@da
%tint *@ux
%ship *@p
Expand All @@ -97,6 +102,7 @@
~| "{<typ>} expected at {<key>}"
?- typ
%text ?>(?=(%text -.val) p.val)
%quot ?>(?=(%quot -.val) p.val)
%date ?>(?=(%date -.val) p.val)
%tint ?>(?=(%tint -.val) p.val)
%ship ?>(?=(%ship -.val) p.val)
Expand Down
2 changes: 2 additions & 0 deletions desk/lib/contacts/json-1.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
^- json
?- -.val
%text (pairs type+s/%text value+s/p.val ~)
%quot (pairs type+s/%quot value+(numb p.val) ~)
%date (pairs type+s/%date value+s/(scot %da p.val) ~)
%tint (pairs type+s/%tint value+s/(rsh 3^2 (scot %ux p.val)) ~)
%ship (pairs type+s/%ship value+(ship p.val) ~)
Expand Down Expand Up @@ -117,6 +118,7 @@
(ot text+(se %tas) value+json ~)
?+ type !!
%text %. val (ta %text so)
%quot %. val (ta %quot ni)
%date %. val (ta %date (se %da))
%tint %. val
%+ ta %tint
Expand Down
3 changes: 2 additions & 1 deletion desk/sur/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
::
+$ value-type
$? %text
%quot
%date
%tint
%look
Expand All @@ -32,7 +33,7 @@
$+ contact-value
$@ ~
$% [%text p=@t]
:: [%quot p=@ud]
[%quot p=@ud]
[%date p=@da]
::
:: color
Expand Down
34 changes: 19 additions & 15 deletions desk/tests/lib/contacts-json-1.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,68 @@
|= [a=vase b=vase]
(expect-eq b a)
::
++ jex-equal
++ jen-equal
|= [jon=json txt=@t]
%+ ex-equal
!> (en:json:html jon)
!> txt
::
++ test-ship
%+ jex-equal
%+ jen-equal
(ship:enjs:j ~sampel-palnet)
'"~sampel-palnet"'
++ test-cid
%+ jex-equal
%+ jen-equal
(cid:enjs:j 0v11abc)
'"0v11abc"'
++ test-kip
;: weld
%+ jex-equal
%+ jen-equal
(kip:enjs:j ~sampel-palnet)
'"~sampel-palnet"'
::
%+ jex-equal
%+ jen-equal
(kip:enjs:j id+0v11abc)
'"0v11abc"'
==
++ test-value
;: weld
::
%+ jex-equal
(value:enjs:j [%text 'the lazy fox'])
%+ jen-equal
(value:enjs:j text+'the lazy fox')
'{"type":"text","value":"the lazy fox"}'
::
%+ jex-equal
(value:enjs:j [%date ~2024.9.11])
%+ jen-equal
(value:enjs:j quot+42)
'{"type":"quot","value":42}'
::
%+ jen-equal
(value:enjs:j date+~2024.9.11)
'{"type":"date","value":"~2024.9.11"}'
::
%+ jex-equal
%+ jen-equal
(value:enjs:j [%tint 0xcafe.babe])
'{"type":"tint","value":"cafe.babe"}'
::
%+ jex-equal
%+ jen-equal
(value:enjs:j [%ship ~sampel-palnet])
'{"type":"ship","value":"~sampel-palnet"}'
::
%+ jex-equal
%+ jen-equal
(value:enjs:j [%look 'https://ship.io/avatar.png'])
'{"type":"look","value":"https://ship.io/avatar.png"}'
::
%+ jex-equal
%+ jen-equal
(value:enjs:j [%cult [~sampel-palnet %circle]])
'{"type":"cult","value":"~sampel-palnet/circle"}'
::
%+ jex-equal
%+ jen-equal
%- value:enjs:j
[%set (silt `(list value)`~[cult/[~sampel-palnet %circle] cult/[~sampel-pardux %square]])]
'{"type":"set","value":[{"type":"cult","value":"~sampel-palnet/circle"},{"type":"cult","value":"~sampel-pardux/square"}]}'
==
++ test-contact
%+ jex-equal
%+ jen-equal
%- contact:enjs:j
%- malt
^- (list [@tas value])
Expand Down

0 comments on commit 90c93f5

Please sign in to comment.