File: 11-markup.t

package info (click to toggle)
libtext-layout-perl 0.045-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 548 kB
  • sloc: perl: 4,117; makefile: 2
file content (169 lines) | stat: -rw-r--r-- 5,055 bytes parent folder | download | duplicates (2)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! perl

# Basic markup parsing -- regular, bold, italic and overlaps.

use strict;
use Test::More tests => 10;

use Text::Layout::Testing;

my $layout = Text::Layout::Testing->new;

my $xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The quick brown fox',
   },
  ];

$layout->set_markup("The quick brown fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The quick ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => '8.333',
     type => "text", text => 'brown',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' fox',
   },
  ];

$layout->set_markup("The quick <span size='8.333'>brown</span> fox");
is_deeply( $layout->_debug_text, $xp );
$layout->set_markup("The quick <small>brown</small> fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The quick ',
   },
   { font => 'Helvetica(sans,normal,normal,11)', size => 11,
     type => "text", text => 'brown',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' fox',
   },
  ];

# font_desc overrides fam/style/weight.
$layout->set_markup("The quick <span style='italic' font_desc='sans 11'>brown</span> fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The quick ',
   },
   { font => 'Helvetica-BoldOblique(sans,italic,bold,10)', size => 10,
     type => "text", text => 'brown',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' fox',
   },
  ];

$layout->set_markup("The quick <span style='italic' weight='bold' face='sans'>brown</span> fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     underline => 'single',
     type => "text", text => 'quick',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     underline => 'double', underline_color => 'blue',
     type => "text", text => 'brown',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' fox',
   },
  ];

$layout->set_markup("The <u>quick</u> <span underline_color='blue' underline='double'>brown</span> fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     strikethrough => 1,
     type => "text", text => 'quick',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' brown fox',
   },
  ];

$layout->set_markup("The <s>quick</s> brown fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     strikethrough => 1, strikethrough_color => 'yellow',
     type => "text", text => 'quick',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' brown fox',
   },
  ];

$layout->set_markup("The <span strikethrough_color='yellow' strikethrough=1>quick</span> brown fox");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     strikethrough => 1, strikethrough_color => 'yellow',
     type => "text", text => 'quick',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     strikethrough_color => 'yellow',
     type => "text", text => ' brown ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     strikethrough => 1, strikethrough_color => 'yellow',
     type => "text", text => 'fox',
   },
  ];

$layout->set_markup("The <span strikethrough_color='yellow'><s>quick</s> brown <span strikethrough=1>fox</span></span>");
is_deeply( $layout->_debug_text, $xp );

$xp =
  [
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => 'The quick ',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     overline => 'double', overline_color => 'red',
     type => "text", text => 'brown',
   },
   { font => 'Times-Roman(times,normal,normal,10)', size => 10,
     type => "text", text => ' fox',
   },
  ];

$layout->set_markup("The quick <span overline_color='red' overline='double'>brown</span> fox");
is_deeply( $layout->_debug_text, $xp );