Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-environment

Environment files for Pudu: load .env variables safely with layered files, discovery, expansion, typed reads, and secrets kept out of every message

0.1.0Apache-2.01

InstallClose

ValuesTest.pudu

Pudu31 lines1.6 KB

GitHub ↗
1/** @Test.Domain.Values.Suite — text to numbers and truth values */2module PuduLangEnvironment.Domain.ValuesTest34import Std.Decimal as Decimal5import Std.Io as Io6import Std.Test as Test7import PuduLangEnvironment.Domain.Values as Values89/// Runs the suite.10fn main() -> Int {11  let checks = Test.suite("Domain.Values", &[12      Test.equals("a whole number is read", &Values.toInt("8080"), &Some(8080)),13      Test.equals("a whole number ignores surrounding space", &Values.toInt(" -12 "), &Some(-12)),14      Test.equals("a whole number refuses a fraction", &Values.toInt("1.5"), &None),15      Test.equals("a whole number refuses text", &Values.toInt("12a"), &None),16      Test.equals("a whole number too large is refused", &Values.toInt("99999999999999999999"), &None),17      Test.equals("a float is read", &Values.toFloat(" 2.5 "), &Some(2.5)),18      Test.equals("a float refuses text", &Values.toFloat("fast"), &None),19      Test.equals("a decimal is read exactly", &Values.toDecimal(" 0.10 "), &Decimal.parse("0.10")),20      Test.equals("a decimal refuses text", &Values.toDecimal("ten"), &None),21      Test.equals("true is read in any case", &[Values.toBool("true"), Values.toBool(" TRUE "), Values.toBool("True")], &[Some(true), Some(true), Some(true)]),22      Test.equals("false is read in any case", &[Values.toBool("false"), Values.toBool("FALSE ")], &[Some(false), Some(false)]),23      Test.equals("other words are not truth values", &[Values.toBool("yes"), Values.toBool("1"), Values.toBool("on"), Values.toBool("")], &[None, None, None, None])24    ])25  let ran = Test.run(&checks)26  for failure in Test.failuresOf(&ran) {27    let _reported = Io.writeErrorLine(failure)28  }29  Test.report(&ran)30}31