Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some tests with whitespace and with missing delimiters

  • Loading branch information...
commit 91a0b422bc1ad54a4ae57254f5b65a6765cb7fad 1 parent a57f88b
Jesse Jones authored April 14, 2012

Showing 1 changed file with 12 additions and 27 deletions. Show diff stats Hide diff stats

  1. 39  src/test_xml.rs
39  src/test_xml.rs
@@ -165,10 +165,8 @@ fn attribute(input: state<node>) -> status<node>
165 165
 	let quote = literal(_, "\"", s);
166 166
 	let name = identifier(_, s, {|n| name_node(n)});
167 167
 	let result = sequence(input, [name, eq, quote, string_body, quote])
168  
-	{
169  
-		|values|
170  
-		result::ok(make_attribute_node(values[0], values[3]))
171  
-	};
  168
+		{|values| result::ok(make_attribute_node(values[0], values[3]))};
  169
+	
172 170
 	ret plog("attribute", input, result);
173 171
 }
174 172
 
@@ -176,10 +174,8 @@ fn attribute(input: state<node>) -> status<node>
176 174
 fn attributes(input: state<node>) -> status<node>
177 175
 {
178 176
 	let result = repeat_zero_or_more(input, attribute(_))
179  
-	{
180  
-		|values|
181  
-		result::ok(make_attributes_node(values))
182  
-	};
  177
+		{|values| result::ok(make_attributes_node(values))};
  178
+		
183 179
 	ret plog("attributes", input, result);
184 180
 }
185 181
 
@@ -213,10 +209,8 @@ fn empty_element(input: state<node>) -> status<node>
213 209
 	let name = identifier(_, s, {|n| name_node(n)});
214 210
 	
215 211
 	let result = sequence(input, [lt, name, attributes(_), slash_gt])
216  
-	{
217  
-		|values|
218  
-		result::ok(make_simple_node(values[1], values[2]))
219  
-	};
  212
+		{|values| result::ok(make_simple_node(values[1], values[2]))};
  213
+		
220 214
 	ret plog("empty_element", input, result);
221 215
 }
222 216
 
@@ -228,10 +222,8 @@ fn complex_element(input: state<node>, element_ptr: @mut parser<node>) -> status
228 222
 	let gt = literal(_, ">", s);
229 223
 	let lt_slash = literal(_, "</", s);
230 224
 	let children = repeat_zero_or_more(_, forward_ref(_, element_ptr),
231  
-	{
232  
-		|values|
233  
-		result::ok(make_children_node(values))
234  
-	});
  225
+		{|values| result::ok(make_children_node(values))});
  226
+		
235 227
 	let body = content(_);
236 228
 	let name = identifier(_, s, {|n| name_node(n)});
237 229
 	
@@ -275,6 +267,9 @@ fn test_simple_element()
275 267
 	assert xml_ok("<trivial/>", "<trivial></trivial>", parser);
276 268
 	assert xml_ok("<trivial first=\"number one\"/>", "<trivial first=\"number one\"></trivial>", parser);
277 269
 	assert xml_ok("<trivial first=\"number one\" second=\"number two\"/>", "<trivial first=\"number one\" second=\"number two\"></trivial>", parser);
  270
+	assert xml_ok("  <  trivial first \t =    \"number one\"  \t/>", "<trivial first=\"number one\"></trivial>", parser);
  271
+	assert check_err_str("<trivial", parser, "expected '/>'", 1);
  272
+	assert check_err_str("<trivial first=\"number one/>", parser, "expected '/>'", 1);
278 273
 }
279 274
 
280 275
 #[test]
@@ -282,7 +277,7 @@ fn test_element()
282 277
 {
283 278
 	let parser = xml_parser();
284 279
 	
285  
-	assert xml_ok("<simple></simple>", "<simple></simple>", parser);
  280
+	assert xml_ok("<simple>\n  \n</simple>", "<simple></simple>", parser);
286 281
 	assert check_err_str("<simple></oops>", parser, "Expected end tag 'simple' but found 'oops'", 1);
287 282
 	assert xml_ok("<simple alpha = \"A\" beta=\"12\"></simple>", "<simple alpha=\"A\" beta=\"12\"></simple>", parser);
288 283
 	
@@ -294,13 +289,3 @@ fn test_element()
294 289
 	assert xml_ok("<parent>some text</parent>", "<parent>some text</parent>", parser);
295 290
 	assert xml_ok("<parent><child/>blah blah</parent>", "<parent><child></child>blah blah</parent>", parser);
296 291
 }
297  
-
298  
-// TODO:
299  
-// may want to use constructors like name_node
300  
-// check (some) funky whitespace
301  
-// check some more error cases
302  
-//    especially missing terminators
303  
-// check a real xml example
304  
-// probably want to get rid of binary_op
305  
-//    or move it into test_expr
306  
-

0 notes on commit 91a0b42

Please sign in to comment.
Something went wrong with that request. Please try again.