-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path050-color.t
147 lines (122 loc) · 4.47 KB
/
050-color.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
use v6;
use Test;
use SemiXML::Sxml;
use XML::XPath;
#-------------------------------------------------------------------------------
subtest 'generated blended color variables 1', {
my $text = q:to/EOTXT/;
$x [
$!Colors.palette outspec=rgbhex base-rgb='#1200ff'
type=blended mode=averaged « »
$set0 [ $sxml:var-ref name=base-color [] ]
$set1 [
$sxml:var-ref name=blend-color1 [] $sxml:var-ref name=blend-color2 []
$sxml:var-ref name=blend-color3 [] $sxml:var-ref name=blend-color4 []
$sxml:var-ref name=blend-color5 []
]
$set2 [ $sxml:var-ref name=blend-color6 [] ]
]
EOTXT
my XML::XPath $p = get-xpath($text);
my Str $c = $p.find( '/x/set0/text()', :to-list)[0].text;
like $c, /:i '#1200ff' /, 'Found base color';
$c = $p.find( '/x/set1/text()', :to-list)[0].text;
ok $c ~~ / [ '#' <xdigit>**6 \s* ]**5 /, 'Found 5 other colors in set 1';
$c = $p.find( '/x/set2/text()', :to-list)[0].text;
like $c, / \s* /, 'There is no 6th color';
$text = q:to/EOTXT/;
$x [
$!Colors.palette
base-rgb='#1200ff' type=blended mode=hard opacity=0.8
ncolors=10 []
$set0 [ $sxml:var-ref name=base-color [] ]
$set1 [
$sxml:var-ref name=blend-color1 [] $sxml:var-ref name=blend-color2 []
$sxml:var-ref name=blend-color3 [] $sxml:var-ref name=blend-color4 []
$sxml:var-ref name=blend-color5 []
]
$set2 [
$sxml:var-ref name=blend-color6 [] $sxml:var-ref name=blend-color9 []
]
]
EOTXT
$p = get-xpath($text);
$c = $p.find( '/x/set2/text()', :to-list)[0].text;
ok $c ~~ / [ '#' <xdigit>**6 \s* ]**2 /, 'Found 6th and 9th color2 in set 2';
}
#-------------------------------------------------------------------------------
subtest 'generated blended color variables 2', {
my $text = q:to/EOTXT/;
$html [
$!Colors.palette outspec=rgbhex base-rgb='#1200ffff'
type=blended mode=hard []
$head [
$style [
color: $sxml:var-ref name=base-color [];
border-color: $sxml:var-ref name=blend-color2 [];
background-color: $sxml:var-ref name=blend-color5 [];
]
]
$body [
$h1 id=h1001 [ Introduction ]
$p [ $strong [some text]
color is thus $set0 [$sxml:var-ref name=blend-color5 [] ].
]
]
]
EOTXT
my XML::XPath $p = get-xpath($text);
my Str $style-text = $p.find( '//style/text()', :to-list)[0].text;
like $style-text, /:s color ':' '#1200FFFF' ';' /, 'Found base color';
like $style-text, /:s 'border-color:' '#' <xdigit>**8 ';' /,
'Found border color';
like $style-text, /:s 'background-color:' '#' <xdigit>**8 ';' /,
'Found background color';
$style-text = $p.find( '//body/p/set0/text()', :to-list)[0].text;
like $style-text, /:s '#' <xdigit>**8 /,
'Found background color somewhere else';
}
#-------------------------------------------------------------------------------
subtest 'generate monochromatic color variables', {
my $text = q:to/EOTXT/;
$x [
$!Colors.palette base-hsl=<0 100 50> type=color-scheme mode=monochromatic
lighten=20 ncolors=6 outspec=hsl set-name=mono []
$set1 [
$sxml:var-ref name=mono-scheme-color1 []
$sxml:var-ref name=mono-scheme-color2 []
$sxml:var-ref name=mono-scheme-color3 []
$sxml:var-ref name=mono-scheme-color4 []
$sxml:var-ref name=mono-scheme-color5 []
$sxml:var-ref name=mono-scheme-color6 []
]
]
EOTXT
my XML::XPath $p = get-xpath($text);
my Str $style-text = $p.find( '//set1/text()', :to-list)[0].text;
like $style-text, / 'hsla(0.0,100.0%,20.0%)' /, 'Found color 2';
like $style-text, / 'hsla(0.0,100.0%,80.0%)' /, 'Found 5th color';
}
#-------------------------------------------------------------------------------
sub get-xpath ( Str $content --> XML::XPath ) {
my SemiXML::Sxml $x .= new;
$x.parse(
config => {
C => { xml => { :!xml-show }},
F => { xml => {
space-preserve => [<set0 set1 set2>],
no-conversion => [<set0 set1 set2 style>],
},
},
ML => { :Colors<SxmlLib::Colors>, },
T => { :config, :tables, :modules, :parse, },
},
:$content, :!raw, :!trace, :!keep
);
# See the result
my Str $xml-text = ~$x;
#diag $xml-text;
XML::XPath.new(:xml($xml-text))
}
#-------------------------------------------------------------------------------
done-testing;