Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-httpclient

Named HTTP clients for Pudu: a client factory, delegating handlers, pooled keep-alive connections, handler lifetimes, logging, and resilience

0.1.1Apache-2.01

InstallClose

OptionsTest.pudu

Pudu28 lines1.7 KB

GitHub ↗
1/** @Test.Options.Suite — typed values a request carries for its handlers */2module PuduLangHttpClient.OptionsTest34import Std.Io as Io5import Std.Test as Test6import PuduLangHttpClient.Options as Options78/// Runs the suite.9fn main() -> Int {10  let tenant = Options.textKey("tenant")11  let attempts = Options.intKey("attempts")12  let traced = Options.boolKey("traced")13  let options = Options.set(&Options.set(&Options.set(&Options.empty(), &tenant, "acme"), &attempts, 3), &traced, false)14  let checks = Test.suite("Options", &[15      Test.equals("each key reads back its own value", &(Options.get(&options, &tenant), Options.get(&options, &attempts), Options.get(&options, &traced)), &(Some("acme"), Some(3), Some(false))),16      Test.equals("a flag reads back true", &Options.get(&Options.set(&options, &traced, true), &traced), &Some(true)),17      Test.equals("a value that does not read back as the key's type is absent", &(Options.get(&options, &Options.intKey("tenant")), Options.get(&options, &Options.boolKey("attempts"))), &(None, None)),18      Test.that("a key is present once set and absent once removed", Options.has(&options, &tenant) && !Options.has(&Options.remove(&options, &tenant), &tenant)),19      Test.equals("names are listed in order", &Options.names(&options), &["attempts", "tenant", "traced"]),20      Test.equals("a custom key writes and reads its own way", &Options.get(&Options.set(&Options.empty(), &Options.key("pair", |pair: (Int, Int)| show(pair[0]) + "," + show(pair[1]), |text: Str| Some((0, text.length()))), (1, 2)), &Options.key("pair", |pair: (Int, Int)| "", |text: Str| Some((9, text.length())))), &Some((9, 3)))21    ])22  let ran = Test.run(&checks)23  for failure in Test.failuresOf(&ran) {24    let _reported = Io.writeErrorLine(failure)25  }26  Test.report(&ran)27}28