From: Ian Jackson Date: Mon, 4 May 2020 17:20:53 +0000 (+0100) Subject: TOML::Tiny::Faithful: Add a test for the types that work now X-Git-Tag: nailing-cargo/1.0.0~233^2~3 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=385da7e5352d7bdae1e5003122a7a1d4d61bdd53;p=nailing-cargo.git TOML::Tiny::Faithful: Add a test for the types that work now This tests the scalar values we have just fixed. Booleans already worked (when we have Serialiser). "Local Date-Time" should be in this test too, but they don't work properly yet... --- diff --git a/t/faithful.t b/t/faithful.t new file mode 100644 index 0000000..cb145b2 --- /dev/null +++ b/t/faithful.t @@ -0,0 +1,58 @@ +use utf8; +use Test2::V0; +use Data::Dumper; +use DateTime; +use DateTime::Format::RFC3339; +use Math::BigInt; +use Math::BigFloat; +use TOML::Tiny::Faithful; + +binmode STDIN, ':encoding(UTF-8)'; +binmode STDOUT, ':encoding(UTF-8)'; + +my $input = q{ +datetime=2020-05-04T16:37:02.905408062+01:00 +datetimes="2020-05-04T16:37:02.905408062+01:00" +float=3.14 +floats="3.14" +uint=3 +uints="3" +nint=-4 +nints="-4" +bigint=1852528528562625752750 +bigints="1852528528562625752750" +hex=0x12 +oct=0o751 +bin=0b11010110 +boolf=false +boolt=true +boolfs="false" +boolts="true" +}; + +sub norm ($) { + join "\n", ( + sort + map { + s{=0o(\d+)$}{ '='.oct($1) }e; + s{=(0[xb]\w+)$}{ '='.eval($1) }e; + $_; + } + grep /./, + split /\n/, $_[0] + ), '' +} + +my $parsed = from_toml($input); +my $actual = norm(to_toml($parsed)); +my $expected = norm($input); + +is($actual, $expected, 'round trip') or do{ + diag 'EXPECTED:'; + diag Dumper($expected); + + diag 'ACTUAL:'; + diag Dumper($actual); +}; + +done_testing;