File: string2hash.t

package info (click to toggle)
libtree-dagnode-perl 1.35-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: perl: 1,455; makefile: 2; sh: 1
file content (45 lines) | stat: -rw-r--r-- 853 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::More;

# -------------

BEGIN{ use_ok('Tree::DAG_Node'); }

my($count)    = 1; # Counting the use_ok above.
my($s)        = q|a => 'b=>b', c => "d=>d", 'e' => "f", 'g=>g' => "h", "i" => "j", 'k, k' => "l, l"|;
my($finished) = 0;
my($reg_exp)  =
qr/
	([\"'])([^"']*?)\1\s*=>\s*(["'])([^"']*?)\3,?\s*
	|
	(["'])([^"']*?)\5\s*=>\s*(.*?),?\s*
	|
	(.*?)\s*=>\s*(["'])([^"']*?)\9,?\s*
	|
	(.*?)\s*=>\s*(.*?),?\s*
/sx;

my(@got);

while (! $finished)
{
	if ($s =~ /$reg_exp/gc)
	{
		push @got, defined($2) ? ($2, $4) : defined($6) ? ($6, $7) : defined($8) ? ($8, $10) : ($11, $12);
	}
	else
	{
		$finished = 1;
	}
}

my(@expected) = ('a', 'b=>b', 'c', 'd=>d', 'e', 'f', 'g=>g', 'h', 'i', 'j', 'k, k', 'l, l');

for my $i (0 .. $#got)
{
	ok($got[$i] eq $expected[$i], "Matched $got[$i]"); $count++;
}

done_testing($count);