File: string.t

package info (click to toggle)
libbson-xs-perl 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,708 kB
  • sloc: ansic: 9,734; perl: 1,049; makefile: 3
file content (72 lines) | stat: -rw-r--r-- 2,206 bytes parent folder | download
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use 5.008001;
use strict;
use warnings;
use utf8;

use Test::More 0.96;

binmode( Test::More->builder->$_, ":utf8" )
  for qw/output failure_output todo_output/;

use lib 't/lib';
use lib 't/pvtlib';
use CleanEnv;
use TestUtils;

use BSON qw/encode decode/;
use BSON::Types qw/bson_string/;

my ($hash);

# test constructor
is( bson_string(), '', "empty bson_string() is ''" );
is( BSON::String->new, '', "empty constructor is ''" );

# test overloading
is( bson_string('héllo wörld'), 'héllo wörld', "string overload" );
ok( bson_string('héllo wörld'), "bool overload" );

# string -> string
$hash = decode( encode( { A => 'héllo wörld' } ) );
is( sv_type( $hash->{A} ), 'PV', "string->string" );
is( $hash->{A}, 'héllo wörld', "value correct" );

# BSON::String -> string
$hash = decode( encode( { A => bson_string('héllo wörld') } ) );
is( sv_type( $hash->{A} ), 'PV', "BSON::String->string" );
is( $hash->{A}, 'héllo wörld', "value correct" );

# MongoDB::BSON::String -> string
my $str = 'héllo wörld';
$hash = decode( encode( { A => bless \$str, "MongoDB::BSON::String" } ) );
is( sv_type( $hash->{A} ), 'PV', "MongoDB::BSON::String->string" );
is( $hash->{A}, 'héllo wörld', "value correct" );

# string -> BSON::String
$hash = decode( encode( { A => 'héllo wörld' } ), wrap_strings => 1 );
is( ref( $hash->{A} ), 'BSON::String', "string->BSON::String" );
is( $hash->{A}->value, 'héllo wörld', "value correct" );

# BSON::String -> BSON::String
$hash = decode( encode( { A => bson_string('héllo wörld') } ), wrap_strings => 1 );
is( ref( $hash->{A} ), 'BSON::String', "BSON::String->BSON::String" );
is( $hash->{A}->value, 'héllo wörld', "value correct" );

# MongoDB::BSON::String -> BSON::String
$hash = decode( encode( { A => bless \$str, "MongoDB::BSON::String" } ), wrap_strings => 1 );
is( ref( $hash->{A} ), 'BSON::String', "MongoDB::BSON::String->BSON::String" );
is( $hash->{A}->value, 'héllo wörld', "value correct" );

done_testing;

#
# This file is part of BSON-XS
#
# This software is Copyright (c) 2018 by MongoDB, Inc.
#
# This is free software, licensed under:
#
#   The Apache License, Version 2.0, January 2004
#
#
# vim: set ts=4 sts=4 sw=4 et tw=75: