File: 31stripcomments.t

package info (click to toggle)
libparse-debcontrol-perl 2.005-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 384 kB
  • sloc: perl: 910; makefile: 2
file content (76 lines) | stat: -rw-r--r-- 3,284 bytes parent folder | download | duplicates (3)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl -w

use Test::More tests => 28;

BEGIN {
        chdir 't' if -d 't';
        use lib '../blib/lib', 'lib/', '..';
}


my $mod = "Parse::DebControl";

#Object initialization - 2 tests

	use_ok($mod);
	ok($pdc = new Parse::DebControl(), "Parser object creation works fine");

#stripComments - 6 tests

	$pdc = new Parse::DebControl(1);
	ok($data = $pdc->parse_mem("Key1: value1\n\#This is a comment\nKey2: value2#another comment\nKey3: value3", {stripComments => 1}), "Comments parse out correctly");
	ok(@$data == 1, "...and there are two stanzas");
	ok(keys %{$data->[0]} == 3, "...and the first stanza is the right size");
	ok($data->[0]->{Key1} eq "value1", "...and the first value is correct");

	ok($data->[0]->{Key2} eq "value2", "...and the second value is correct");
	ok($data->[0]->{Key3} eq "value3", "...and the third value is correct");

	#Comment char as last character - 2 tests
	ok($data = $pdc->parse_mem("Key1: value\#", {stripComments => 1}), "Parse with pound as last character");
	ok($data->[0]->{Key1} eq "value", "...data is correct");

	#Literal pound as last character - 2 tests
	ok($data = $pdc->parse_mem("Key1: value\#\#", {stripComments => 1}), "Parse with literal pound as last character");
	ok($data->[0]->{Key1} eq "value\#", "...data is correct");

	#Comment char as first character - 3 tests
	ok($data = $pdc->parse_mem("Key1: value\n\#oo: bar", {stripComments => 1}), "Parse with comment as first character");
	ok($data->[0]->{Key1} eq "value", "...data is correct");
	ok(keys %{$data->[0]} == 1, "...data is right size");

	#Literal pound as first character - 3 tests
	ok($data = $pdc->parse_mem("Key1: value\n\#\#oo: bar", {stripComments => 1}), "Parse with literal pound  as first character");
	ok($data->[0]->{Key1} eq "value", "...data is correct");
	ok($data->[0]->{"\#oo"} eq "bar", "...pound-key character is correct");

	#Line skip - 3 tests
	ok($data = $pdc->parse_mem("Key1: value\n#hello there#\nKey2: value2", {stripComments => 1}), "Parse with line skip");
	ok($data->[0]->{Key1} eq "value", "...first value is correct");
	ok($data->[0]->{Key2} eq "value2", "...second value is correct");

	#Line skip; leading whitespace - 3 tests
	ok($data = $pdc->parse_mem("Key1: value\n         #hello there#\nKey2: value2", {stripComments => 1}), "Parse with line skip and leading space");
	ok($data->[0]->{Key1} eq "value", "...first value is correct");
	ok($data->[0]->{Key2} eq "value2", "...second value is correct");

	# Comments in the middle of an indented block
        my $test_str = <<'EOF';
Key1: value,
      next1,
      next2,
#hello there
#
      next3
EOF
        my $val_ref = "value,next1,next2,next3";

	ok($data = $pdc->parse_mem($test_str, {stripComments => 1}), "Parse with comments in indented block");
        $data->[0]->{Key1} =~ s/^\s*//mg; # strip leading whitespace
        $data->[0]->{Key1} =~ s/\n//g;    # collapse newlines
	ok($data->[0]->{Key1} eq $val_ref, "...value is correct");

	ok($data = $pdc->parse_mem($test_str, {verbMultiLine => 1, stripComments => 1}), "Parse with comments in indented block");
        $data->[0]->{Key1} =~ s/^\s*//mg;# strip leading whitespace
        $data->[0]->{Key1} =~ s/\n//g;   # collapse newlines
	ok($data->[0]->{Key1} eq $val_ref, "...value is correct");