Wed, 01 Jun 2011 22:14:25 +0100
Initial commit of LuaExpat 1.1.0
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | #!/usr/local/bin/lua5.1 |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | -- See Copyright Notice in license.html |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | -- $Id: test.lua,v 1.6 2006/06/08 20:34:52 tomas Exp $ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 | require"lxp" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 | print (lxp._VERSION) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | -- basic test with no preamble |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 | local p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 | p:setencoding("ISO-8859-1") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | assert(p:parse[[<tag cap="5">hi</tag>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | preamble = [[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | <?xml version="1.0" encoding="ISO-8859-1"?> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | <!DOCTYPE greeting [ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | <!ENTITY xuxu "is this a xuxu?"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 | <!ATTLIST to |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | method CDATA #FIXED "POST" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 | > |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | <!ENTITY test-entity |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | SYSTEM "entity1.xml"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | <!NOTATION TXT SYSTEM "txt"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 | <!ENTITY test-unparsed SYSTEM "unparsed.txt" NDATA txt> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | <!ATTLIST hihi |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | explanation ENTITY #REQUIRED> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 | ]> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 | ]] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 | local X |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | function getargs (...) X = arg end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 | function xgetargs (c) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | return function (...) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | table.insert(arg, 1, c) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 | table.insert(X, arg) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 | end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 | end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | print("testing start/end tags") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 | StartElement = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 | EndElement = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 | assert(p:getcallbacks() == callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 | assert(p:parse([[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 | <to priority="10" xu = "hi"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 | ]])) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 | assert(X.n == 3 and X[1] == p and X[2] == "to") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 | x = X[3] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 | assert(x.priority=="10" and x.xu=="hi" and x.method=="POST") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 | assert(x[1] == "priority" and x[2] == "xu" and table.getn(x) == 2) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 | assert(p:parse("</to>")) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 | assert(p:parse()) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 | print("testing CharacterData/Cdata") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 | CharacterData = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 | assert(p:parse"<to>a basic text<<![CDATA[<<ha>>]]></to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 | assert(X[1] == p and X[2] == "a basic text<<<ha>>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 | callbacks.chardata = error -- no more calls to `chardata' |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | assert(p:parse("")) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | assert(p:parse()) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | -- assert(p:parse()) -- no problem to finish twice. alas, it has problems |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | assert(p:getcallbacks() == callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | CharacterData = xgetargs"c", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 | StartCdataSection = xgetargs"s", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 | EndCdataSection = xgetargs"e", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 | assert(p:parse"<to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 | assert(p:parse"<![CDATA[hi]]>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 | assert(table.getn(X) == 3) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | assert(X[1][1] == "s" and X[1][2] == p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 | assert(X[2][1] == "c" and X[2][2] == p and X[2][3] == "hi") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 | assert(X[3][1] == "e" and X[3][2] == p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 | assert(p:parse"</to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 | print("testing ProcessingInstruction") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 | callbacks = {ProcessingInstruction = getargs} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 | <to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 | <?lua how is this passed to <here>? ?> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 | </to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 | assert(X[1] == p and X[2] == "lua" and |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 | X[3] == "how is this passed to <here>? ") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 | ------------------------------ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 | print("testing Comment") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 | callbacks = {Comment = xgetargs"c"; CharacterData = xgetargs"t"} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 | <to>some text |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 | <!-- <a comment> with some & symbols --> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 | some more text</to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | assert(X[1][1] == "t" and X[2][1] == "c" and X[3][1] == "t") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 | assert(X[1][2] == X[2][2] and X[2][2] == X[3][2] and X[3][2] == p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 | assert(X[1][3] == "some text\n") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 | assert(X[2][3] == " <a comment> with some & symbols ") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 | assert(X[3][3] == "\nsome more text") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 | print("testing ExternalEntity") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 | entities = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 | ["entity1.xml"] = "<hi/>" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 | callbacks = {StartElement = xgetargs"s", EndElement = xgetargs"e", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 | ExternalEntityRef = function (p, context, base, systemID, publicId) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 | assert(base == "/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 | return context:parse(entities[systemID]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 | end} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 | p:setbase("/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 | <to> &test-entity; |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 | </to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 | assert(p:getbase() == "/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 | assert(X[1][1] == "s" and X[1][3] == "to") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 | assert(X[2][1] == "s" and X[2][3] == "hi") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 | assert(X[3][1] == "e" and X[3][3] == "hi") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 | assert(X[4][1] == "e" and X[4][3] == "to") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 | print("testing default handles") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 | text = [[<to> hi &xuxu; </to>]] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 | local t = "" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 | callbacks = { Default = function (p, s) t = t .. s end } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 | assert(p:parse(text)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 | assert(t == preamble..text) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 | t = "" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 | callbacks = { DefaultExpand = function (p, s) t = t .. s end } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 | assert(p:parse(text)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 | assert(t == preamble..string.gsub(text, "&xuxu;", "is this a xuxu?")) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 | print("testing notation declarations and unparsed entities") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 | UnparsedEntityDecl = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 | NotationDecl = function (p, name, base, systemId, publicId) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 | assert(name == "TXT" and systemId == "txt" and base == "/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 | end, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 | p:setbase("/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 | assert(p:parse[[<hihi explanation="test-unparsed"/>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 | assert(X[2] == "test-unparsed" and X[3] == "/base" and |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 | X[4] == "unparsed.txt" and X[6] == "txt" and X.n == 6) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 | print("testing namespace declarations") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 | callbacks = { StartNamespaceDecl = xgetargs"sn", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 | EndNamespaceDecl = xgetargs"en", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 | StartElement = xgetargs"s", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 | EndElement = xgetargs"e", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 | p = lxp.new(callbacks, "?") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 | <x xmlns:space='a/namespace'> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 | <space:a/> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 | </x> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 | x = X[1] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 | assert(x[1] == "sn" and x[3] == "space" and x[4] == "a/namespace" and table.getn(x) == 4) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 | x = X[3] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 | assert(x[1] == "s" and x[3] == "a/namespace?a") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 | x = X[4] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 | assert(x[1] == "e" and x[3] == "a/namespace?a") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 | x = X[6] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 | assert(x[1] == "en" and x[3] == "space" and table.getn(x) == 3) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 | -- Error reporting |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 | data = [[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 | <tag> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 | <other< </other> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 | </tag> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 | ]] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 | local status, msg, line, col, byte = p:parse(data) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 | assert(status == nil and type(msg) == "string" and line == 2 and col == 9) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 | assert(string.sub(data, byte, byte) == "<") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 | p:parse("<to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 | local status, msg, line, col, byte = p:parse() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 | assert(status == nil and line == 1 and col == 5 and byte == 5) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
249 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 | -- position reporting |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 | callbacks = { ProcessingInstruction = function (p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
252 | X = {p:pos()} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
253 | end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
254 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
255 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
258 | <to> <?test where is `pos'? ?> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 | </to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
261 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 | assert(X[1] == 1 and X[2] == 6 and X[3] == 6) -- line, column, abs. position |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
263 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 | print("testing errors") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 | -- invalid keys |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 | assert(not pcall(lxp.new, {StatCdata=print})) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 | assert(pcall(lxp.new, {StatCdata=print, _nonstrict = true})) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
271 | -- invalid sequences |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 | assert(p:parse[[<to></to>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 | assert(p:parse()) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 | assert(p:parse(" ") == nil) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
276 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 | -- closing unfinished document |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 | assert(p:parse[[<to>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 | local status, err = pcall(p.close, p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 | assert(not status and string.find(err, "error closing parser")) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 | -- test for GC |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 | print("\ntesting garbage collection") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 | collectgarbage(); collectgarbage() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 | local x = gcinfo() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 | for i=1,100000 do |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 | -- due to a small bug in Lua... |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 | if math.mod(i, 100) == 0 then collectgarbage() end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 | lxp.new({}) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 | end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 | collectgarbage(); collectgarbage() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 | assert(math.abs(gcinfo() - x) <= 2) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 | print"OK" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 |