X-Git-Url: http://git.shiar.net/gitweb.cgi/perl/html-form-simple.git/blobdiff_plain/bb5bd81e03c47ff9cc779c5109bd6e042219a1f8..08784cd0bf249108184d0fa6860623e81c4ab5ac:/t/html.t?ds=sidebyside
diff --git a/t/html.t b/t/html.t
index 2fea804..757b248 100644
--- a/t/html.t
+++ b/t/html.t
@@ -5,7 +5,7 @@ use warnings;
use Test::More;
-plan tests => 55;
+plan tests => 66;
use_ok('HTML::Form::Simple');
@@ -312,14 +312,14 @@ is_deeply(
is(
$form->radio(foo => 'test'),
- '',
+ '',
'radio method'
);
is(
- $form->radio(foo => undef, 2),
- '',
- 'labelless radio'
+ $form->radio(foo => undef, 'test'),
+ '',
+ 'labeled radio'
);
is(
@@ -330,15 +330,24 @@ is(
is_deeply(
[ $form->radio(undef, ['', '<">']) ],
+ [
+ '',
+ '',
+ ],
+ 'multiple radios'
+);
+
+is_deeply(
+ [ $form->radio(undef, undef, ['', '<">']) ],
[
'',
'',
],
- 'multiple radios'
+ 'multiple radio labels'
);
is_deeply(
- [ $form->radio(foo => 'test', ['foo', ''], {value => '', id => ''}) ],
+ [ $form->radio(foo => ['foo', ''], 'test', {value => '', id => ''}) ],
[
'',
'',
@@ -347,7 +356,7 @@ is_deeply(
);
is_deeply(
- [ $form->radio(foo => ['', 0], [0, 1, '']) ],
+ [ $form->radio(foo => [0, 1, ''], ['', 0]) ],
[
'',
'',
@@ -356,6 +365,39 @@ is_deeply(
'multiple radios with custom values'
);
+{
+ # make sure arguments aren't modified
+ my @args = (foo => [0, {value => 1}], [0, 1], {name => 0, value => 1});
+ my @orgs = (foo => [0, {value => 1}], [0, 1], {name => 0, value => 1});
+ my @output = (
+ '',
+ '',
+ );
+
+ is_deeply(
+ [ $form->radio(@args) ],
+ \@output,
+ 'options var to radio'
+ );
+
+ is_deeply(
+ [ $form->check(@args) ],
+ [
+ '',
+ '',
+ ],
+ 'options var to check'
+ );
+
+ is(
+ scalar $form->radio(@args),
+ join('', @output),
+ 'options var again to radio'
+ );
+
+ is_deeply(\@args, \@orgs, 'options var unmodified');
+}
+
# check
is(
@@ -422,5 +464,43 @@ is_deeply(
'various checkboxes'
);
+# defaults
+
+my $defform = HTML::Form::Simple->new({foo => '<">', '' => 'empty', 0 => 0});
+ok($defform, 'form with defaults');
+
+is(
+ $defform->hidden(''),
+ '',
+ 'hidden with default'
+);
+
+is(
+ $defform->hidden(undef),
+ '',
+ 'nameless hidden'
+);
+
+is(
+ $defform->text('foo'),
+ '',
+ 'input with default'
+);
+
+is(
+ $defform->text('foo', {value => 'custom'}),
+ '',
+ 'input with value and default'
+);
+
+is_deeply(
+ [ $defform->radio(0 => [1, 0]) ],
+ [
+ '',
+ '',
+ ],
+ 'select with default'
+);
+
#TODO