Fri, 23 Apr 2021 21:15:05 +0100
New implementation of lxp.lom by Tom?s Guisasola
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 | #!/usr/local/bin/lua |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 | local lom = require "lxp.lom" |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 | |
36
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
5 | local u_acute_utf8 = string.char(195)..string.char(186) -- C3 BA |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
6 | local u_acute_latin1 = string.char(250) -- FA |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
7 | |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 | local tests = { |
36
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
9 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
10 | [[<abc a1="A1" a2="A2">inside tag `abc'</abc>]], |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
11 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
12 | tag="abc", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
13 | attr = { "a1", "a2", a1 = "A1", a2 = "A2", }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
14 | "inside tag `abc'", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
15 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
16 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
17 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
18 | [[<qwerty q1="q1" q2="q2"> |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 | <asdf>some text</asdf> |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 | </qwerty>]], |
36
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
21 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
22 | tag = "qwerty", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
23 | attr = { "q1", "q2", q1 = "q1", q2 = "q2", }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
24 | "\n\t", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
25 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
26 | tag = "asdf", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
27 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
28 | "some text", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
29 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
30 | "\n", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
31 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
32 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
33 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
34 | [[<ul><li>conteudo 1</li><li>conte]]..u_acute_utf8..[[do 2</li></ul>]], |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
35 | encoding = "UTF-8", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
36 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
37 | tag = "ul", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
38 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
39 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
40 | tag = "li", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
41 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
42 | "conteudo 1", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
43 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
44 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
45 | tag = "li", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
46 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
47 | "conteúdo 2", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
48 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
49 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
50 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
51 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
52 | [[<ul><li>Conteudo 1</li><li>Conte]]..u_acute_latin1..[[do 2</li><li>Conteúdo 3</li></ul>]], |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
53 | encoding = "ISO-8859-1", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
54 | doctype = [[<!DOCTYPE test [<!ENTITY uacute "ú">]>]], -- Ok! |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
55 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
56 | tag = "ul", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
57 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
58 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
59 | tag = "li", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
60 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
61 | "Conteudo 1", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
62 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
63 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
64 | tag = "li", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
65 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
66 | "Conteúdo 2", -- Latin-1 becomes UTF-8 |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
67 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
68 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
69 | tag = "li", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
70 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
71 | "Conteúdo 3", -- entity becomes a UTF-8 character |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
72 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
73 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
74 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
75 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
76 | [[<ul><li>Conteúdo</li></ul>]], |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
77 | --doctype = [[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">]], --> ignora as entidades |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
78 | --doctype = [[<!DOCTYPE html SYSTEM "about:legacy-compat">]], --> ignora as entidades |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
79 | --doctype = [[<!DOCTYPE html>]], --> undefined entity |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
80 | --doctype = [[<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">]], --> sintax error |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
81 | --doctype = [[<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" SYSTEM "http://www.w3.org/TR/html4/strict.dtd">]], --> syntax error |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
82 | --doctype = [[<!DOCTYPE HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1//EN//HTML">]], --> syntax error |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
83 | --doctype = [[<!DOCTYPE HTMLlat1 PUBLIC "-//W3C//ENTITIES Latin 1 for XHTML//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent">]], --> ignora entidades |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
84 | --doctype = [[<!DOCTYPE isolat1 PUBLIC "//W3C//ENTITIES Added Latin 1//EN//XML" "http://www.w3.org/2003/entities/2007/isolat1.ent">]], --> ignora entidades |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
85 | doctype = [[<!DOCTYPE test [<!ENTITY uacute "ú">]>]], -- Ok! |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
86 | encoding = "UTF-8", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
87 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
88 | tag = "ul", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
89 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
90 | { |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
91 | tag = "li", |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
92 | attr = {}, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
93 | "Conteúdo", -- entity becomes a UTF-8 character |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
94 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
95 | }, |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
96 | }, |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 | } |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 | |
36
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
99 | function table.equal (t1, t2) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
100 | for nome, val in pairs (t1) do |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
101 | local tv = type(val) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
102 | if tv == "table" then |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
103 | if type(t2[nome]) ~= "table" then |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
104 | return false, "Different types at entry `"..nome.."': t1."..nome.." is "..tv.." while t2."..nome.." is "..type(t2[nome]).." ["..tostring(t2[nome]).."]" |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
105 | else |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
106 | local ok, msg = table.equal (val, t2[nome]) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
107 | if not ok then |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
108 | return false, "["..nome.."]\t"..tostring(val).." ~= "..tostring(t2[nome]).."; "..msg |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
109 | end |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
110 | end |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
111 | else |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
112 | if val ~= t2[nome] then |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
113 | return false, "["..nome.."]\t["..tostring(val).."] ~= ["..tostring(t2[nome])..']' |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
114 | end |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
115 | end |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
116 | end |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
117 | return true |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 | end |
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 | |
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 | for i, s in ipairs(tests) do |
36
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
122 | io.write'.' |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
123 | local encoding = s.encoding or "ISO-8859-1" |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
124 | local header = [[<?xml version="1.0" encoding="]]..encoding..[["?>]]..(s.doctype or '') |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
125 | local doc = header..s[1] |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
126 | |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
127 | local o1 = assert (lom.parse (doc)) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
128 | assert(table.equal (o1, s[2])) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
129 | |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
130 | local o2 = assert (lom.parse (string.gmatch(doc, ".-%>"))) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
131 | assert(table.equal (o2, s[2])) |
0
24d141cb2d1e
Initial commit of LuaExpat 1.1.0
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 | end |
36
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
133 | |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
134 | local o = assert (lom.parse ([[ |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
135 | <?xml version="1.0"?> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
136 | <a1> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
137 | <b1> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
138 | <c1>t111</c1> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
139 | <c2>t112</c2> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
140 | </b1> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
141 | <b2> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
142 | <c1>t121</c1> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
143 | <c2>t122</c2> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
144 | </b2> |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
145 | </a1>]])) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
146 | assert (o.tag == "a1") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
147 | assert (o[1] == "\n\t") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
148 | assert (o[2].tag == "b1") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
149 | assert (o[2][2].tag == "c1") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
150 | local c1 = lom.find_elem (o, "c1") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
151 | assert (type(c1) == "table") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
152 | assert (c1.tag == "c1") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
153 | assert (c1[1] == "t111") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
154 | local next_child = lom.list_children (o) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
155 | assert (next_child().tag == "b1") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
156 | assert (next_child().tag == "b2") |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
157 | assert (next_child() == nil) |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
158 | |
4a61f00ee916
New implementation of lxp.lom by Tom?s Guisasola
Matthew Wild <mwild1@gmail.com>
parents:
0
diff
changeset
|
159 | print"OK" |