
ValuesTest.pudu
Pudu31 lines1.6 KB
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 Values8910fn 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