File: 1.t

package info (click to toggle)
libx12-parser-perl 0.80-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: perl: 432; makefile: 5
file content (138 lines) | stat: -rw-r--r-- 3,098 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
use strict;
use Test;
BEGIN { plan tests => 15 }
#########################
use FindBin;
use X12::Parser::Tree;

#setup for the test
my $root = X12::Parser::Tree->new();
$root->set_name('X12');

#add 1 child
my $child = X12::Parser::Tree->new();
$child->set_name('ST');
$child->set_loop_start_parm( 'ST', '', '' );
$child->set_parent($root);
$root->add_child($child);

#add 2 child
$child = X12::Parser::Tree->new();
$child->set_name('2000A');
$child->set_loop_start_parm( 'HL', '3', '20' );
$child->set_parent($root);
$root->add_child($child);

#add 2.1 child
my $grandchild = X12::Parser::Tree->new();
$grandchild->set_name('2010AA');
$grandchild->set_loop_start_parm( 'NM1', '1', '85' );
$grandchild->set_parent($child);
$child->add_child($grandchild);

#add 2.2 child
$grandchild = X12::Parser::Tree->new();
$grandchild->set_name('2010AB');
$grandchild->set_loop_start_parm( 'NM1', '1', '87' );
$grandchild->set_parent($child);
$child->add_child($grandchild);

#add 3 child
$child = X12::Parser::Tree->new();
$child->set_name('2000B');
$child->set_loop_start_parm( '2000B', '3', '22' );
$child->set_parent($root);
$root->add_child($child);

#add 3.1 child
$grandchild = X12::Parser::Tree->new();
$grandchild->set_name('2010BA');
$grandchild->set_loop_start_parm( 'NM1', '1', 'IL' );
$grandchild->set_parent($child);
$child->add_child($grandchild);

#add 3.2 child
$grandchild = X12::Parser::Tree->new();
$grandchild->set_name('2010BB');
$grandchild->set_loop_start_parm( 'NM1', '1', 'PR,QD,AO' );
$grandchild->set_parent($child);
$child->add_child($grandchild);
my $svalue = '';
my $ivalue = 0;

#test
my $node = $root;
$svalue = $node->get_name;
ok( $svalue, 'X12' );

#test
$ivalue = $node->is_root;
ok( $ivalue, 1 );

#test
$svalue = $node->get_parent;
ok( $svalue, undef );

#test
$ivalue = $node->has_children;
ok( $ivalue, 1 );

#test 5
$ivalue = $node->get_child_count;

#test
ok( $ivalue, 3 );

#test
$child  = $node->get_child(0);
$svalue = $child->get_name();
ok( $svalue, 'ST' );

#test
$child  = $node->get_child(2);
$svalue = $child->get_name();
ok( $svalue, '2000B' );

#test
$node   = $child;
$ivalue = $node->has_children();
ok( $ivalue, 1 );

#test
$ivalue = $node->get_child_count;
ok( $ivalue, 2 );

#test
$child  = $node->get_child(0);
$svalue = $child->get_name();
ok( $svalue, '2010BA' );

#test
$node = $child;
my $arrayref = [ 'NM1', 'IL', '2', 'GREEN HOSPITAL' ];
$ivalue = $node->is_loop_start($arrayref);
ok( $ivalue, 1 );

#test
$arrayref = [ 'NM1', 'QC', '2', 'GREEN HOSPITAL' ];
$ivalue = $node->is_loop_start($arrayref);
ok( $ivalue, 0 );

#test
$node   = $node->get_parent;
$node   = $node->get_child(1);
$svalue = $node->get_name();
ok( $svalue, '2010BB' );

#test
$arrayref = [ 'NM1', 'QD', '2', 'GREEN HOSPITAL' ];
$ivalue = $node->is_loop_start($arrayref);
ok( $ivalue, 1 );

#test
$arrayref = [ 'NM1', 'QC', '2', 'GREEN HOSPITAL' ];
$ivalue = $node->is_loop_start($arrayref);
ok( $ivalue, 0 );