~ubuntu-branches/ubuntu/wily/libsereal-encoder-perl/wily

« back to all changes in this revision

Viewing changes to t/030_canonical_vs_test_deep.t

  • Committer: Package Import Robot
  • Author(s): Alexandre Mestiashvili, Alexandre Mestiashvili, gregor herrmann
  • Date: 2015-04-29 11:12:18 UTC
  • mfrom: (17.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20150429111218-v3ghc7ck5gcr38fu
Tags: 3.005.001-1
[ Alexandre Mestiashvili ]
* Imported Upstream version 3.005.001
* d/control: cme fix dpkg
* d/copyright: updated debian/* copyright year

[ gregor herrmann ]
* Mark package as autopkgtest-able.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!perl
 
2
use strict;
 
3
use warnings;
 
4
use Sereal::Encoder qw(encode_sereal);
 
5
use Test::More;
 
6
 
 
7
my %tests = (
 
8
    # IMPORTANT: If you add new types of cases here please update the
 
9
    # "CANONICAL REPRESENTATION" documentation.
 
10
    utf8_flag_on_ascii_string => [
 
11
        sub {
 
12
            return "en";
 
13
        },
 
14
        sub {
 
15
            my $en = "en";
 
16
            utf8::upgrade($en);
 
17
            return $en;
 
18
        },
 
19
    ],
 
20
    IV_string_value => [
 
21
        sub { "12345" },
 
22
        sub { "12345" + 0 },
 
23
    ],
 
24
    NV_string_value => [
 
25
        sub { "12.345" },
 
26
        sub { "12.345" + 0 },
 
27
    ],
 
28
);
 
29
 
 
30
eval {
 
31
    require Test::Deep::NoTest;
 
32
    die "PANIC: We expect at least Test::Deep 0.110 (and Test::Deep::NoTest doesn't support ->VERSION(...)"
 
33
        unless version->new(Test::Deep->VERSION) >= version->new('0.110');
 
34
    1;
 
35
} or do {
 
36
    my $error = $@ // "Zombie Error";
 
37
    plan skip_all => "We are skipping all our tests because we don't have a suitable Test::Deep here, got error: $error";
 
38
};
 
39
plan tests => keys(%tests) * 2;
 
40
 
 
41
for my $test (keys %tests) {
 
42
    my ($x, $y) = @{$tests{$test}};
 
43
    my $x_value = $x->();
 
44
    my $y_value = $y->();
 
45
 
 
46
    my $x_value_sereal = encode_sereal($x_value, {canonical => 1});
 
47
    my $y_value_sereal = encode_sereal($y_value, {canonical => 1});
 
48
 
 
49
    cmp_ok($x_value_sereal, 'ne', $y_value_sereal, "The $test values are not the same under Sereal");
 
50
    ok(Test::Deep::eq_deeply($x_value, $y_value), "The $test values are the same under Test::Deep though");
 
51
}