Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_tui/tests/draw.rs

12.2 KiB, 39 runs

created by r1870400018:1219, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_tui::lib_tui::text::{
2 typ::TextType,
3 view::TextView,
4};
5
6use oxedyne_fe2o3_core::{
7 prelude::*,
8 test::test_it,
9};
10use oxedyne_fe2o3_geom::{
11 dim::{
12 Dim,
13 Span,
14 },
15 rect::AbsRect,
16};
17use oxedyne_fe2o3_text::{
18 Text,
19 lines::LineRange,
20};
21
22
23pub fn test_text(filter: &'static str) -> Outcome<()> {
24
25 res!(test_it(filter, &["Extract view", "all", "text", "extract"], || {
26 let text: Vec<Text<TextType>> = vec![
27 Text::from("The Epic of Gilgamesh"),
28 Text::from("Tablet 1"),
29 Text::from("He who has seen everything, I will make known (?) to the lands."),
30 Text::from("I will teach (?) about him who experienced all things,"),
31 Text::from("... alike,"),
32 Text::from("Anu granted him the totality of knowledge of all."),
33 Text::from("He saw the Secret, discovered the Hidden,"),
34 Text::from("he brought information of (the time) before the Flood."),
35 Text::from("He went on a distant journey, pushing himself to exhaustion,"),
36 Text::from("but then was brought to peace."),
37 Text::from("He carved on a stone stela all of his toils,"),
38 Text::from("and built the wall of Uruk-Haven,"),
39 Text::from("the wall of the sacred Eanna Temple, the holy sanctuary."),
40 Text::from("Look at its wall which gleams like copper(?),"),
41 Text::from("inspect its inner wall, the likes of which no one can equal!"),
42 Text::from("Take hold of the threshold stone--it dates from ancient times!"),
43 Text::from("Go close to the Eanna Temple, the residence of Ishtar,"),
44 Text::from("such as no later king or man ever equaled!"),
45 Text::from("Go up on the wall of Uruk and walk around,"),
46 Text::from("examine its foundation, inspect its brickwork thoroughly."),
47 Text::from("Is not (even the core of) the brick structure made of kiln-fired brick,"),
48 Text::from("and did not the Seven Sages themselves lay out its plans?"),
49 Text::from("One league city, one league palm gardens, one league lowlands, the open area(?) of the Ishtar Temple,"),
50 Text::from("three leagues and the open area(?) of Uruk it (the wall) encloses."),
51 Text::from("Find the copper tablet box,"),
52 Text::from("open the ... of its lock of bronze,"),
53 Text::from("undo the fastening of its secret opening."),
54 Text::from("Take and read out from the lapis lazuli tablet"),
55 Text::from("how Gilgamesh went through every hardship."),
56 ];
57 let expected = vec![
58 fmt!("who has see"),
59 fmt!("ill teach ("),
60 fmt!(" alike,"),
61 fmt!(" granted hi"),
62 fmt!("saw the Sec"),
63 ];
64 let text_view = AbsRect::from((Dim(3), Dim(2), Dim(11), Dim(5)));
65 debug!("text_view = {:?}", text_view);
66 let lines = TextView::extract_view(
67 &text,
68 &text_view,
69 );
70 for (i, line) in lines.iter().enumerate() {
71 debug!("line {} = '{}'", i, line);
72 }
73 req!(lines.len(), expected.len(), "(L: result len, R: expected len)");
74 for (i, line) in lines.iter().enumerate() {
75 req!(*line, expected[i], "(L: result line, R: expected line)");
76 }
77 Ok(())
78 }));
79
80 // Test the clipping of a rectangle of height 1 by a view.
81 //
82 // Not to scale.
83 // +---------------------------------------+
84 // | (2,1) (12,1) |
85 // | +------------------+ |
86 // | | 5 | |
87 // | | +=======+ | |
88 // | | (3,4) | |
89 // | | | 7 |
90 // | | 10 | |
91 // | +------------------+ |
92 // | view |
93 // | |
94 // | |
95 // | |
96 // +---------------------------------------+
97 //
98 res!(test_it(filter, &["Relative text range 000", "all", "text", "range"], || {
99 let range = LineRange {
100 line: Dim(4),
101 span: Span::new((Dim(3), Dim(5))),
102 };
103 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
104 let result = view.clip(range.to_abs_rect());
105 let expected = AbsRect::from((Dim(3), Dim(4), Dim(5), Dim(1)));
106 req!(Some(expected), result, "L: expected, R: result");
107 Ok(())
108 }));
109
110 // Not to scale.
111 // +---------------------------------------+
112 // | (2,1) (12,1) |
113 // | +------------------+ |
114 // | | 4 | |
115 // | | +======|x |
116 // | | (8,4) | |
117 // | | | 7 |
118 // | | 10 | |
119 // | +------------------+ |
120 // | view |
121 // | |
122 // | |
123 // | |
124 // +---------------------------------------+
125 //
126 res!(test_it(filter, &["Relative text range 010", "all", "text", "range"], || {
127 let range = LineRange {
128 line: Dim(4),
129 span: Span::new((Dim(8), Dim(5))),
130 };
131 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
132 let result = view.clip(range.to_abs_rect());
133 let expected = AbsRect::from((Dim(8), Dim(4), Dim(4), Dim(1)));
134 req!(Some(expected), result, "L: expected, R: result");
135 Ok(())
136 }));
137
138 // Not to scale.
139 // +---------------------------------------+
140 // | (2,1) (12,1) |
141 // | +------------------+ |
142 // | | 1 | |
143 // | | +|xxxxxxx |
144 // | | (11,4)| |
145 // | | | 7 |
146 // | | 10 | |
147 // | +------------------+ |
148 // | view |
149 // | |
150 // | |
151 // | |
152 // +---------------------------------------+
153 //
154 res!(test_it(filter, &["Relative text range 020", "all", "text", "range"], || {
155 let range = LineRange {
156 line: Dim(4),
157 span: Span::new((Dim(11), Dim(5))),
158 };
159 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
160 let result = view.clip(range.to_abs_rect());
161 let expected = AbsRect::from((Dim(11), Dim(4), Dim(1), Dim(1)));
162 req!(Some(expected), result, "L: expected, R: result");
163 Ok(())
164 }));
165
166 // Not to scale.
167 // +---------------------------------------+
168 // | (2,1) (12,1) |
169 // | +------------------+ |
170 // | | 0 | |
171 // | | +xxxxxxxx |
172 // | | (12,4)| |
173 // | | | 7 |
174 // | | 10 | |
175 // | +------------------+ |
176 // | view |
177 // | |
178 // | |
179 // | |
180 // +---------------------------------------+
181 //
182 res!(test_it(filter, &["Relative text range 030", "all", "text", "range"], || {
183 let range = LineRange {
184 line: Dim(4),
185 span: Span::new((Dim(12), Dim(5))),
186 };
187 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
188 let result = view.clip(range.to_abs_rect());
189 // A range that starts at the far edge of the view has nothing inside it. An earlier
190 // fe2o3_geom answered with a rectangle of zero width; `Span::clip` now answers `None`,
191 // which is what the caller in `draw/tbox.rs` matches on when it decides whether there is
192 // anything to paint.
193 let expected: Option<AbsRect> = None;
194 req!(expected, result, "L: expected, R: result");
195 Ok(())
196 }));
197
198 // Not to scale.
199 // +---------------------------------------+
200 // | (2,1) (12,1) |
201 // | +------------------+ |
202 // | | 0 | |
203 // | | |xxxxxxxxx |
204 // | | (12,4)| |
205 // | | | 7 |
206 // | | 10 | |
207 // | +------------------+ |
208 // | view |
209 // | |
210 // | |
211 // | |
212 // +---------------------------------------+
213 //
214 res!(test_it(filter, &["Relative text range 040", "all", "text", "range"], || {
215 let range = LineRange {
216 line: Dim(4),
217 span: Span::new((Dim(13), Dim(5))),
218 };
219 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
220 let result = view.clip(range.to_abs_rect());
221 // A range that starts at the far edge of the view has nothing inside it. An earlier
222 // fe2o3_geom answered with a rectangle of zero width; `Span::clip` now answers `None`,
223 // which is what the caller in `draw/tbox.rs` matches on when it decides whether there is
224 // anything to paint.
225 let expected: Option<AbsRect> = None;
226 req!(expected, result, "L: expected, R: result");
227 Ok(())
228 }));
229
230 // Not to scale.
231 // +---------------------------------------+
232 // | (2,1) (12,1) |
233 // | +------------------+ |
234 // | | 5 | |
235 // | +=======+ | |
236 // | |(2,4) | |
237 // | | | 7 |
238 // | | 10 | |
239 // | +------------------+ |
240 // | view |
241 // | |
242 // | |
243 // | |
244 // +---------------------------------------+
245 //
246 res!(test_it(filter, &["Relative text range 050", "all", "text", "range"], || {
247 let range = LineRange {
248 line: Dim(4),
249 span: Span::new((Dim(2), Dim(5))),
250 };
251 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
252 let result = view.clip(range.to_abs_rect());
253 let expected = AbsRect::from((Dim(2), Dim(4), Dim(5), Dim(1)));
254 req!(Some(expected), result, "L: expected, R: result");
255 Ok(())
256 }));
257
258 // Not to scale.
259 // +---------------------------------------+
260 // | (2,1) (12,1) |
261 // | +------------------+ |
262 // | | 4 | |
263 // | xx+=====+ | |
264 // | |(2,4) | |
265 // | | | 7 |
266 // | | 10 | |
267 // | +------------------+ |
268 // | view |
269 // | |
270 // | |
271 // | |
272 // +---------------------------------------+
273 //
274 res!(test_it(filter, &["Relative text range 060", "all", "text", "range"], || {
275 let range = LineRange {
276 line: Dim(4),
277 span: Span::new((Dim(1), Dim(5))),
278 };
279 let view = AbsRect::from((Dim(2), Dim(1), Dim(10), Dim(7)));
280 let result = view.clip(range.to_abs_rect());
281 let expected = AbsRect::from((Dim(2), Dim(4), Dim(4), Dim(1)));
282 req!(Some(expected), result, "L: expected, R: result");
283 Ok(())
284 }));
285
286 Ok(())
287}