| 1 | #!perl |
| 2 | use strictscip-perl cpan Data-Password-zxcvbn 1.1.3 strict/; |
| 3 | use warningsscip-perl cpan Data-Password-zxcvbn 1.1.3 warnings/; |
| 4 | use Test::Mostscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/Most/; |
| 5 | use libscip-perl cpan Data-Password-zxcvbn 1.1.3 lib/ 't/lib'; |
| 6 | use JSON::MaybeXSscip-perl cpan Data-Password-zxcvbn 1.1.3 JSON/MaybeXS/; |
| 7 | use Scalar::Utilscip-perl cpan Data-Password-zxcvbn 1.1.3 Scalar/Util/ qw(looks_like_number); |
| 8 | use Test::MyVisitorscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/; |
| 9 | use Data::Password::zxcvbnscip-perl cpan Data-Password-zxcvbn 1.1.3 Data/Password/zxcvbn/ qw(password_strength); |
| 10 | |
| 11 | my $to_json = Test::MyVisitor->newscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/new().( |
| 12 | object => sub { $_scip-perl cpan Data-Password-zxcvbn 1.1.3 main/`@_`.[0]->visit_refscip-perl cpan Data-Password-zxcvbn 1.1.3 main/visit_ref().($_scip-perl cpan Data-Password-zxcvbn 1.1.3 main/`@_`.[1]->TO_JSONscip-perl cpan Data-Password-zxcvbn 1.1.3 main/TO_JSON().) }, |
| 13 | ); |
| 14 | my $no_log10 = Test::MyVisitor->newscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/new().( |
| 15 | hash => sub { my %ret = %{$_scip-perl cpan Data-Password-zxcvbn 1.1.3 main/$_.}; deletescip-perl cpan Data-Password-zxcvbn 1.1.3 main/delete(). $ret{guesses_log10}; \%ret }, |
| 16 | ); |
| 17 | my $lax_numbers = Test::MyVisitor->newscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/new().( |
| 18 | hash_value => sub { |
| 19 | my ($visitor,$value,$key) = @_scip-perl cpan Data-Password-zxcvbn 1.1.3 main/`@_`.; |
| 20 | return $visitscip-perl cpan Data-Password-zxcvbn 1.1.3 main/visit().or->visit($value) if refscip-perl cpan Data-Password-zxcvbn 1.1.3 main/ref().($value); |
| 21 | return $value unless looks_like_numberscip-perl cpan Data-Password-zxcvbn 1.1.3 main/looks_like_number().($value); |
| 22 | # 1% rounding |
| 23 | my $tolerance = absscip-perl cpan Data-Password-zxcvbn 1.1.3 main/abs().(intscip-perl cpan Data-Password-zxcvbn 1.1.3 main/int().($value/100)) || 1; |
| 24 | return numscip-perl cpan Data-Password-zxcvbn 1.1.3 main/num().($value,$tolerance); |
| 25 | }, |
| 26 | ); |
| 27 | |
| 28 | sub to_datascip-perl cpan Data-Password-zxcvbn 1.1.3 main/to_data(). { $no_log10->visitscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/visit().($to_json->visitscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/visit().(shiftscip-perl cpan Data-Password-zxcvbn 1.1.3 main/shift().)) } |
| 29 | sub to_testscip-perl cpan Data-Password-zxcvbn 1.1.3 main/to_test(). { $lax_numbers->visitscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/visit().($no_log10->visitscip-perl cpan Data-Password-zxcvbn 1.1.3 Test/MyVisitor/visit().(shiftscip-perl cpan Data-Password-zxcvbn 1.1.3 main/shift().)) } |
| 30 | |
| 31 | my $cases = decode_jsonscip-perl cpan Data-Password-zxcvbn 1.1.3 main/decode_json().(do { |
| 32 | openscip-perl cpan Data-Password-zxcvbn 1.1.3 main/open(). my $fh,'<','t/data/regression-data.json'; |
| 33 | local $/scip-perl cpan Data-Password-zxcvbn 1.1.3 main/`$/`.; |
| 34 | <$fh>; |
| 35 | }); |
| 36 | |
| 37 | planscip-perl cpan Data-Password-zxcvbn 1.1.3 main/plan(). tests => scalarscip-perl cpan Data-Password-zxcvbn 1.1.3 main/scalar(). @{$cases}; |
| 38 | |
| 39 | for my $case (@{$cases}) { |
| 40 | my $got = to_datascip-perl cpan Data-Password-zxcvbn 1.1.3 main/to_data().(password_strengthscip-perl cpan Data-Password-zxcvbn 1.1.3 Data/Password/zxcvbn/password_strength().($case->{password})); |
| 41 | my $test = to_testscip-perl cpan Data-Password-zxcvbn 1.1.3 main/to_test().($case->{strength}); |
| 42 | cmp_deeplyscip-perl cpan Data-Password-zxcvbn 1.1.3 main/cmp_deeply().( |
| 43 | $got, |
| 44 | $test, |
| 45 | "checking $case->{password}", |
| 46 | ) or explainscip-perl cpan Data-Password-zxcvbn 1.1.3 main/explain(). $got,explainscip-perl cpan Data-Password-zxcvbn 1.1.3 main/explain(). $test; |
| 47 | } |
| 48 | |
| 49 | done_testing; |