#lang imperative-syndicate/test-implementation

(test-case
    [(assertion-struct greeting (text))

     (spawn #:name "A" (assert (greeting "Hi from outer space!")))
     (spawn #:name "B" (on (asserted (greeting $t))
                           (printf "Outer dataspace: ~a\n" t)))

     (dataspace #:name "C"
                (spawn #:name "D" (assert (outbound (greeting "Hi from middle!"))))
                (spawn #:name "E" (on (asserted (inbound (greeting $t)))
                                      (printf "Middle dataspace: ~a\n" t)))

                (dataspace #:name "F"
                           (spawn #:name "G" (assert (outbound (outbound (greeting "Inner!")))))
                           (spawn #:name "H" (on (asserted (inbound (inbound (greeting $t))))
                                                 (printf "Inner dataspace: ~a\n" t)))))]
  no-crashes
  (expected-output (set "Outer dataspace: Hi from outer space!"
                        "Middle dataspace: Hi from outer space!"
                        "Inner dataspace: Hi from outer space!"
                        "Outer dataspace: Hi from middle!"
                        "Middle dataspace: Hi from middle!"
                        "Inner dataspace: Hi from middle!"
                        "Outer dataspace: Inner!"
                        "Middle dataspace: Inner!"
                        "Inner dataspace: Inner!")))
