File: boolean-jsonpp.t

package info (click to toggle)
libyaml-libyaml-perl 0.76%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 688 kB
  • sloc: perl: 1,603; ansic: 1,140; sh: 29; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use FindBin '$Bin';
use lib $Bin;
use TestYAMLTests;

local $YAML::XS::Boolean = "JSON::PP";

my $yaml = <<'...';
---
boolfalse: false
booltrue: true
stringfalse: 'false'
stringtrue: 'true'
...


my $hash = eval { Load $yaml };

if ($@ and $@ =~ m{JSON/PP}) {
    plan skip_all => "JSON::PP not installed";
    exit;
}

plan tests => 7;

isa_ok($hash->{booltrue}, 'JSON::PP::Boolean');
isa_ok($hash->{boolfalse}, 'JSON::PP::Boolean');

cmp_ok($hash->{booltrue}, '==', 1, "boolean true is true");
cmp_ok($hash->{boolfalse}, '==', 0, "boolean false is false");

ok(! ref $hash->{stringtrue}, "string 'true' stays string");
ok(! ref $hash->{stringfalse}, "string 'false' stays string");

my $yaml2 = Dump($hash);
cmp_ok($yaml2, 'eq', $yaml, "Roundtrip booleans ok");