/[eiffelstudio]/trunk/eweasel/tests/rdtp003/parser_test.e
ViewVC logotype

Contents of /trunk/eweasel/tests/rdtp003/parser_test.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86987 - (show annotations)
Thu Aug 11 21:49:58 2011 UTC (8 years, 5 months ago) by manus
File size: 5551 byte(s)
New test similar to rdtp001 except that it ensures that the implementation of `is_equivalent' from AST_EIFFEL is correct by comparing the result of two parsings of the same class and verifying they are indeed equivalent.

1 indexing
2 description : "System's root class"
3
4 class
5 PARSER_TEST
6
7 inherit
8 ARGUMENTS
9
10 KL_SHARED_EXECUTION_ENVIRONMENT
11
12 ENCODING_CONVERTER
13 rename
14 make as make_encoding
15 end
16
17 SHARED_ENCODING_CONVERTER
18
19 INTERNAL_COMPILER_STRING_EXPORTER
20
21 create
22 make
23
24 feature {NONE} -- Initialization
25
26 make is
27 do
28 make_encoding
29 test_roundtrip := False
30
31 create {AST_NULL_FACTORY} factory
32 create parser.make_with_factory (factory)
33 parser.set_il_parser
34 execute
35
36 create {AST_ROUNDTRIP_LIGHT_FACTORY} factory
37 create parser.make_with_factory (factory)
38 parser.set_il_parser
39 execute
40
41 test_roundtrip_scanner := True
42 create {AST_ROUNDTRIP_SCANNER_FACTORY} factory
43 create scanner.make_with_factory (factory)
44 create light_factory
45 create parser.make_with_factory (light_factory)
46 parser.set_il_parser
47 execute
48 test_roundtrip_scanner := False
49
50 test_roundtrip := True
51 scanner := Void
52 create {AST_ROUNDTRIP_FACTORY} factory
53 create parser.make_with_factory (factory)
54 parser.set_il_parser
55 execute
56 end
57
58 feature {NONE} -- Implementation
59
60 test_parse (file_name: STRING) is
61 local
62 file: KL_BINARY_INPUT_FILE
63 fault: RAW_FILE
64 count: INTEGER
65 output: STRING
66 file_system: KL_SHARED_FILE_SYSTEM
67 fn: STRING
68 l_class1, l_class2: CLASS_AS
69 do
70 if equal (file_name.substring (file_name.count - 1, file_name.count), ".e") then
71 -- Set for `IL' parsing since it accepts more classes.
72 create file.make (file_name)
73 count := file.count
74 file.open_read
75 if file.is_open_read then
76 file.read_string (count)
77 parse_eiffel_class (scanner, parser, file.last_string)
78
79 if parser.error_handler.has_error then
80 -- We ignore syntax errors since we want to test roundtrip parsing
81 -- on valid Eiffel classes.
82 parser.error_handler.wipe_out
83 else
84 l_class1 := parser.root_node
85 parse_eiffel_class (scanner, parser, file.last_string)
86 l_class2 := parser.root_node
87
88 if (l_class1 = Void or l_class2 = Void) or else not l_class1.is_equivalent (l_class2) then
89 create fault.make_open_append ("errors")
90 fault.put_string (file_name)
91 fault.put_new_line
92 fault.close
93 error_count := error_count + 1
94 end
95 end
96
97 file.close
98 else
99 print ("couldn't open file: " + file_name)
100 io.new_line
101 end
102 end
103 end
104
105 parse_eiffel_class (a_scanner: EIFFEL_ROUNDTRIP_SCANNER; a_parser: STANDALONE_EIFFEL_PARSER; a_buffer: STRING)
106 -- Using a parser, parse our code using different parser mode, to ensure that we can
107 -- indeed convert any kind of Eiffel classes.
108 require
109 a_parser_not_void: a_parser /= Void
110 a_buffer_not_void: a_buffer /= Void
111 do
112 a_parser.error_handler.wipe_out
113 -- First we do it using the old conventions.
114 if a_scanner /= Void then
115 a_scanner.set_syntax_version ({EIFFEL_PARSER}.obsolete_64_syntax)
116 a_scanner.scan_string (a_buffer)
117 end
118 a_parser.set_syntax_version ({EIFFEL_PARSER}.obsolete_64_syntax)
119 a_parser.parse_class_from_string (a_buffer, Void, Void)
120 if a_parser.error_handler.has_error then
121 a_parser.error_handler.wipe_out
122 -- There was an error, let's try to see if the code is using transitional syntax.
123 if a_scanner /= Void then
124 a_scanner.set_syntax_version ({EIFFEL_PARSER}.transitional_64_syntax)
125 a_scanner.scan_string (a_buffer)
126 end
127 a_parser.set_syntax_version ({EIFFEL_PARSER}.transitional_64_syntax)
128 a_parser.parse_class_from_string (a_buffer, Void, Void)
129 if a_parser.error_handler.has_error then
130 a_parser.error_handler.wipe_out
131 -- Still an error, let's try to see if the code is already using `attribute'.
132 if a_scanner /= Void then
133 a_scanner.set_syntax_version ({EIFFEL_PARSER}.ecma_syntax)
134 a_scanner.scan_string (a_buffer)
135 end
136 a_parser.set_syntax_version ({EIFFEL_PARSER}.ecma_syntax)
137 a_parser.parse_class_from_string (a_buffer, Void, Void)
138 end
139 end
140 end
141
142 test_conc (base_path, rem_path: STRING; recursive: BOOLEAN) is
143 local
144 full_path: STRING
145 do
146 full_path := base_path + operating_environment.Directory_separator.out + rem_path
147 if recursive then
148 test_recursive (full_path)
149 else
150 test_parse (full_path)
151 end
152 end
153
154 test_recursive (path: STRING) is
155 local
156 dir: KL_DIRECTORY
157 dir_names, file_names: ARRAY [STRING]
158 do
159 create dir.make (path)
160
161 dir_names := dir.directory_names
162 if dir_names /= Void then
163 dir_names.do_all (agent test_conc(path, ?, True))
164 end
165
166 dir.open_read
167 file_names := dir.filenames
168 if file_names /= Void then
169 file_names.do_all (agent test_conc(path, ?, False))
170 end
171
172 end
173
174 execute is
175 require
176 argument_count > 0
177 local
178 i: INTEGER
179 dir: KL_DIRECTORY
180 l_dir: STRING
181 do
182 from
183 i := 1
184 until
185 i > argument_count
186 loop
187 l_dir := Execution_environment.interpreted_string (argument (i))
188 create dir.make (l_dir)
189 if dir.exists then
190 test_recursive (l_dir)
191 i := i + 1
192 else
193 print ("directory: " + l_dir + " is not accessible%N")
194 i := argument_count + 1
195 error_count := error_count + 1
196 end
197 end
198 print ("number of errors: " + error_count.out + "%N")
199 end
200
201 feature {NONE}
202
203 error_count: INTEGER
204
205 test_roundtrip: BOOLEAN
206 -- Are we testing the roundtrip?
207
208 test_roundtrip_scanner: BOOLEAN
209
210 factory: AST_FACTORY
211 -- Factory being used for parsing.
212
213 light_factory: AST_ROUNDTRIP_LIGHT_FACTORY
214
215 parser: STANDALONE_EIFFEL_PARSER
216
217 scanner: EIFFEL_ROUNDTRIP_SCANNER
218
219 end -- class PARSER_TEST

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23