[libtype-tiny-perl] 08/14: improve classifier/compile_match_on_type code, documentation and tests

Jonas Smedegaard dr at jones.dk
Fri May 30 17:41:31 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.043_03
in repository libtype-tiny-perl.

commit e590cff2f84ec28ece168638c1691391e0d8f5b7
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date:   Tue May 6 21:02:27 2014 +0100

    improve classifier/compile_match_on_type code, documentation and tests
---
 lib/Type/Utils.pm                    |  5 ++++-
 t/20-unit/Type-Utils/match-on-type.t | 14 ++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lib/Type/Utils.pm b/lib/Type/Utils.pm
index 5a6f378..80e879f 100644
--- a/lib/Type/Utils.pm
+++ b/lib/Type/Utils.pm
@@ -431,7 +431,7 @@ sub compile_match_on_type
 		}
 	}
 	
-	push @code, 'else', '  { Type::Util::_croak("No cases matched for %s", Type::Tiny::_dd($_[0])) }';
+	push @code, 'else', '  { Type::Utils::_croak("No cases matched for %s", Type::Tiny::_dd($_[0])) }';
 	
 	push @code, '}';  # /sub
 	
@@ -942,6 +942,9 @@ type constraints Num, Str, and Any as well. In this case, the
 classifier has picked the most specific type constraint that "42"
 satisfies.
 
+If no type constraint is satisfied by the value, then the classifier
+will return undef.
+
 =item C<< dwim_type($string, %options) >>
 
 Given a string like "ArrayRef[Int|CodeRef]", turns it into a type constraint
diff --git a/t/20-unit/Type-Utils/match-on-type.t b/t/20-unit/Type-Utils/match-on-type.t
index d3c9fbc..468f7bf 100644
--- a/t/20-unit/Type-Utils/match-on-type.t
+++ b/t/20-unit/Type-Utils/match-on-type.t
@@ -86,6 +86,20 @@ is(
 	'to_json_2 using match_on_type works',
 );
 
+my $compiled1 = compile_match_on_type(
+	HashRef()  => sub { 'HASH' },
+	ArrayRef() => sub { 'ARRAY' },
+);
+
+is(ref($compiled1), 'CODE', 'compile_match_on_type returns a coderef');
+is($compiled1->({}), 'HASH', '... correct result');
+is($compiled1->([]), 'ARRAY', '... correct result');
+like(
+	exception { $compiled1->(42) },
+	qr/^No cases matched for Value "?42"?/,
+	'... correct exception',
+);
+
 if ($ENV{EXTENDED_TESTING})
 {
 	require Benchmark;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtype-tiny-perl.git



More information about the Pkg-perl-cvs-commits mailing list