Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mediator

In-process messaging for Pudu: requests, notifications, streams, pipeline behaviors, processors, and exception handling

0.1.0Apache-2.01

InstallClose

NotificationTest.pudu

Pudu34 lines1.7 KB

GitHub ↗
1/** @Test.Notification.Suite — notification kinds, envelopes, and unheard answers */2module PuduLangMediator.NotificationTest34import Std.Io as Io5import Std.Test as Test6import PuduLangMediator.Message as Message7import PuduLangMediator as Messaging8import PuduLangMediator.Notification as Notification9import PuduLangMediator.Utils.Erasure as Erasure1011/// Runs the suite.12fn main() -> Int {13  let placed: Notification.Kind[Int, Str] = Notification.kind("orders.placed")14  let other: Notification.Kind[Int, Str] = Notification.kind("orders.shipped")15  let tagged = Notification.tagged(&placed, ["audited"])16  let sealed = Notification.envelope(&placed, 5)17  let failed = Message.answered(&placed.info, &placed.outcomes, Err(Messaging.Raised("mail down")))18  let quiet = Message.unheard(&placed.info)19  let checks = Test.suite("Notification", &[20      Test.equals("a notification kind is an event", &placed.info.shape, &Message.Event),21      Test.equals("tags are carried", &tagged.info.tags, &["audited"]),22      Test.equals("a fresh route has no handlers", &Notification.route().handlers.length(), &0),23      Test.equals("an envelope opens for its kind", &Erasure.unpack(&placed.notifications, &sealed.packed), &Some(5)),24      Test.equals("an unheard publication of the kind succeeded", &Notification.answerOf(&placed, &quiet), &Some(Ok(()))),25      Test.equals("an unheard publication of another kind is not this kind's", &Notification.answerOf(&other, &quiet), &None),26      Test.equals("a failed publication reads back", &Notification.answerOf(&placed, &failed), &Some(Err(Messaging.Raised("mail down"))))27    ])28  let ran = Test.run(&checks)29  for failure in Test.failuresOf(&ran) {30    let _reported = Io.writeErrorLine(failure)31  }32  Test.report(&ran)33}34