chiark / gitweb /
TOML::Tiny::Faithful: Add a test for the types that work now
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 4 May 2020 17:20:53 +0000 (18:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 6 May 2020 00:18:28 +0000 (01:18 +0100)
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...

t/faithful.t [new file with mode: 0644]

diff --git a/t/faithful.t b/t/faithful.t
new file mode 100644 (file)
index 0000000..cb145b2
--- /dev/null
@@ -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;