Sun, 19 Nov 2017 20:06:07 +0100
Keep callbacks in an uservalue instead of by reference
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 | |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
5 | if string.find(_VERSION, " 5.0") then |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
6 | lxp = assert(loadlib("./lxp.so", "luaopen_lxp"))() |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
7 | else |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
8 | lxp = require"lxp" |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
9 | gcinfo = function () return collectgarbage"count" end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
10 | end |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 | print (lxp._VERSION) |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
12 | assert(lxp.new, "Cannot find function lxp.new ("..tostring(lxp.new)..")") |
0
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 | -- basic test with no preamble |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 | local p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 | p:setencoding("ISO-8859-1") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 | assert(p:parse[[<tag cap="5">hi</tag>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | |
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 | preamble = [[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 | <?xml version="1.0" encoding="ISO-8859-1"?> |
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 | <!DOCTYPE greeting [ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 | <!ENTITY xuxu "is this a xuxu?"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 | <!ATTLIST to |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 | method CDATA #FIXED "POST" |
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 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 | <!ENTITY test-entity |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 | SYSTEM "entity1.xml"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 | <!NOTATION TXT SYSTEM "txt"> |
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 | <!ENTITY test-unparsed SYSTEM "unparsed.txt" NDATA txt> |
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 | <!ATTLIST hihi |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 | explanation ENTITY #REQUIRED> |
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 | ]> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 | ]] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 | |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
44 | X = {} |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
45 | if string.find(_VERSION, " 5.0") then |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
46 | function getargs (...) X = arg end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
47 | function xgetargs (c) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
48 | return function (...) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
49 | table.insert(arg, 1, c) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
50 | table.insert(X, arg) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
51 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
52 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
53 | else |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
54 | (loadstring or load)[[ |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
55 | function getargs (...) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
56 | X = { ... } |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
57 | X.n = select('#', ...) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
58 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
59 | function xgetargs (c) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
60 | return function (...) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
61 | local arg = { ... } |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
62 | arg.n = select('#', ...) + 1 |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
63 | table.insert(arg, 1, c) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
64 | table.insert(X, arg) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
65 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
66 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
67 | table.getn = function (t) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
68 | if t.n then |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
69 | return t.n |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
70 | else |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
71 | local n = 0 |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
72 | for i in pairs(t) do |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
73 | if type(i) == "number" then |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
74 | n = math.max(n, i) |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
75 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
76 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
77 | return n |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
78 | end |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
79 | end]]() |
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
80 | end |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 | print("testing start/end tags") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 | StartElement = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 | EndElement = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 | assert(p:getcallbacks() == callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 | assert(p:parse([[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 | <to priority="10" xu = "hi"> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 | ]])) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 | 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
|
97 | x = X[3] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | assert(x.priority=="10" and x.xu=="hi" and x.method=="POST") |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
99 | assert(x[1] == "priority" and x[2] == "xu" and table.getn(x) == 2, "x[1] == "..tostring(x[1])..", x[2] == "..tostring(x[2])..", #x == "..tostring(table.getn(x))) |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 | assert(p:parse("</to>")) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 | assert(p:parse()) |
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 CharacterData/Cdata") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 | CharacterData = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 | 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
|
113 | 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
|
114 | callbacks.chardata = error -- no more calls to `chardata' |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 | assert(p:parse("")) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 | assert(p:parse()) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 | -- 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
|
118 | assert(p:getcallbacks() == callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 | CharacterData = xgetargs"c", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 | StartCdataSection = xgetargs"s", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 | EndCdataSection = xgetargs"e", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 | assert(p:parse"<to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 | assert(p:parse"<![CDATA[hi]]>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | assert(table.getn(X) == 3) |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
133 | assert(X[1][1] == "s" and X[1][2] == p, "X[1][1] == "..tostring(X[1][1])..", X[1][2] == "..tostring(X[1][2])..", p == "..tostring(p)) |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 | 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
|
135 | 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
|
136 | assert(p:parse"</to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 | p:close() |
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 | ------------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 | print("testing ProcessingInstruction") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 | callbacks = {ProcessingInstruction = getargs} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 | <to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 | <?lua how is this passed to <here>? ?> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 | </to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 | 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
|
150 | X[3] == "how is this passed to <here>? ") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 | ------------------------------ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 | print("testing Comment") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 | callbacks = {Comment = xgetargs"c"; CharacterData = xgetargs"t"} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 | <to>some text |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 | <!-- <a comment> with some & symbols --> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 | some more text</to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 | p:close() |
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 | 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
|
168 | 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
|
169 | assert(X[1][3] == "some text\n") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 | 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
|
171 | assert(X[3][3] == "\nsome more text") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 | print("testing ExternalEntity") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 | entities = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 | ["entity1.xml"] = "<hi/>" |
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 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 | callbacks = {StartElement = xgetargs"s", EndElement = xgetargs"e", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 | ExternalEntityRef = function (p, context, base, systemID, publicId) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 | assert(base == "/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 | return context:parse(entities[systemID]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 | end} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 | p:setbase("/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 | <to> &test-entity; |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 | </to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 | assert(p:getbase() == "/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 | 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
|
197 | 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
|
198 | 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
|
199 | 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
|
200 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 | print("testing default handles") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 | text = [[<to> hi &xuxu; </to>]] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 | local t = "" |
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 | 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
|
208 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 | assert(p:parse(text)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 | assert(t == preamble..text) |
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 | t = "" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 | 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
|
216 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 | assert(p:parse(text)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 | 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
|
221 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 | print("testing notation declarations and unparsed entities") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 | callbacks = { |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 | UnparsedEntityDecl = getargs, |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 | NotationDecl = function (p, name, base, systemId, publicId) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 | 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
|
230 | end, |
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 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 | p:setbase("/base") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 | assert(p:parse(preamble)) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 | assert(p:parse[[<hihi explanation="test-unparsed"/>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 | 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
|
238 | 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
|
239 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 | ---------------------------- |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 | print("testing namespace declarations") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 | callbacks = { StartNamespaceDecl = xgetargs"sn", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 | EndNamespaceDecl = xgetargs"en", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 | StartElement = xgetargs"s", |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 | EndElement = xgetargs"e", |
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 | X = {} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 | p = lxp.new(callbacks, "?") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
252 | <x xmlns:space='a/namespace'> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
253 | <space:a/> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
254 | </x> |
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:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 | x = X[1] |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
258 | assert(x[1] == "sn" and x[3] == "space" and x[4] == "a/namespace" and table.getn(x) == 4, "x[1] == "..tostring(x[1])..", x[3] == "..tostring(x[3])..", x[4] == "..tostring(x[4])..", #x == "..tostring(table.getn(x))) |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 | x = X[3] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 | 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
|
261 | x = X[4] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 | 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
|
263 | x = X[6] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 | 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
|
265 | |
3
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
266 | ---------------------------- |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
267 | print("testing doctype declarations") |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 | |
3
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
269 | callbacks = { |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
270 | StartDoctypeDecl = getargs |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
271 | } |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
272 | p = lxp.new(callbacks) |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
273 | assert(p:parse([[<!DOCTYPE root PUBLIC "foo" "hello-world">]])) |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
274 | assert(p:parse[[<root/>]]) |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
275 | p:close() |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
276 | assert(X[2] == "root" and X[3] == "hello-world" and X[4] == "foo" and |
d7524f665625
Add test for StartDoctypeDecl
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
277 | X[5] == false) |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 | -- Error reporting |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 | data = [[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 | <tag> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 | <other< </other> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 | </tag> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 | ]] |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 | 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
|
287 | 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
|
288 | assert(string.sub(data, byte, byte) == "<") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 | p:parse("<to>") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 | local status, msg, line, col, byte = p:parse() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 | 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
|
294 | |
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 | -- position reporting |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 | callbacks = { ProcessingInstruction = function (p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 | X = {p:pos()} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 | end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 | p = lxp.new(callbacks) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 | assert(p:parse[[ |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 | <to> <?test where is `pos'? ?> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 | </to> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 | ]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 | p:close() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 | 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
|
309 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 | print("testing errors") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 | -- invalid keys |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 | assert(not pcall(lxp.new, {StatCdata=print})) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 | assert(pcall(lxp.new, {StatCdata=print, _nonstrict = true})) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 | -- invalid sequences |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 | assert(p:parse[[<to></to>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 | assert(p:parse()) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 | assert(p:parse(" ") == nil) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 | -- closing unfinished document |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 | p = lxp.new{} |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 | assert(p:parse[[<to>]]) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 | local status, err = pcall(p.close, p) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 | 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
|
328 | |
4 | 329 | -- closing unfinished document |
330 | print("testing parser:stop()"); | |
331 | local stopped; | |
332 | p = lxp.new{ | |
333 | StartElement = function (parser, name, attr) | |
334 | if name == "stop" then | |
335 | parser:stop() | |
336 | stopped = true | |
337 | else | |
338 | stopped = false | |
339 | end | |
340 | end | |
341 | } | |
342 | local ok, err = p:parse[[<root><parseme>Hello</parseme><stop>here</stop><notparsed/></root>]]; | |
343 | assert(not ok) | |
344 | assert(err == "parsing aborted") | |
345 | assert(stopped == true, "parser not stopped") | |
346 | ||
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 | -- test for GC |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 | print("\ntesting garbage collection") |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 | collectgarbage(); collectgarbage() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 | local x = gcinfo() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
352 | for i=1,100000 do |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 | -- due to a small bug in Lua... |
11
b2a77ebe7aed
test.lua: Expand tests and add compatibility with Lua 5.2
Tom?s Guisasola Gorham <tomas@tecgraf.puc-rio.br>
parents:
4
diff
changeset
|
354 | if (math.mod or math.fmod)(i, 100) == 0 then collectgarbage() end |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
355 | lxp.new({}) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 | end |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 | collectgarbage(); collectgarbage() |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 | assert(math.abs(gcinfo() - x) <= 2) |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
359 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
361 | print"OK" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
362 |