]> git.proxmox.com Git - pve-common.git/blob - test/is_deeply_test.pl
bump version to 8.2.1
[pve-common.git] / test / is_deeply_test.pl
1 #!/usr/bin/perl
2
3 use lib '../src';
4
5 use strict;
6 use warnings;
7
8 use Test::More;
9 use PVE::Tools;
10
11 my $tests = [
12 {
13 name => 'both undef',
14 a => undef,
15 b => undef,
16 expected => 1,
17 },
18 {
19 name => 'empty string',
20 a => '',
21 b => '',
22 expected => 1,
23 },
24 {
25 name => 'empty string and undef',
26 a => '',
27 b => undef,
28 expected => 0,
29 },
30 {
31 name => '0 and undef',
32 a => 0,
33 b => undef,
34 expected => 0,
35 },
36 {
37 name => 'equal strings',
38 a => 'test',
39 b => 'test',
40 expected => 1,
41 },
42 {
43 name => 'unequal strings',
44 a => 'test',
45 b => 'tost',
46 expected => 0,
47 },
48 {
49 name => 'equal numerics',
50 a => 42,
51 b => 42,
52 expected => 1,
53 },
54 {
55 name => 'unequal numerics',
56 a => 42,
57 b => 420,
58 expected => 0,
59 },
60 {
61 name => 'equal arrays',
62 a => ['foo', 'bar'],
63 b => ['foo', 'bar'],
64 expected => 1,
65 },
66 {
67 name => 'equal empty arrays',
68 a => [],
69 b => [],
70 expected => 1,
71 },
72 {
73 name => 'unequal arrays',
74 a => ['foo', 'bar'],
75 b => ['bar', 'foo'],
76 expected => 0,
77 },
78 {
79 name => 'equal empty hashes',
80 a => { },
81 b => { },
82 expected => 1,
83 },
84 {
85 name => 'equal hashes',
86 a => { foo => 'bar' },
87 b => { foo => 'bar' },
88 expected => 1,
89 },
90 {
91 name => 'unequal hashes',
92 a => { foo => 'bar' },
93 b => { bar => 'foo' },
94 expected => 0,
95 },
96 {
97 name => 'equal nested hashes',
98 a => {
99 foo => 'bar',
100 bar => 1,
101 list => ['foo', 'bar'],
102 properties => {
103 baz => 'boo',
104 },
105 },
106 b => {
107 foo => 'bar',
108 bar => 1,
109 list => ['foo', 'bar'],
110 properties => {
111 baz => 'boo',
112 },
113 },
114 expected => 1,
115 },
116 {
117 name => 'unequal nested hashes',
118 a => {
119 foo => 'bar',
120 bar => 1,
121 list => ['foo', 'bar'],
122 properties => {
123 baz => 'boo',
124 },
125 },
126 b => {
127 foo => 'bar',
128 bar => 1,
129 list => ['foo', 'bar'],
130 properties => {
131 baz => undef,
132 },
133 },
134 expected => 0,
135 },
136 ];
137
138 for my $test ($tests->@*) {
139 is (PVE::Tools::is_deeply($test->{a}, $test->{b}), $test->{expected}, $test->{name});
140 }
141
142 done_testing();