From bb2bf61723962222952d2f68da497f8391dc6a5e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 9 Oct 2012 20:52:44 -0500 Subject: initial implementation --- t/basic.t | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 t/basic.t (limited to 't/basic.t') diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..02c77c1 --- /dev/null +++ b/t/basic.t @@ -0,0 +1,98 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Moose::Util::TypeConstraints 'find_type_constraint'; + +use MooseX::Validation::Doctypes; + +doctype 'Person' => { + id => 'Str', + name => 'Str', + title => 'Str', +}; + +doctype 'Location' => { + id => 'Str', + city => 'Str', + state => 'Str', + country => 'Str', + zipcode => 'Int', +}; + +{ + my $person = find_type_constraint('Person'); + isa_ok($person, 'Moose::Meta::TypeConstraint'); + isa_ok($person, 'MooseX::Meta::TypeConstraint::Doctype'); + + is_deeply( + $person->doctype, + { id => 'Str', name => 'Str', title => 'Str' }, + "got the right doctype" + ); + + { + my $errors = $person->validate({ + id => '17382-QA', + name => 'Bob', + title => 'CIO' + }); + is($errors, undef, "no errors"); + } + + { + my $errors = $person->validate({ + id => '17382-QA', + name => 'Bob', + title => 'CIO', + favorite_food => 'ice cream', + }); + isa_ok($errors, 'MooseX::Validation::Doctypes::Errors'); + is_deeply( + $errors->extra_data, + { favorite_food => 'ice cream' }, + "got the right extra data" + ); + is($errors->errors, undef, "no errors"); + } + + { + my $errors = $person->validate({ + id => '17382-QA', + name => 'Bob', + }); + isa_ok($errors, 'MooseX::Validation::Doctypes::Errors'); + is($errors->extra_data, undef, "no extra data"); + is_deeply( + $errors->errors, + { title => "invalid value undef for 'title'" }, + "got the right errors" + ); + } +} + +{ + my $location = find_type_constraint('Location'); + isa_ok($location, 'Moose::Meta::TypeConstraint'); + isa_ok($location, 'MooseX::Meta::TypeConstraint::Doctype'); + + { + my $errors = $location->validate({ + id => 'My House', + city => 'Anytown', + state => 'IL', + country => 'USA', + zipcode => 'ABCDEF' + }); + isa_ok($errors, 'MooseX::Validation::Doctypes::Errors'); + is($errors->extra_data, undef, "no extra data"); + is_deeply( + $errors->errors, + { zipcode => "invalid value \"ABCDEF\" for 'zipcode'" }, + "got the right errors" + ); + } +} + +done_testing; -- cgit v1.2.3