-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhfdump.t
executable file
·221 lines (188 loc) · 2.99 KB
/
xhfdump.t
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env perl
# -*- mode: perl; coding: utf-8 -*-
#----------------------------------------
use strict;
use warnings qw(FATAL all NONFATAL misc);
use FindBin; BEGIN { do "$FindBin::Bin/t_lib.pl" }
#----------------------------------------
use Test::More;
use YATT::Lite::Test::TestUtil;
use Data::Dumper;
my $LOADER = 'YATT::Lite::XHF';
my $DUMPER = 'YATT::Lite::XHF::Dumper';
# undef
# 空文字列
# 空白入り文字列
# 入れ子
# 先頭/末尾の、空白/空行
my @tests
= ([<<END, undef]
= #null
END
, [<<END, 'foo']
- foo
END
#
, [<<END, '' => 'bar']
-
- bar
END
, [<<END, undef, 'bar']
= #null
- bar
END
, [<<END, foo => undef]
foo= #null
END
, [<<END, '', undef]
-
= #null
END
, [<<END, undef, undef]
= #null
= #null
END
#
, [<<END, foo => 'bar', baz => 'qux']
foo: bar
baz: qux
END
, undef
, [<<END, foo => "bar\nbaz\n"]
foo:
bar
baz
END
, [<<END, foo => "bar\n\n", baz => "qux\n\n\n"]
foo:
bar
baz:
qux
END
, [<<END, "foo bar" => 'baz']
- foo bar
- baz
END
, [<<END, [qw(foo bar baz)]]
[
- foo
- bar
- baz
]
END
, [<<END, [foo => undef, 'bar'], baz => undef]
[
- foo
= #null
- bar
]
baz= #null
END
, [<<END, foo => {bar => 'baz', hoe => 1}, bar => [1..3]]
foo{
bar: baz
hoe: 1
}
bar[
- 1
- 2
- 3
]
END
, [<<END, [bar => 1, baz => 2], [1..3], [1..3, [4..7]]]
[
bar: 1
baz: 2
]
[
- 1
- 2
- 3
]
[
1: 2
3[
4: 5
6: 7
]
]
END
, [<<END, {foo => 'bar', '' => 'baz', bang => undef}]
{
-
- baz
bang= #null
foo: bar
}
END
, [<<END, []]
[
]
END
, [<<END, {}]
{
}
END
);
my @dumponly =
(
[<<END, foo => [bless([foo => 1, bar => 2], "ARRAY"), "baz"]]
foo[
[
foo: 1
bar: 2
]
- baz
]
END
);
my @no_trailing_nl = (
[<<END, [foo => "bar\n"]]
foo:
bar
END
);
plan tests => 2 + 3*grep(defined $_, @tests) + @dumponly + @no_trailing_nl;
use_ok($LOADER);
use_ok($DUMPER);
sub breakpoint {}
my $T = 0;
foreach my $data (@tests) {
unless (defined $data) {
breakpoint();
next;
}
++$T;
my ($exp, @data) = @$data;
my $title = join(", ", Data::Dumper->new(\@data)->Terse(1)->Indent(0)->Dump);
eq_or_diff my $got = $DUMPER->dump_xhf(@data)."\n", $exp, "<T$T> dump: $title";
is_deeply [$LOADER->new(string => $got)->read], \@data, "<T$T> read: $title";
is_deeply [$LOADER->new(string => $exp)->read], \@data, "<T$T> read_exp: $title";
}
my $D = 0;
foreach my $data (@dumponly) {
++$D;
my ($exp, @data) = @$data;
my $title = join(", ", Data::Dumper->new(\@data)->Terse(1)->Indent(0)->Dump);
eq_or_diff my $got = $DUMPER->dump_xhf(@data)."\n", $exp, "<D$D> dump: $title";
}
{
my $O = 0;
my $test = sub {
my ($exp, $data) = @_;
my $title = join(", ", Data::Dumper->new($data)->Terse(1)->Indent(0)->Dump);
++$O;
eq_or_diff $DUMPER->dump_strict_xhf(@$data)."\n", $exp, "<O$O> dump: $title";
};
foreach my $t (@no_trailing_nl) {
$test->(@$t);
}
}
{
package ARRAY;
use overload qw("" stringify);
sub stringify {
"faked_string";
}
}
done_testing();