Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,89 @@
|
||||
module main
|
||||
|
||||
import encoding.xml
|
||||
import os
|
||||
|
||||
fn test_large_gtk_file() ! {
|
||||
// Note: If you are contributing to this project, you should download the
|
||||
// GIR file from https://raw.githubusercontent.com/gtk-rs/gir-files/master/Gtk-4.0.gir
|
||||
// and place it in the same directory as this file.
|
||||
path := os.join_path(os.dir(@FILE), 'Gtk-4.0.gir')
|
||||
if !os.exists(path) {
|
||||
println('Skipping test_large_gtk_file because file does not exist.')
|
||||
return
|
||||
}
|
||||
|
||||
actual := xml.XMLDocument.from_file(path) or {
|
||||
return error('Failed to parse large GTK XML file')
|
||||
}
|
||||
|
||||
mut valid := false
|
||||
for elm in actual.get_elements_by_tag('class') {
|
||||
if 'c:type' in elm.attributes && elm.attributes['c:type'] == 'GtkWindow' {
|
||||
assert elm.attributes['parent'] == 'Widget'
|
||||
assert elm.attributes['c:symbol-prefix'] == 'window'
|
||||
valid = true
|
||||
}
|
||||
}
|
||||
assert valid, 'GtkWindow class not found!'
|
||||
|
||||
valid = false
|
||||
for elm in actual.get_elements_by_tag('constructor') {
|
||||
if 'c:identifier' in elm.attributes && elm.attributes['c:identifier'] == 'gtk_window_new' {
|
||||
assert elm == xml.XMLNode{
|
||||
name: 'constructor'
|
||||
attributes: {
|
||||
'name': 'new'
|
||||
'c:identifier': 'gtk_window_new'
|
||||
}
|
||||
children: [
|
||||
xml.XMLNodeContents(xml.XMLNode{
|
||||
name: 'doc'
|
||||
attributes: {
|
||||
'xml:space': 'preserve'
|
||||
}
|
||||
children: [
|
||||
xml.XMLNodeContents('Creates a new `GtkWindow`.
|
||||
|
||||
To get an undecorated window (no window borders), use
|
||||
[method@Gtk.Window.set_decorated].
|
||||
|
||||
All top-level windows created by gtk_window_new() are stored
|
||||
in an internal top-level window list. This list can be obtained
|
||||
from [func@Gtk.Window.list_toplevels]. Due to GTK keeping a
|
||||
reference to the window internally, gtk_window_new() does not
|
||||
return a reference to the caller.
|
||||
|
||||
To delete a `GtkWindow`, call [method@Gtk.Window.destroy].'),
|
||||
]
|
||||
}),
|
||||
xml.XMLNodeContents(xml.XMLNode{
|
||||
name: 'return-value'
|
||||
attributes: {
|
||||
'transfer-ownership': 'none'
|
||||
}
|
||||
children: [
|
||||
xml.XMLNodeContents(xml.XMLNode{
|
||||
name: 'doc'
|
||||
attributes: {
|
||||
'xml:space': 'preserve'
|
||||
}
|
||||
children: [xml.XMLNodeContents('a new `GtkWindow`.')]
|
||||
}),
|
||||
xml.XMLNodeContents(xml.XMLNode{
|
||||
name: 'type'
|
||||
attributes: {
|
||||
'name': 'Widget'
|
||||
'c:type': 'GtkWidget*'
|
||||
}
|
||||
children: []
|
||||
}),
|
||||
]
|
||||
}),
|
||||
]
|
||||
}
|
||||
valid = true
|
||||
}
|
||||
}
|
||||
assert valid, 'gtk_window_new constructor not found!'
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<message>
|
||||
<greeting>
|
||||
Hello, World!
|
||||
</greeting>
|
||||
</message>
|
||||
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'hello_world.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'message'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'greeting'
|
||||
children: [
|
||||
'Hello, World!',
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<note>
|
||||
<to>Tove</to>
|
||||
<from>Jani</from>
|
||||
<heading>Reminder</heading>
|
||||
<body>Don't forget me this weekend!</body>
|
||||
</note>
|
||||
@@ -0,0 +1,41 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'note.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'note'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'to'
|
||||
children: [
|
||||
'Tove',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'from'
|
||||
children: [
|
||||
'Jani',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'heading'
|
||||
children: [
|
||||
'Reminder',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'body'
|
||||
children: [
|
||||
"Don't forget me this weekend!",
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<CATALOG>
|
||||
<CD>
|
||||
<TITLE>Empire Burlesque</TITLE>
|
||||
<ARTIST>Bob Dylan</ARTIST>
|
||||
<COUNTRY>USA</COUNTRY>
|
||||
<COMPANY>Columbia</COMPANY>
|
||||
<PRICE>10.90</PRICE>
|
||||
<YEAR>1985</YEAR>
|
||||
</CD>
|
||||
<CD>
|
||||
<TITLE>Hide your heart</TITLE>
|
||||
<ARTIST>Bonnie Tyler</ARTIST>
|
||||
<COUNTRY>UK</COUNTRY>
|
||||
<COMPANY>CBS Records</COMPANY>
|
||||
<PRICE>9.90</PRICE>
|
||||
<YEAR>1988</YEAR>
|
||||
</CD>
|
||||
<CD>
|
||||
<TITLE>Greatest Hits</TITLE>
|
||||
<ARTIST>Dolly Parton</ARTIST>
|
||||
<COUNTRY>USA</COUNTRY>
|
||||
<COMPANY>RCA</COMPANY>
|
||||
<PRICE>9.90</PRICE>
|
||||
<YEAR>1982</YEAR>
|
||||
</CD>
|
||||
<CD>
|
||||
<TITLE>Still got the blues</TITLE>
|
||||
<ARTIST>Gary Moore</ARTIST>
|
||||
<COUNTRY>UK</COUNTRY>
|
||||
<COMPANY>Virgin records</COMPANY>
|
||||
<PRICE>10.20</PRICE>
|
||||
<YEAR>1990</YEAR>
|
||||
</CD>
|
||||
</CATALOG>
|
||||
@@ -0,0 +1,181 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'cd_catalog.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'CATALOG'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'CD'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'TITLE'
|
||||
children: [
|
||||
'Empire Burlesque',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'ARTIST'
|
||||
children: [
|
||||
'Bob Dylan',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COUNTRY'
|
||||
children: [
|
||||
'USA',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COMPANY'
|
||||
children: [
|
||||
'Columbia',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'PRICE'
|
||||
children: [
|
||||
'10.90',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'YEAR'
|
||||
children: [
|
||||
'1985',
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'CD'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'TITLE'
|
||||
children: [
|
||||
'Hide your heart',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'ARTIST'
|
||||
children: [
|
||||
'Bonnie Tyler',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COUNTRY'
|
||||
children: [
|
||||
'UK',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COMPANY'
|
||||
children: [
|
||||
'CBS Records',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'PRICE'
|
||||
children: [
|
||||
'9.90',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'YEAR'
|
||||
children: [
|
||||
'1988',
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'CD'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'TITLE'
|
||||
children: [
|
||||
'Greatest Hits',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'ARTIST'
|
||||
children: [
|
||||
'Dolly Parton',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COUNTRY'
|
||||
children: [
|
||||
'USA',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COMPANY'
|
||||
children: [
|
||||
'RCA',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'PRICE'
|
||||
children: [
|
||||
'9.90',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'YEAR'
|
||||
children: [
|
||||
'1982',
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'CD'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'TITLE'
|
||||
children: [
|
||||
'Still got the blues',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'ARTIST'
|
||||
children: [
|
||||
'Gary Moore',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COUNTRY'
|
||||
children: [
|
||||
'UK',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'COMPANY'
|
||||
children: [
|
||||
'Virgin records',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'PRICE'
|
||||
children: [
|
||||
'10.20',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'YEAR'
|
||||
children: [
|
||||
'1990',
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1 @@
|
||||
XML document is empty.
|
||||
@@ -0,0 +1 @@
|
||||
<sample>Single root element.</sample>
|
||||
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'root.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'sample'
|
||||
children: [
|
||||
'Single root element.',
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<level1>
|
||||
<level2>
|
||||
<level3>
|
||||
<level4>
|
||||
Deeply nested content.
|
||||
</level4>
|
||||
</level3>
|
||||
</level2>
|
||||
<level2>
|
||||
<level3>
|
||||
Less deeply nested content.
|
||||
</level3>
|
||||
</level2>
|
||||
</level1>
|
||||
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'nested.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'level1'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'level2'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'level3'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'level4'
|
||||
children: [
|
||||
'Deeply nested content.',
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'level2'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'level3'
|
||||
children: [
|
||||
'Less deeply nested content.',
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<letter>
|
||||
Dear Mr. <name>John Smith</name>.
|
||||
Your order <orderid>1032</orderid>
|
||||
will be shipped on <shipdate>2001-07-13</shipdate>.
|
||||
</letter>
|
||||
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'mixed.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'letter'
|
||||
children: [
|
||||
'Dear Mr.',
|
||||
xml.XMLNode{
|
||||
name: 'name'
|
||||
children: ['John Smith']
|
||||
},
|
||||
'.\n Your order',
|
||||
xml.XMLNode{
|
||||
name: 'orderid'
|
||||
children: ['1032']
|
||||
},
|
||||
'will be shipped on',
|
||||
xml.XMLNode{
|
||||
name: 'shipdate'
|
||||
children: ['2001-07-13']
|
||||
},
|
||||
'.',
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!-- Employee Information-->
|
||||
<address>
|
||||
<!-- Full or first name -->
|
||||
<name>Jones</name>
|
||||
<!-- Registered name of the company -> -->
|
||||
<company>ABSystems</company>
|
||||
<phone>
|
||||
<!-- Phone with country code -) -->
|
||||
(046) 1233-44778
|
||||
</phone>
|
||||
</address>
|
||||
@@ -0,0 +1,42 @@
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() ! {
|
||||
path := os.join_path(os.dir(@FILE), 'comment.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
comments: [
|
||||
xml.XMLComment{
|
||||
text: ' Employee Information'
|
||||
},
|
||||
]
|
||||
root: xml.XMLNode{
|
||||
name: 'address'
|
||||
children: [
|
||||
xml.XMLComment{
|
||||
text: ' Full or first name '
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'name'
|
||||
children: ['Jones']
|
||||
},
|
||||
xml.XMLComment{
|
||||
text: ' Registered name of the company -> '
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'company'
|
||||
children: ['ABSystems']
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'phone'
|
||||
children: [xml.XMLComment{
|
||||
text: ' Phone with country code -) '
|
||||
}, '(046) 1233-44778']
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Malformed XML. Found "<" in attribute string: "<body"
|
||||
@@ -0,0 +1 @@
|
||||
<message <body>Sample</body></message>
|
||||
@@ -0,0 +1 @@
|
||||
XML node <warning> not closed.
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<message>
|
||||
<warning>
|
||||
Hello World
|
||||
<!--missing </warning> -->
|
||||
</message>
|
||||
@@ -0,0 +1,4 @@
|
||||
<sample>
|
||||
<html>This is <b>bold</b></html>
|
||||
<html><![CDATA[This is <b>bold</b>]]></html>
|
||||
</sample>
|
||||
@@ -0,0 +1,29 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() {
|
||||
path := os.join_path(os.dir(@FILE), 'cdata.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'sample'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'html'
|
||||
children: ['This is <b>bold</b>']
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'html'
|
||||
children: [xml.XMLCData{
|
||||
text: 'This is <b>bold</b>'
|
||||
}]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE body [
|
||||
<!ENTITY warning "Warning: Something bad happened... please refresh and try again.">
|
||||
]>
|
||||
<body>
|
||||
<message> &warning; </message>
|
||||
</body>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE body [
|
||||
<!ENTITY warning "Warning: Something bad happened... please refresh and try again.">
|
||||
]>
|
||||
<body>
|
||||
<message>
|
||||
Warning: Something bad happened... please refresh and try again.
|
||||
</message>
|
||||
</body>
|
||||
@@ -0,0 +1,11 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() {
|
||||
expected := xml.XMLDocument.from_file(os.join_path(os.dir(@FILE), 'entity.xml'))!.validate()!
|
||||
actual :=
|
||||
xml.XMLDocument.from_file(os.join_path(os.dir(@FILE), 'entity_expected.xml'))!.validate()!
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() {
|
||||
path := os.join_path(os.dir(@FILE), 'element.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
doctype: xml.DocumentType{
|
||||
name: 'note'
|
||||
dtd: xml.DocumentTypeDefinition{
|
||||
name: ''
|
||||
list: [
|
||||
xml.DTDElement{
|
||||
name: 'note'
|
||||
definition: ['to', 'from', 'heading', 'body']
|
||||
},
|
||||
xml.DTDElement{
|
||||
name: 'to'
|
||||
definition: ['#PCDATA']
|
||||
},
|
||||
xml.DTDElement{
|
||||
name: 'from'
|
||||
definition: ['#PCDATA']
|
||||
},
|
||||
xml.DTDElement{
|
||||
name: 'heading'
|
||||
definition: ['#PCDATA']
|
||||
},
|
||||
xml.DTDElement{
|
||||
name: 'body'
|
||||
definition: ['#PCDATA']
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
root: xml.XMLNode{
|
||||
name: 'note'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'to'
|
||||
children: [
|
||||
'Tove',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'from'
|
||||
children: [
|
||||
'Jani',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'heading'
|
||||
children: [
|
||||
'Reminder',
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'body'
|
||||
children: [
|
||||
"Don't forget me this weekend!",
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!.validate()!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT note (to,from,heading,body)>
|
||||
<!ELEMENT to (#PCDATA)>
|
||||
<!ELEMENT from (#PCDATA)>
|
||||
<!ELEMENT heading (#PCDATA)>
|
||||
<!ELEMENT body (#PCDATA)>
|
||||
]>
|
||||
<note>
|
||||
<to>Tove</to>
|
||||
<from>Jani</from>
|
||||
<heading>Reminder</heading>
|
||||
<body>Don't forget me this weekend!</body>
|
||||
</note>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<book category="web">
|
||||
<title lang="en" code:type="const char*">Learning XML</title>
|
||||
<author attr=" surrounding spaces ">Erik T. Ray</author>
|
||||
<year>2003</year>
|
||||
<price>39.95</price>
|
||||
</book>
|
||||
@@ -0,0 +1,45 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() {
|
||||
path := os.join_path(os.dir(@FILE), 'attributes.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'book'
|
||||
attributes: {
|
||||
'category': 'web'
|
||||
}
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'title'
|
||||
attributes: {
|
||||
'lang': 'en'
|
||||
'code:type': 'const char*'
|
||||
}
|
||||
children: ['Learning XML']
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'author'
|
||||
attributes: {
|
||||
'attr': ' surrounding spaces '
|
||||
}
|
||||
children: ['Erik T. Ray']
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'year'
|
||||
children: ['2003']
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'price'
|
||||
children: ['39.95']
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE body [
|
||||
<!ENTITY>
|
||||
]>
|
||||
<body>
|
||||
</body>
|
||||
@@ -0,0 +1 @@
|
||||
Entity is missing name.
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE body [
|
||||
<!ENTITY missing>
|
||||
]>
|
||||
<body>
|
||||
&missing;
|
||||
</body>
|
||||
@@ -0,0 +1 @@
|
||||
Entity is missing value.
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT>
|
||||
]>
|
||||
<note>
|
||||
</note>
|
||||
@@ -0,0 +1 @@
|
||||
Element is missing name.
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE note [
|
||||
<!ELEMENT note invalid>
|
||||
]>
|
||||
<note>
|
||||
</note>
|
||||
@@ -0,0 +1 @@
|
||||
Invalid element definition: invalid
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<sst count="5" uniqueCount="5">
|
||||
<si>
|
||||
<t a="1">Item 1</t>
|
||||
</si>
|
||||
<si>
|
||||
<t>Item 2</t>
|
||||
</si>
|
||||
<si>
|
||||
<t>Item 3</t>
|
||||
</si>
|
||||
<si>
|
||||
<t>Item 4</t>
|
||||
</si>
|
||||
<si>
|
||||
<t>Item 5</t>
|
||||
</si>
|
||||
</sst>
|
||||
@@ -0,0 +1,71 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() {
|
||||
path := os.join_path(os.dir(@FILE), 'shared.xml')
|
||||
|
||||
expected := xml.XMLDocument{
|
||||
root: xml.XMLNode{
|
||||
name: 'sst'
|
||||
attributes: {
|
||||
'count': '5'
|
||||
'uniqueCount': '5'
|
||||
}
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 'si'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 't'
|
||||
attributes: {
|
||||
'a': '1'
|
||||
}
|
||||
children: ['Item 1']
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'si'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 't'
|
||||
children: ['Item 2']
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'si'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 't'
|
||||
children: ['Item 3']
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'si'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 't'
|
||||
children: ['Item 4']
|
||||
},
|
||||
]
|
||||
},
|
||||
xml.XMLNode{
|
||||
name: 'si'
|
||||
children: [
|
||||
xml.XMLNode{
|
||||
name: 't'
|
||||
children: ['Item 5']
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
actual := xml.XMLDocument.from_file(path)!
|
||||
|
||||
assert expected == actual, 'Parsed XML document should be equal to expected XML document'
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
fn test_valid_parsing() {
|
||||
// We use a .bin file to avoid stripping the BOM from the XML file
|
||||
path := os.join_path(os.dir(@FILE), 'workbook.bin')
|
||||
|
||||
doc := xml.XMLDocument.from_file(path) or {
|
||||
assert false, 'Failed to parse workbook.bin'
|
||||
exit(1)
|
||||
}
|
||||
|
||||
sheets := doc.get_elements_by_tag('sheet')
|
||||
assert sheets.len == 1, 'Expected 1 sheet, got ${sheets.len}'
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x15" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main">
|
||||
<fileVersion appName="xl" lastEdited="6" lowestEdited="6" rupBuild="14420"/>
|
||||
<workbookPr defaultThemeVersion="164011"/>
|
||||
<bookViews>
|
||||
<workbookView xWindow="0" yWindow="0" windowWidth="22260" windowHeight="12645"/>
|
||||
</bookViews>
|
||||
<sheets>
|
||||
<sheet name="Sheet1" sheetId="1" r:id="rId1"/>
|
||||
</sheets>
|
||||
<calcPr calcId="162913"/>
|
||||
<extLst>
|
||||
<ext uri="{140A7094-0E35-4892-8432-C4D2E57EDEB5}" xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main">
|
||||
<x15:workbookPr chartTrackingRefBase="1"/>
|
||||
</ext>
|
||||
</extLst>
|
||||
</workbook>
|
||||
@@ -0,0 +1,25 @@
|
||||
module main
|
||||
|
||||
import os
|
||||
import encoding.xml
|
||||
|
||||
// All the XML files in the spec directory obtained recursively
|
||||
const spec_files = os.walk_ext(os.join_path(os.dir(@FILE), 'local'), 'xml')
|
||||
|
||||
fn test_can_parse_all_files() ! {
|
||||
assert spec_files.len > 0, 'No XML files found in the spec directory'
|
||||
for file in spec_files {
|
||||
doc := xml.XMLDocument.from_file(file) or {
|
||||
// Parsing failed. Check if this was an expected error.
|
||||
parent := os.dir(file)
|
||||
error_file := os.join_path(parent, 'expected_error.txt')
|
||||
error_text := os.read_file(error_file) or {
|
||||
// No expected error. Fail the test.
|
||||
return error('Failed to parse XML file: ' + file)
|
||||
}
|
||||
// Check if the error message matches the expected error.
|
||||
assert err.msg().trim_space() == error_text.trim_space()
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user