Skip to content

Commit

Permalink
Add test for JS
Browse files Browse the repository at this point in the history
  • Loading branch information
perlancar committed Feb 19, 2015
1 parent ae5c2ef commit 178d67e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
36 changes: 36 additions & 0 deletions t/js-misc.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!perl

use 5.010;
use strict;
use warnings;

use Data::Sah::JS qw(gen_validator);
use Test::More 0.98;

my $node_path = Data::Sah::JS::get_nodejs_path();
unless ($node_path) {
plan skip_all => 'node.js is not available';
}

# check double popping of _sahv_dpath, fixed in 0.42+

my @tests = (
{
schema => ["array", {of=>["hash", keys=>{a=>[array=>of=>"any"]}]}],
input => [{a=>[]}, {a=>[]}],
valid => 1,
},
);
#test_sah_cases(\@tests, {gen_validator_opts=>{return_type=>"str"}});

# XXX use test_sah_cases() when it supports js
for my $test (@tests) {
my $v = gen_validator($test->{schema}, {return_type=>"str"});
my $res = $v->($test->{input});
if ($test->{valid}) {
is($res, "", $test->{name}) or diag $res;
} else {
isnt($res, "", $test->{name});
}
}
done_testing();
3 changes: 1 addition & 2 deletions t/perl-misc.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use 5.010;
use strict;
use warnings;

use DateTime;
use Test::Data::Sah qw(test_sah_cases);
use Test::More 0.96;
use Test::More 0.98;

# check double popping of _sahv_dpath, fixed in 0.42+

Expand Down

0 comments on commit 178d67e

Please sign in to comment.