plunder

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

test_stroll.sire (10098B)


      1 ; Copyright 2023 The Plunder Authors
      2 ; Use of this source code is governed by a BSD-style license that can be
      3 ; found in the LICENSE file.
      4 
      5 #### test_stroll <- test_datom
      6 
      7 :| sire
      8 :| datom
      9 :| stroll
     10 :| stew
     11 
     12 
     13 ;;; Utils ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     14 
     15 = notesDB
     16 ^ assertTransactStrollDb _ | emptyStrollDb 42
     17 ++ ## ={:db/id} %[{plunder page}]
     18    ## ={:page/title} {Plunder}
     19    ## ={:block/uid} {TtzFH-Ym1}
     20    ## ={:block/children}
     21       ++ ## ={:block/string} {Members}
     22          ## ={:block/uid} {r0wrZ2qQL}
     23          ## ={:block/order} 0
     24          ## ={:block/page} %[{plunder page}]
     25          ## ={:block/children}
     26             ++ ## ={:block/string} {[[Iceman]]}
     27                ## ={:block/uid} {3LKryaGyF}
     28                ## ={:block/order} 0
     29                ## ={:block/page} %[{plunder page}]
     30                ## ={:block/refs} %[{iceman page}]
     31                ## ={:block/children}
     32                   ++ ## ={:block/string} {((b2fdrwjXZ))}
     33                      ## ={:block/uid} {D_fFfQNlb}
     34                      ## ={:block/order} 0
     35                      ## ={:block/page} %[{plunder page}]
     36                      ## ={:block/refs} %[{b2fdrwjXZ}] ; ref
     37             ++ ## ={:block/string} {[[Sol]]}
     38                ## ={:block/uid} {o-_aIaa83}
     39                ## ={:block/order} 1
     40                ## ={:block/page} %[{plunder page}]
     41                ## ={:block/refs} %[{sol page}]
     42                ## ={:block/children}
     43                   ++ ## ={:block/string} {((16M_lgxfk))}
     44                      ## ={:block/uid} {xYAA9mPYv}
     45                      ## ={:block/order} 0
     46                      ## ={:block/page} %[{plunder page}]
     47                      ## ={:block/refs} %[{16M_lgxfk}]
     48 ++ ## ={:db/id} %[{iceman page}]
     49    ## ={:page/title} {Iceman}
     50    ## ={:block/uid} {pnKunZ4If}
     51    ## ={:block/children}
     52       ++ ## ={:block/string} {Currently working on}
     53          ## ={:block/uid} {5COIJVctB}
     54          ## ={:block/order} 0
     55          ## ={:block/page} %[{iceman page}]
     56          ## ={:block/children}
     57             ++ ## ={:db/id} %[{b2fdrwjXZ}]
     58                ## ={:block/string} {Datom}
     59                ## ={:block/uid} {b2fdrwjXZ}
     60                ## ={:block/order} 0
     61                ## ={:block/page} %[{iceman page}]
     62 ++ ## ={:db/id} %[{sol page}]
     63    ## ={:page/title} {Sol}
     64    ## ={:block/uid} {1NLcDwisF}
     65    ## ={:block/children}
     66       ++ ## ={:block/string} {Currently working on}
     67          ## ={:block/uid} {yzo5F7CVd}
     68          ## ={:block/order} 0
     69          ## ={:block/page} %[{sol page}]
     70          ## ={:block/children}
     71             ++ ## ={:db/id} %[{16M_lgxfk}]
     72                ## ={:block/string} {Compiler}
     73                ## ={:block/uid} {16M_lgxfk}
     74                ## ={:block/order} 0
     75                ## ={:block/page} %[{sol page}]
     76 
     77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     78 ; Conceptual demo:
     79 ;
     80 ; Here we try to break down the workflow of reading and writing.
     81 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     82 
     83 ;
     84 ;; Case 1: Grab blocks under the main Plunder page.
     85 ;
     86 
     87 ; Gets the toplevel block for the Plunder page.
     88 = plunderPage
     89 | assertRight | findPageBlock {Plunder} notesDB
     90 
     91 ; Gets the one "Members" block that's on the Plunder page.
     92 = membersBlock
     93 @ q | makeOrderedChildrenQuery plunderPage
     94 | idx 0 | assertRight | findBlocksContent q notesDB
     95 
     96 ; Gets the two blocks under Members in sorted order.
     97 = (memberBlockContents membersBlock db)
     98 @ q | makeOrderedChildrenQuery membersBlock
     99 | assertRight | findBlocksContent q db
    100 
    101 =?= (memberBlockContents membersBlock notesDB)
    102  ++  ## ={:block/uid} {3LKryaGyF}
    103      ## ={:block/string} {[[Iceman]]}
    104      ## ={:block/children}
    105         [#[{:block/uid}={D_fFfQNlb} {:block/order}=0]]
    106  ++  ## ={:block/uid} {o-_aIaa83}
    107      ## ={:block/string} {[[Sol]]}
    108      ## ={:block/children}
    109         [#[{:block/uid}={xYAA9mPYv} {:block/order}=0]]
    110 
    111 ; Notes: Not entirely happy with the above. Doing this as a bunch of
    112 ; separate lookups seems questionable and likely to result in inconsistent
    113 ; views if the database is modified mid-read. A real implementation also needs
    114 ; to do binding of an entity to a UI element with subscriptions.
    115 ;
    116 
    117 ;
    118 ;; Case 2: Get the "linked references" section of a page.
    119 ;
    120 ; Roam's big idea is that for every item (page or block) that you view, you can
    121 ; see all things which reference it in context. So find out all the blocks which
    122 ; reference the Iceman page, their uid and the title of the page they are on.
    123 ;
    124 
    125 = icemanPage
    126 | assertRight | findPageBlock {Iceman} notesDB
    127 
    128 = referencingBlocks
    129 | findPageBlocksReferencing icemanPage notesDB
    130 
    131 =?=    referencingBlocks
    132     ++  1
    133     ++  ## ={:block/refs}
    134             ++  ## ={:block/uid} {3LKryaGyF}
    135                 ## ={:block/page}
    136                    [#[{:block/uid}={TtzFH-Ym1} {:page/title}=[%Plunder]]]
    137 
    138 ; Notes: The referencing blocks query above really would work better as a
    139 ; :query
    140 
    141 ;
    142 ;; Case 3: Inserting a new bullet under an item.
    143 ;
    144 ; So you're cursor is on a bullet, but now you want a NEW bullet after
    145 ; that. Whoah!
    146 ;
    147 ; Test that we move all bullet points around correctly
    148 
    149 ; Insert at beginning
    150 =?=    | sortRowTabByOrder
    151        | findBlocksChildrenUnsorted {r0wrZ2qQL}
    152        | assertRight
    153        | insertEmptyBlock {r0wrZ2qQL} 0 notesDB
    154     @ [_ nextUid] | genUid | idx 0 notesDB
    155     ++ #[{:block/uid}=nextUid {:block/order}=0]
    156     ++ #[{:block/uid}={3LKryaGyF} {:block/order}=1]
    157     ++ #[{:block/uid}={o-_aIaa83} {:block/order}=2]
    158 
    159 ; Middle
    160 =?=    | sortRowTabByOrder
    161        | findBlocksChildrenUnsorted {r0wrZ2qQL}
    162        | assertRight
    163        | insertEmptyBlock {r0wrZ2qQL} 1 notesDB
    164     @ [_ nextUid] | genUid | idx 0 notesDB
    165     ++ #[{:block/uid}={3LKryaGyF} {:block/order}=0]
    166     ++ #[{:block/uid}=nextUid {:block/order}=1]
    167     ++ #[{:block/uid}={o-_aIaa83} {:block/order}=2]
    168 
    169 ; End
    170 =?=    | sortRowTabByOrder
    171        | findBlocksChildrenUnsorted {r0wrZ2qQL}
    172        | assertRight
    173        | insertEmptyBlock {r0wrZ2qQL} 2 notesDB
    174     @ [_ nextUid] | genUid | idx 0 notesDB
    175     ++ #[{:block/uid}={3LKryaGyF} {:block/order}=0]
    176     ++ #[{:block/uid}={o-_aIaa83} {:block/order}=1]
    177     ++ #[{:block/uid}=nextUid {:block/order}=2]
    178 
    179 ;
    180 ;; Case 4: Write some text in that block
    181 ;
    182 ; When we set the text of a block, we have to parse it and do bookkeeping
    183 ; around references between them. Tests that we update these correctly.
    184 ;
    185 
    186 ; Change uid "D_fFfQNlb" from "((b2fdrwjXZ))" to "[[Iceman]] ((b2fdrwjXZ))".
    187 = changedSubIcemanRefDB
    188 | setBlockText {D_fFfQNlb} {[[Iceman]] ((b2fdrwjXZ))} notesDB
    189 
    190 ; Ensure we added a reference to {pnKunZ4If}
    191 =?=     [{pnKunZ4If} {b2fdrwjXZ}]
    192     | findAllRefUids {D_fFfQNlb} changedSubIcemanRefDB
    193 
    194 ; Change the text again to remove the block reference.
    195 = changed2SubIcemanRefDB
    196 | setBlockText {D_fFfQNlb} {[[Iceman]]} changedSubIcemanRefDB
    197 
    198 =?=     [{pnKunZ4If}]
    199     | findAllRefUids {D_fFfQNlb} changed2SubIcemanRefDB
    200 
    201 ; Change it again so it now points to an invalid uid.
    202 = changed3SubIcemanRefDB
    203 | setBlockText {D_fFfQNlb} {((AAAAAAAAA))} changed2SubIcemanRefDB
    204 
    205 =?=     []
    206     | findAllRefUids {D_fFfQNlb} changed3SubIcemanRefDB
    207 
    208 ;
    209 ;; Case 5: Move a bullet from one parent to another.
    210 ;
    211 
    212 = reorderingTestDB
    213 ^ assertTransactStrollDb _ | emptyStrollDb 42
    214 ++ ## ={:db/id} %[{reorder testing}]
    215    ## ={:page/title} {Reorder}
    216    ## ={:block/uid} {Mkd32lJAn}
    217    ## ={:block/children}
    218       ++ ## ={:block/string} {Source}
    219          ## ={:block/uid} {ohlsan321}
    220          ## ={:block/order} 0
    221          ## ={:block/page} %[{reorder testing}]
    222          ## ={:block/children}
    223             ++ ## ={:block/string} {A}
    224                ## ={:block/uid} {xh8spvba1}
    225                ## ={:block/order} 0
    226                ## ={:block/page} %[{reorder testing}]
    227             ++ ## ={:block/string} {B}
    228                ## ={:block/uid} {492kcn1sl}
    229                ## ={:block/order} 1
    230                ## ={:block/page} %[{reorder testing}]
    231             ++ ## ={:block/string} {C}
    232                ## ={:block/uid} {wdf1297fD}
    233                ## ={:block/order} 2
    234                ## ={:block/page} %[{reorder testing}]
    235       ++ ## ={:block/string} {Destination}
    236          ## ={:block/uid} {ck20LBq8I}
    237          ## ={:block/order} 0
    238          ## ={:block/page} %[{reorder testing}]
    239          ## ={:block/children}
    240             ++ ## ={:block/string} {1}
    241                ## ={:block/uid} {AnLk21dYd}
    242                ## ={:block/order} 0
    243                ## ={:block/page} %[{reorder testing}]
    244             ++ ## ={:block/string} {2}
    245                ## ={:block/uid} {ssk209jkD}
    246                ## ={:block/order} 1
    247                ## ={:block/page} %[{reorder testing}]
    248             ++ ## ={:block/string} {3}
    249                ## ={:block/uid} {ui3d9vvaa}
    250                ## ={:block/order} 2
    251                ## ={:block/page} %[{reorder testing}]
    252 ++ ## ={:db/id} %[{other reorder page}]
    253    ## ={:page/title} {Reorder Dest}
    254    ## ={:block/uid} {me29jsdfN}
    255 
    256 ; Moves `Reorder > Source > B` to between `Reorder > Destination > (1) and (2)`.
    257 = reparentedSamePageDB
    258 | reparent {492kcn1sl} {ck20LBq8I} 1 reorderingTestDB
    259 
    260 ; Checks that the source's parent was reordered correctly
    261 =?=     | sortRowTabByOrder
    262         | findBlocksChildrenUnsorted {ohlsan321} reparentedSamePageDB
    263     ++ #[{:block/uid}={xh8spvba1} {:block/order}=0]
    264     ++ #[{:block/uid}={wdf1297fD} {:block/order}=1]
    265 
    266 ; Checks that the bullet arrived at the correct destination and reordered the
    267 ; bullets after it:
    268 =?=     | sortRowTabByOrder
    269         | findBlocksChildrenUnsorted {ck20LBq8I} reparentedSamePageDB
    270     ++ #[{:block/uid}={AnLk21dYd} {:block/order}=0]
    271     ++ #[{:block/uid}={492kcn1sl} {:block/order}=1]
    272     ++ #[{:block/uid}={ssk209jkD} {:block/order}=2]
    273     ++ #[{:block/uid}={ui3d9vvaa} {:block/order}=3]
    274 
    275 ; Move the whole source block to a block on the Reorder page.
    276 = reparentedDifferentPageDB
    277 | reparent {ohlsan321} {me29jsdfN} 0 reorderingTestDB
    278 
    279 ; Checks that we change the {:block/page} of our children, by comparing it with
    280 ; the eid of a toplevel node we moved to.
    281 =?=     ^ getPageByEid _ reparentedDifferentPageDB
    282         | getEidOf {xh8spvba1} reparentedDifferentPageDB
    283     | getEidOf {me29jsdfN} reparentedDifferentPageDB