v / vlib / encoding / xml / test / gtk / gtk_test.v
89 lines · 81 sloc · 2.45 KB · acf6b344f733169ec6ecc9881f8a8c2c795b9883
Raw
1module main
2
3import encoding.xml
4import os
5
6fn test_large_gtk_file() ! {
7 // Note: If you are contributing to this project, you should download the
8 // GIR file from https://raw.githubusercontent.com/gtk-rs/gir-files/master/Gtk-4.0.gir
9 // and place it in the same directory as this file.
10 path := os.join_path(os.dir(@FILE), 'Gtk-4.0.gir')
11 if !os.exists(path) {
12 println('Skipping test_large_gtk_file because file does not exist.')
13 return
14 }
15
16 actual := xml.XMLDocument.from_file(path) or {
17 return error('Failed to parse large GTK XML file')
18 }
19
20 mut valid := false
21 for elm in actual.get_elements_by_tag('class') {
22 if 'c:type' in elm.attributes && elm.attributes['c:type'] == 'GtkWindow' {
23 assert elm.attributes['parent'] == 'Widget'
24 assert elm.attributes['c:symbol-prefix'] == 'window'
25 valid = true
26 }
27 }
28 assert valid, 'GtkWindow class not found!'
29
30 valid = false
31 for elm in actual.get_elements_by_tag('constructor') {
32 if 'c:identifier' in elm.attributes && elm.attributes['c:identifier'] == 'gtk_window_new' {
33 assert elm == xml.XMLNode{
34 name: 'constructor'
35 attributes: {
36 'name': 'new'
37 'c:identifier': 'gtk_window_new'
38 }
39 children: [
40 xml.XMLNodeContents(xml.XMLNode{
41 name: 'doc'
42 attributes: {
43 'xml:space': 'preserve'
44 }
45 children: [
46 xml.XMLNodeContents('Creates a new `GtkWindow`.
47
48To get an undecorated window (no window borders), use
49[[email protected]_decorated].
50
51All top-level windows created by gtk_window_new() are stored
52in an internal top-level window list. This list can be obtained
53from [[email protected]_toplevels]. Due to GTK keeping a
54reference to the window internally, gtk_window_new() does not
55return a reference to the caller.
56
57To delete a `GtkWindow`, call [[email protected]].'),
58 ]
59 }),
60 xml.XMLNodeContents(xml.XMLNode{
61 name: 'return-value'
62 attributes: {
63 'transfer-ownership': 'none'
64 }
65 children: [
66 xml.XMLNodeContents(xml.XMLNode{
67 name: 'doc'
68 attributes: {
69 'xml:space': 'preserve'
70 }
71 children: [xml.XMLNodeContents('a new `GtkWindow`.')]
72 }),
73 xml.XMLNodeContents(xml.XMLNode{
74 name: 'type'
75 attributes: {
76 'name': 'Widget'
77 'c:type': 'GtkWidget*'
78 }
79 children: []
80 }),
81 ]
82 }),
83 ]
84 }
85 valid = true
86 }
87 }
88 assert valid, 'gtk_window_new constructor not found!'
89}
90