-
Notifications
You must be signed in to change notification settings - Fork 2
/
99regression.t
49 lines (48 loc) · 1.82 KB
/
99regression.t
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
37
38
39
40
41
42
43
44
45
46
47
48
49
use strict;
use warnings;
use Test::More qw(no_plan);
use Data::FlexSerializer;
use Sereal::Encoder qw(encode_sereal);
use Sereal::Decoder qw(decode_sereal);
use Data::Dumper;
{
my $flex = Data::FlexSerializer->new(
assume_compression => 0,
detect_compression => 0,
output_format => 'storable',
detect_json => 1,
detect_storable => 1,
detect_sereal => 0,
);
is_deeply($flex->detect_formats, { storable => 1, json => 1, sereal => 0 }, "We have the expected detection formats");
is_deeply($flex->deserialize(qq[{"foo": "bar"}]), { foo => "bar" }, "We can detect JSON");
$flex->detect_json(0);
is_deeply($flex->detect_formats, { storable => 1, json => 0, sereal => 0 }, "We have the expected detection formats");
eval {
$flex->deserialize(qq[{"foo": "bar"}]);
fail "Why does this work now?";
1;
} or do {
chomp(my $error = $@ || "Zombie Error");
pass "We shouldn't be able to deserialize JSON anymore: $error";
};
$flex->detect_storable(0);
$flex->detect_sereal(1);
is_deeply($flex->detect_formats, { storable => 0, json => 0, sereal => 1 }, "We have the expected detection formats");
eval {
is_deeply($flex->deserialize(encode_sereal({foo => "bar"})), { foo => "bar" }, "We can now deserialize Sereal");
1;
} or do {
chomp(my $error = $@ || "Zombie Error");
fail "We shouldn't die on this: $error";
};
$flex->detect_sereal(0);
is_deeply($flex->detect_formats, { storable => 0, json => 0, sereal => 0 }, "We have the expected detection formats");
eval {
$flex->deserialize(qq[{"foo": "bar"}]);
fail "We should die on this as we have no formats left";
1;
} or do {
pass "We died because we had no formats left";
};
}