~ubuntu-branches/ubuntu/saucy/libyaml-libyaml-perl/saucy-security

« back to all changes in this revision

Viewing changes to t/alias.t

  • Committer: Bazaar Package Importer
  • Author(s): Ryan Niebur
  • Date: 2009-06-01 02:17:22 UTC
  • Revision ID: james.westby@ubuntu.com-20090601021722-8qlj45pmu8ffwzau
Tags: upstream-0.32
ImportĀ upstreamĀ versionĀ 0.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use t::TestYAMLTests tests => 10;
 
2
 
 
3
my ($a, $b) = Load(<<'...');
 
4
---
 
5
- &one [ a, b, c]
 
6
- foo: *one
 
7
--- &1
 
8
foo: &2 [*2, *1]
 
9
...
 
10
 
 
11
is "$a->[0]", "$a->[1]{'foo'}",
 
12
   'Loading an alias works';
 
13
is "$b->{'foo'}", "$b->{'foo'}[0]",
 
14
   'Another alias load test';
 
15
is "$b", "$b->{'foo'}[1]",
 
16
   'Another alias load test';
 
17
 
 
18
my $value = { xxx => 'yyy' };
 
19
my $array = [$value, 'hello', $value];
 
20
is Dump($array), <<'...', 'Duplicate node has anchor/alias';
 
21
---
 
22
- &1
 
23
  xxx: yyy
 
24
- hello
 
25
- *1
 
26
...
 
27
 
 
28
my $list = [];
 
29
push @$list, $list;
 
30
push @$list, $array;
 
31
is Dump($list), <<'...', 'Dump of multiple and circular aliases';
 
32
--- &1
 
33
- *1
 
34
- - &2
 
35
    xxx: yyy
 
36
  - hello
 
37
  - *2
 
38
...
 
39
 
 
40
my $hash = {};
 
41
$hash->{a1} = $hash->{a2} = [];
 
42
$hash->{b1} = $hash->{b2} = [];
 
43
$hash->{c1} = $hash->{c2} = [];
 
44
$hash->{d1} = $hash->{d2} = [];
 
45
$hash->{e1} = $hash->{e2} = [];
 
46
is Dump($hash), <<'...', 'Alias Order is Correct';
 
47
---
 
48
a1: &1 []
 
49
a2: *1
 
50
b1: &2 []
 
51
b2: *2
 
52
c1: &3 []
 
53
c2: *3
 
54
d1: &4 []
 
55
d2: *4
 
56
e1: &5 []
 
57
e2: *5
 
58
...
 
59
 
 
60
my $yaml = <<'...';
 
61
---
 
62
foo: &text |
 
63
  sub foo {
 
64
      print "hello\n";
 
65
  }
 
66
bar: *text
 
67
...
 
68
 
 
69
$hash = Load($yaml);
 
70
is $hash->{bar}, $hash->{foo}, 'Scalar anchor/aliases Load';
 
71
like $hash->{bar}, qr/"hello/, 'Aliased scalar has correct value';
 
72
 
 
73
$yaml = <<'...';
 
74
---
 
75
foo: &rx !!perl/regexp (?-xsim:lala)
 
76
bar: *rx
 
77
...
 
78
 
 
79
$hash = Load($yaml);
 
80
is $hash->{bar}, $hash->{foo}, 'Regexp anchor/aliases Load';
 
81
like "falala", $hash->{bar}, 'Aliased regexp works';