# Copyright (c) 2009 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Parameters.bunit,v 1.5 2009/10/12 04:12:32 nagler Exp $ Type(); my($empty) = class()->new([]); my($simple) = class()->new([ 'p1', [qw(gender Gender), Type_Gender()->FEMALE], [qw(*repeat Integer), sub {99}], ]); my($error); [ new => [ [] => 'Parameters', [['param1']] => 'Parameters(param1)', [['Boolean']] => 'Parameters(Boolean)', [['+Boolean']] => 'Parameters(+Boolean)', [[[qw(?bool Boolean)], '*String']] => 'Parameters(?bool,*String)', [[qw(+Boolean +String)]] => qr{Boolean: only the last.*repeat}, [[qw(?Boolean +String)]] => qr{String: param must be optional}, [['NoSuchType']] => qr{not.found}i, ], parameters => [ [[], $empty] => [class(), {}], [{}, $empty] => [class(), {}], [['value1'], $simple] => [class(), { p1 => 'value1', gender => Type_Gender()->FEMALE, repeat => [99], }], [[Type_Month()->MAY, qw(male 1 2 3)], $simple] => [class(), { p1 => Type_Month()->MAY, gender => Type_Gender()->MALE, repeat => [1, 2, 3], }], sub {[[qw(v1 not-gender)], $simple, $error = {}]} => sub { assert_equals({ param_name => 'gender', param_value => 'not-gender', type_error => Bivio_TypeError()->NOT_FOUND, }, $error); return 1; }, [{not_found => 1}, $simple] => qr{not_found: not found}, ], ];