File: 04_scalar.t

package info (click to toggle)
libyaml-tiny-perl 1.51-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 380 kB
  • sloc: perl: 2,482; makefile: 45
file content (120 lines) | stat: -rw-r--r-- 3,165 bytes parent folder | download | duplicates (2)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/perl

# Testing of scalar-context calls to the compatibility functions

use strict;
BEGIN {
	$|  = 1;
	$^W = 1;
}

use File::Spec::Functions ':ALL';
use t::lib::Test;
use Test::More;
BEGIN {
	if ( t::lib::Test->have_yamlpm ) {
		plan( tests => 18 );
	} else {
		plan( skip_all => 'Requires YAML.pm' );
		exit(0);
	}
}

use YAML       ();
use YAML::Tiny ();





#####################################################################
# Sample documents

my $one = <<'END_YAML';
---
- foo
END_YAML

my $two = <<'END_YAML';
---
- foo
---
- bar
END_YAML





#####################################################################
# Match Listwise Behaviour

SCOPE: {
	my $one_list_pm   = [ YAML::Load( $one ) ];
	my $two_list_pm   = [ YAML::Load( $two ) ];
	my $one_list_tiny = [ YAML::Tiny::Load( $one ) ];
	my $two_list_tiny = [ YAML::Tiny::Load( $two ) ];

	is_deeply( $one_list_pm, [ [ 'foo' ] ],  'one: Parsed correctly'     );
	is_deeply( $one_list_pm, $one_list_tiny, 'one: List context matches' );

	is_deeply( $two_list_pm, [ [ 'foo' ], [ 'bar' ] ], 'two: Parsed correctly'     );
	is_deeply( $two_list_pm, $two_list_tiny,           'two: List context matches' );
}





#####################################################################
# Match Scalar Behaviour

SCOPE: {
	my $one_scalar_pm   = YAML::Load( $one );
	my $two_scalar_pm   = YAML::Load( $two );
	my $one_scalar_tiny = YAML::Tiny::Load( $one );
	my $two_scalar_tiny = YAML::Tiny::Load( $two );

	is_deeply( $one_scalar_pm, [ 'foo' ],        'one: Parsed correctly'       );
	is_deeply( $one_scalar_pm, $one_scalar_tiny, 'one: Scalar context matches' );

	is_deeply( $two_scalar_pm, [ 'bar' ],        'two: Parsed correctly'       );
	is_deeply( $two_scalar_pm, $two_scalar_tiny, 'two: Scalar context matches' );
}





#####################################################################
# Repeat for LoadFile

my $one_file = catfile(qw{ t data one.yml });
my $two_file = catfile(qw{ t data two.yml });
ok( -f $one_file, "Found $one_file" );
ok( -f $two_file, "Found $two_file" );
SCOPE: {
	my $one_list_pm   = [ YAML::LoadFile( $one_file ) ];
	my $two_list_pm   = [ YAML::LoadFile( $two_file ) ];
	my $one_list_tiny = [ YAML::Tiny::LoadFile( $one_file ) ];
	my $two_list_tiny = [ YAML::Tiny::LoadFile( $two_file ) ];

	is_deeply( $one_list_pm, [ [ 'foo' ] ],  'one: Parsed correctly'     );
	is_deeply( $one_list_pm, $one_list_tiny, 'one: List context matches' );

	is_deeply( $two_list_pm, [ [ 'foo' ], [ 'bar' ] ], 'two: Parsed correctly'     );
	is_deeply( $two_list_pm, $two_list_tiny,           'two: List context matches' );
}

SCOPE: {
	my $one_scalar_pm   = YAML::LoadFile( $one_file );
	my $two_scalar_pm   = YAML::LoadFile( $two_file );
	my $one_scalar_tiny = YAML::Tiny::LoadFile( $one_file );
	my $two_scalar_tiny = YAML::Tiny::LoadFile( $two_file );

	is_deeply( $one_scalar_pm, [ 'foo' ],        'one: Parsed correctly'       );
	is_deeply( $one_scalar_pm, $one_scalar_tiny, 'one: Scalar context matches' );

	is_deeply( $two_scalar_pm, [ 'bar' ],        'two: Parsed correctly'       );
	is_deeply( $two_scalar_pm, $two_scalar_tiny, 'two: Scalar context matches' );
}