-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path103-xml.t
118 lines (97 loc) · 2.23 KB
/
103-xml.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use v6;
use Test;
use SemiXML::Sxml;
#-------------------------------------------------------------------------------
# Testing;
# Test $tag [ ... ] Normal content
# Test $tag « ... » Text only no child elements
# Test $*!tag [ ... ] Spacing around tags
#
#-------------------------------------------------------------------------------
# Setup
my $dir = 't/D103';
mkdir $dir unless $dir.IO ~~ :e;
my $f1 = "$dir/test-file.sxml";
my $f2 = 't/D103/f1.html';
spurt( $f1, q:to/EOSX/);
$html [
$head [
$style type=text/css «
green {
color: #0f0;
background-color: #f0f;
}
»
$script «
var a_tags = $('a');
var b = a_tags[1];
»
]
$body [
$h1 class=green [ Data from file ]
$table [
$tr [
$th[ header ]
$td[ data at $a href='http://example.com/' []
$p [
bla bla $b [bla] bla $u [bla $b [bla]].
]
]
]
]
]
]
EOSX
#-------------------------------------------------------------------------------
my Hash $config = {
C => {
out-fmt => { :doctype-show, :xml-show },
},
F => {
in-fmt => {
space-preserve => [<style>,]
}
},
S => {
out-fmt => {
filename => 'f1',
rootpath => 't/D103',
fileext => 'html',
}
},
T => {
:tables, :parse, :file-handling
},
X => {
out-fmt => {
xml-version => 1.1,
xml-encoding => 'UTF-8',
}
},
}
# Parse
my SemiXML::Sxml $x .= new(:refine([<in-fmt out-fmt>]));
$x.parse( :filename($f1), :$config, :!trace, :!raw, :!keep);
my Str $xml-text = ~$x;
#diag $xml-text;
like $xml-text, /:s '<?' xml version '="1.1"' encoding '="UTF-8"' '?>' /,
'Xml prelude found';
like $xml-text, /:s '<!' DOCTYPE html '>' /, 'Doctype found';
ok $xml-text ~~ m/
'green {
color: #0f0;
background-color: #f0f;
}'
/, 'Check for literal text in css';
like $xml-text, /:s var a_tags '=' "\$('a');" var b '=' a_tags/,
'Check for literal text in javascript';
ok $xml-text ~~ ms/ '<tr>' '<th>' /, "'Th' after 'tr' found";
$x.save;
ok $f2.IO ~~ :e, "File $f2 written";
#-------------------------------------------------------------------------------
# Cleanup
unlink $f1;
unlink $f2;
rmdir $dir;
done-testing();
exit(0);