line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Sah; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-03-01'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Test-Sah'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.020'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
103982
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
10
|
|
|
|
|
|
|
#use Log::Any '$log'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
967
|
use Data::Sah qw(gen_validator); |
|
1
|
|
|
|
|
7023
|
|
|
1
|
|
|
|
|
56
|
|
13
|
1
|
|
|
1
|
|
8
|
use Test::Builder; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
1
|
|
|
1
|
|
8
|
my $self = shift; |
19
|
1
|
|
|
|
|
3
|
my $caller = caller; |
20
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
222
|
|
21
|
1
|
|
|
|
|
2
|
*{$caller.'::is_valid'} = \&is_valid; |
|
1
|
|
|
|
|
5
|
|
22
|
1
|
|
|
|
|
3
|
*{$caller.'::is_invalid'} = \&is_invalid; |
|
1
|
|
|
|
|
3
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
12
|
$Test->exported_to($caller); |
25
|
1
|
|
|
|
|
13
|
$Test->plan(@_); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub is_valid { |
29
|
1
|
|
|
1
|
1
|
129
|
my ($data, $schema, $msg) = @_; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
8
|
my $v = gen_validator($schema, {return_type=>'str'}); |
32
|
1
|
|
|
|
|
91502
|
my $res = $v->($data); |
33
|
1
|
|
|
|
|
33
|
my $ok = $Test->ok(!$res, $msg); |
34
|
1
|
50
|
|
|
|
556
|
$ok or $Test->diag($res); |
35
|
1
|
|
|
|
|
8
|
$ok; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub is_invalid { |
39
|
1
|
|
|
1
|
1
|
6
|
my ($data, $schema, $msg) = @_; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
my $v = gen_validator($schema, {return_type=>'str'}); |
42
|
1
|
|
|
|
|
13871
|
$Test->ok($v->($data), $msg); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
# ABSTRACT: Test data against Sah schema |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding UTF-8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Test::Sah - Test data against Sah schema |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 VERSION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This document describes version 0.020 of Test::Sah (from Perl distribution Test-Sah), released on 2020-03-01. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 SYNOPSIS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
use Test::More; |
65
|
|
|
|
|
|
|
use Test::Sah; # exports is_valid() and is_invalid() |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
is_valid ({}, [hash => keys=>{a=>"int", b=>"str"}]); # ok |
68
|
|
|
|
|
|
|
is_invalid([], [array => {min_len=>1}]); # ok |
69
|
|
|
|
|
|
|
done_testing; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This module is a proof of concept. It provides C<is_valid()> and C<is_invalid()> |
74
|
|
|
|
|
|
|
to test data structure against L<Sah> schema. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 FUNCTIONS |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
All these functions are exported by default. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 is_valid($data, $schema[, $msg]) => BOOL |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Test that C<$data> validates to C<$schema>. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 is_invalid($data, $schema[, $msg]) => BOOL |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Test that C<$data> does not validate to C<$schema>. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 HOMEPAGE |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Test-Sah>. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SOURCE |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Test-Sah>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 BUGS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Sah> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
101
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
102
|
|
|
|
|
|
|
feature. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SEE ALSO |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L<Test::Sah::Schema> to test Sah schema modules. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
L<Data::Sah> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L<Sah> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 AUTHOR |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
This software is copyright (c) 2020, 2012 by perlancar@cpan.org. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
121
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |