288 -- closing unfinished document |
288 -- closing unfinished document |
289 p = lxp.new{} |
289 p = lxp.new{} |
290 assert(p:parse[[<to>]]) |
290 assert(p:parse[[<to>]]) |
291 local status, err = pcall(p.close, p) |
291 local status, err = pcall(p.close, p) |
292 assert(not status and string.find(err, "error closing parser")) |
292 assert(not status and string.find(err, "error closing parser")) |
|
293 |
|
294 -- closing unfinished document |
|
295 print("testing parser:stop()"); |
|
296 local stopped; |
|
297 p = lxp.new{ |
|
298 StartElement = function (parser, name, attr) |
|
299 if name == "stop" then |
|
300 parser:stop() |
|
301 stopped = true |
|
302 else |
|
303 stopped = false |
|
304 end |
|
305 end |
|
306 } |
|
307 local ok, err = p:parse[[<root><parseme>Hello</parseme><stop>here</stop><notparsed/></root>]]; |
|
308 assert(not ok) |
|
309 assert(err == "parsing aborted") |
|
310 assert(stopped == true, "parser not stopped") |
293 |
311 |
294 |
312 |
295 -- test for GC |
313 -- test for GC |
296 print("\ntesting garbage collection") |
314 print("\ntesting garbage collection") |
297 collectgarbage(); collectgarbage() |
315 collectgarbage(); collectgarbage() |