File: 110_nobless.t

package info (click to toggle)
libsereal-encoder-perl 4.005%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,980 kB
  • sloc: ansic: 8,664; perl: 5,705; sh: 25; makefile: 5
file content (50 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download | duplicates (4)
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
50
#!perl
use strict;
use warnings;
use File::Spec;
use Scalar::Util qw( blessed );
use lib File::Spec->catdir(qw(t lib));
BEGIN {
    lib->import('lib')
        if !-d 't';
}

use Sereal::TestSet qw(:all);
use Test::More;
use Sereal::Encoder;

my $ok = have_encoder_and_decoder();
if (not $ok) {
    plan skip_all => 'Did not find right version of decoder';
}
else {
    my $class = 'MyFoo';
    my %hash = ( x => 1 );
    my $object = bless( \%hash, $class );
    my $dec = Sereal::Decoder->new();

    # do not bless anything
    {
        my $enc = Sereal::Encoder->new({ no_bless_objects => 1 });
        my $blob = $enc->encode( $object );

        my $data = $dec->decode( $blob );

        ok( ref( $data ) && !blessed( $data ), 'reference without class' );
        is_deeply( $data, \%hash, 'same structure' );
    }

    # normally do the blessing
    {
        my $enc = Sereal::Encoder->new();
        my $blob = $enc->encode( $object );

        my $data = $dec->decode( $blob );

        is_deeply( $data, $object, 'same structure' );
        isa_ok( $data, $class, 'same class' );
    }
}

done_testing();