RPA Toolkit
added ini file parsing test.
[rpatk.git] / phpext / prpa / tests / 013.phpt
1 --TEST--
2 Parse .ini file
3 --SKIPIF--
4 <?php if (!extension_loaded("prpa")) echo "skip\n"; ?>
5 --FILE--
6 <?php 
7         $records = 0;
8         $error = 0;
9         $bnf = "#!emitnone\n" .
10         "#!emitid SectionName 1\n" .
11         "#!emitid Name 2\n" .
12         "#!emitid Value 3\n" .
13         "S                                      ::= [#0x0009] | [#0x000B] | [#0x000C] | [#0x0020] | [#0x00A0] | [#0xFEFF]\n" .
14         "EOL                            ::= [#0x000D] [#0x000A] | [#0x000A] | [#0x000D] | [#0x2028] | [#0x2029]\n" .
15         "SectionName            ::= [a-zA-Z][a-zA-Z0-9]*\n" .
16         "SectionLine            ::= '[' <SectionName> ']' <S>* \n" .
17         "Comment                        ::= ';' (. - <EOL>)+ \n" .      
18         "Name                           ::= [a-zA-Z][a-zA-Z0-9]* \n" .
19         "Value                          ::= (. - <EOL>)+ \n" .
20         "NameValue                      ::= <Name> <S>* '=' <S>* <Value>? \n" .
21         "Section                        ::= <SectionLine> (<NameValue>|<EOL>|<S>|<Comment>)*\n" .
22         "Ini                            ::= <Section>+\n";
23         
24
25         $inifile = "[PersonName]\n" .
26         "FirstName = John\n" .
27         "LastName = Smith\n\n" .
28         "[PersonAddress]\n" .           
29         "Street = NE 231\n" .
30         "; this is a comment\n" .
31         "City = Seattle\n" .
32         "State = Washington\n" .
33         "ZIP = 98115\n";
34
35
36         $ret = rpaparse($bnf, RPA_ENCODING_UTF8, $inifile, $records, $error);
37         if ($ret < 0)
38                 die($error . "\n");
39         echo($inifile . "\n");
40         if (is_array($records)) {
41                 foreach ($records as $record) {
42                         if ($record['type'] & RPA_RECORD_START) {
43                                 echo("START ");
44                                 echo ($record['uid'] . ", " . $record['rule'] . ": " . $record['input'] . "\n");
45                         }
46                 }
47         }
48 ?>
49 --EXPECT--
50 [PersonName]
51 FirstName = John
52 LastName = Smith
53
54 [PersonAddress]
55 Street = NE 231
56 ; this is a comment
57 City = Seattle
58 State = Washington
59 ZIP = 98115
60
61 START 1, SectionName: PersonName
62 START 2, Name: FirstName
63 START 3, Value: John
64 START 2, Name: LastName
65 START 3, Value: Smith
66 START 1, SectionName: PersonAddress
67 START 2, Name: Street
68 START 3, Value: NE 231
69 START 2, Name: City
70 START 3, Value: Seattle
71 START 2, Name: State
72 START 3, Value: Washington
73 START 2, Name: ZIP
74 START 3, Value: 98115