File: hash_param.t

package info (click to toggle)
libcgi-pm-perl 4.68-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,028 kB
  • sloc: perl: 6,082; makefile: 9
file content (47 lines) | stat: -rw-r--r-- 1,018 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!perl

use strict;
use warnings;

use Test::More 'no_plan';
use CGI;

# Mix hash and old parammeters
my $p = {
    'class'    => 'class_set',
    '-default' => [''],
    '-name'    => 'name_set',
    'id'       => 'id_set'
};

sub _test {
    my $cnt = 100;
    my $err = 0;
    for (1 .. $cnt) {
        my $cg    = CGI->new;
        my $str   = $cg->hidden(%$p);

	# Check if hidden return only one line
        my $count = () = $str =~ /input/g;
        if ($count > 1) {
	   $err++;
	   next;
	}

	# Check if input line has proper values
        $str =~ s/\<input\s+//;
        $str =~ s/\/>//;
        my %th = map { split("=") } split(" ", $str);
        is(delete $th{type}, '"hidden"', "Type");
        is(delete $th{name}, '"name_set"', "name");
        is(delete $th{class}, '"class_set"', "class");
        is(delete $th{id}, '"id_set"', "class");
        is(delete $th{value}, '""', "value");
        is(keys %th, 0, "keys");
    }
    ok($err == 0, "Check hash_param");
}

for (1 .. 10) {
    _test();
}