1use crate::{Class, Font};
28
29const LARGE_OPS: &str = "\u{2211}\u{220F}\u{2210}\u{22C0}\u{22C1}\u{22C2}\u{22C3}\u{2A00}\u{2A01}\u{2A02}\u{2A03}\u{2A04}\u{2A05}\u{2A06}\u{222B}\u{222C}\u{222D}\u{222E}\u{222F}\u{2230}";
31
32const BINARY: &str = "+-*\u{2212}\u{00B1}\u{2213}\u{00D7}\u{00F7}\u{22C5}\u{2217}\u{00B7}\u{2218}\u{2216}\u{2227}\u{2228}\u{2229}\u{222A}\u{2295}\u{2296}\u{2297}\u{2299}\u{2216}";
33
34const RELATIONS: &str = "=<>:\u{2264}\u{2265}\u{2260}\u{2248}\u{2261}\u{2208}\u{2209}\u{2282}\u{2283}\u{2286}\u{2287}\
35\u{2192}\u{2190}\u{2194}\u{21D2}\u{21D4}\u{21A6}\u{2191}\u{2193}\u{27F9}\u{27FA}\u{223C}\u{221D}\u{2245}\u{225C}\
36\u{2323}\u{2254}\u{2255}\u{220B}\u{2225}\u{2223}\u{2224}\u{22A5}\u{224D}\u{226A}\u{226B}\
37\u{227D}";
38
39const OPENERS: &str = "([{\u{27E8}\u{230A}\u{2308}\u{27E6}\u{301A}";
40const CLOSERS: &str = ")]}\u{27E9}\u{230B}\u{2309}\u{27E7}\u{301B}";
41const PUNCTUATION: &str = ",;";
42
43const MARKUP_ORDINARY: &str = "\u{2A00}\u{2A03}\u{2A04}\u{2A05}\u{2A06}\u{2229}\u{222A}\u{2191}\u{2193}\u{2194}\u{21A6}\u{27F9}\u{27FA}\u{220B}\u{2225}\u{2223}\u{2224}\u{22A5}\u{224D}\u{226A}\u{226B}";
46
47const MARKUP_BINARY: &str = "/";
50
51const MARKUP_PUNCTUATION: &str = ":";
54
55#[derive(Clone, Copy, Debug, PartialEq, Eq)]
57pub enum Convention {
58 MathType,
60 Markup,
62}
63
64fn is_large_op(ch: char) -> bool {
66 LARGE_OPS.contains(ch)
67}
68
69fn mathtype_class(ch: char) -> Class {
71 if is_large_op(ch) {
72 Class::Op
73 } else if OPENERS.contains(ch) {
74 Class::Open
75 } else if CLOSERS.contains(ch) {
76 Class::Close
77 } else if PUNCTUATION.contains(ch) {
78 Class::Punct
79 } else if BINARY.contains(ch) {
80 Class::Bin
81 } else if RELATIONS.contains(ch) {
82 Class::Rel
83 } else {
84 Class::Ord
85 }
86}
87
88pub fn class_of_char(ch: char) -> Class {
93 class_of_char_with(ch, Convention::MathType)
94}
95
96pub fn class_of_char_with(ch: char, convention: Convention) -> Class {
98 match convention {
99 Convention::MathType => mathtype_class(ch),
100 Convention::Markup => {
101 if MARKUP_ORDINARY.contains(ch) {
102 Class::Ord
103 } else if MARKUP_BINARY.contains(ch) {
104 Class::Bin
105 } else if MARKUP_PUNCTUATION.contains(ch) {
106 Class::Punct
107 } else {
108 mathtype_class(ch)
109 }
110 }
111 }
112}
113
114pub fn is_large_op_with(ch: char, convention: Convention) -> bool {
116 match convention {
117 Convention::MathType => is_large_op(ch),
118 Convention::Markup => is_large_op(ch) && !MARKUP_ORDINARY.contains(ch),
119 }
120}
121
122pub fn is_symbol_face(ch: char) -> bool {
131 if ch.is_ascii() {
132 return false;
133 }
134 is_large_op(ch)
135 || matches!(class_of_char(ch), Class::Bin | Class::Rel)
136 || matches!(
137 ch,
138 '\u{2200}'
139 | '\u{2203}'
140 | '\u{2205}'
141 | '\u{221E}'
142 | '\u{2202}'
143 | '\u{2207}'
144 | '\u{210F}'
145 | '\u{2113}'
146 | '\u{2135}'
147 | '\u{2118}'
148 | '\u{2220}'
149 | '\u{22EF}'
150 )
151}
152
153pub fn symbol_position(ch: char) -> Option<(Font, u8)> {
166 symbol_code(ch)
167 .map(|code| (Font::Symbol, code))
168 .or_else(|| extra_code(ch).map(|code| (Font::Extra, code)))
169}
170
171pub fn euclid_math_two_position(ch: char) -> Option<u8> {
178 match ch {
179 '\u{227D}' => Some(0xB1),
180 _ => None,
181 }
182}
183
184pub fn symbol_code(ch: char) -> Option<u8> {
200 if ch.is_ascii() {
201 return Some(ch as u8);
202 }
203 let index = SYMBOL_CODES
204 .binary_search_by_key(&ch, |(character, _)| *character)
205 .ok()?;
206 Some(SYMBOL_CODES[index].1)
207}
208
209pub fn extra_code(ch: char) -> Option<u8> {
219 let index = EXTRA_CODES
220 .binary_search_by_key(&ch, |(character, _)| *character)
221 .ok()?;
222 Some(EXTRA_CODES[index].1)
223}
224
225pub fn extra_positions() -> &'static [(char, u8)] {
229 EXTRA_CODES
230}
231
232const SYMBOL_CODES: &[(char, u8)] = &[
237 ('\u{00AC}', 0xD8),
238 ('\u{00B0}', 0xB0),
239 ('\u{00B1}', 0xB1),
240 ('\u{00B5}', 0x6D),
241 ('\u{00D7}', 0xB4),
242 ('\u{00F7}', 0xB8),
243 ('\u{0192}', 0xA6),
244 ('\u{0391}', 0x41),
245 ('\u{0392}', 0x42),
246 ('\u{0393}', 0x47),
247 ('\u{0394}', 0x44),
248 ('\u{0395}', 0x45),
249 ('\u{0396}', 0x5A),
250 ('\u{0397}', 0x48),
251 ('\u{0398}', 0x51),
252 ('\u{0399}', 0x49),
253 ('\u{039A}', 0x4B),
254 ('\u{039B}', 0x4C),
255 ('\u{039C}', 0x4D),
256 ('\u{039D}', 0x4E),
257 ('\u{039E}', 0x58),
258 ('\u{039F}', 0x4F),
259 ('\u{03A0}', 0x50),
260 ('\u{03A1}', 0x52),
261 ('\u{03A3}', 0x53),
262 ('\u{03A4}', 0x54),
263 ('\u{03A5}', 0x55),
264 ('\u{03A6}', 0x46),
265 ('\u{03A7}', 0x43),
266 ('\u{03A8}', 0x59),
267 ('\u{03A9}', 0x57),
268 ('\u{03B1}', 0x61),
269 ('\u{03B2}', 0x62),
270 ('\u{03B3}', 0x67),
271 ('\u{03B4}', 0x64),
272 ('\u{03B5}', 0x65),
273 ('\u{03B6}', 0x7A),
274 ('\u{03B7}', 0x68),
275 ('\u{03B8}', 0x71),
276 ('\u{03B9}', 0x69),
277 ('\u{03BA}', 0x6B),
278 ('\u{03BB}', 0x6C),
279 ('\u{03BC}', 0x6D),
280 ('\u{03BD}', 0x6E),
281 ('\u{03BE}', 0x78),
282 ('\u{03BF}', 0x6F),
283 ('\u{03C0}', 0x70),
284 ('\u{03C1}', 0x72),
285 ('\u{03C2}', 0x56),
286 ('\u{03C3}', 0x73),
287 ('\u{03C4}', 0x74),
288 ('\u{03C5}', 0x75),
289 ('\u{03C6}', 0x6A),
290 ('\u{03C7}', 0x63),
291 ('\u{03C8}', 0x79),
292 ('\u{03C9}', 0x77),
293 ('\u{03D1}', 0x4A),
294 ('\u{03D2}', 0xA1),
295 ('\u{03D5}', 0x66),
296 ('\u{03D6}', 0x76),
297 ('\u{2022}', 0xB7),
298 ('\u{2026}', 0xBC),
299 ('\u{2032}', 0xA2),
300 ('\u{2033}', 0xB2),
301 ('\u{2044}', 0xA4),
302 ('\u{20AC}', 0xA0),
303 ('\u{2111}', 0xC1),
304 ('\u{2118}', 0xC3),
305 ('\u{211C}', 0xC2),
306 ('\u{2126}', 0x57),
307 ('\u{2135}', 0xC0),
308 ('\u{2190}', 0xAC),
309 ('\u{2191}', 0xAD),
310 ('\u{2192}', 0xAE),
311 ('\u{2193}', 0xAF),
312 ('\u{2194}', 0xAB),
313 ('\u{21B5}', 0xBF),
314 ('\u{21D0}', 0xDC),
315 ('\u{21D1}', 0xDD),
316 ('\u{21D2}', 0xDE),
317 ('\u{21D3}', 0xDF),
318 ('\u{21D4}', 0xDB),
319 ('\u{2200}', 0x22),
320 ('\u{2202}', 0xB6),
321 ('\u{2203}', 0x24),
322 ('\u{2205}', 0xC6),
323 ('\u{2206}', 0x44),
324 ('\u{2207}', 0xD1),
325 ('\u{2208}', 0xCE),
326 ('\u{2209}', 0xCF),
327 ('\u{220B}', 0x27),
328 ('\u{220F}', 0xD5),
329 ('\u{2211}', 0xE5),
330 ('\u{2212}', 0x2D),
331 ('\u{2217}', 0x2A),
332 ('\u{221A}', 0xD6),
333 ('\u{221D}', 0xB5),
334 ('\u{221E}', 0xA5),
335 ('\u{2220}', 0xD0),
336 ('\u{2223}', 0x7C),
337 ('\u{2227}', 0xD9),
338 ('\u{2228}', 0xDA),
339 ('\u{2229}', 0xC7),
340 ('\u{222A}', 0xC8),
341 ('\u{222B}', 0xF2),
342 ('\u{2234}', 0x5C),
343 ('\u{223C}', 0x7E),
344 ('\u{2245}', 0x40),
345 ('\u{2248}', 0xBB),
346 ('\u{2260}', 0xB9),
347 ('\u{2261}', 0xBA),
348 ('\u{2264}', 0xA3),
349 ('\u{2265}', 0xB3),
350 ('\u{2282}', 0xCC),
351 ('\u{2283}', 0xC9),
352 ('\u{2284}', 0xCB),
353 ('\u{2286}', 0xCD),
354 ('\u{2287}', 0xCA),
355 ('\u{2295}', 0xC5),
356 ('\u{2297}', 0xC4),
357 ('\u{22A5}', 0x5E),
358 ('\u{22C5}', 0xD7),
359 ('\u{2320}', 0xF3),
360 ('\u{2321}', 0xF5),
361 ('\u{2329}', 0xE1),
362 ('\u{232A}', 0xF1),
363 ('\u{25CA}', 0xE0),
364 ('\u{2660}', 0xAA),
365 ('\u{2663}', 0xA7),
366 ('\u{2665}', 0xA9),
367 ('\u{2666}', 0xA8),
368];
369
370const EXTRA_CODES: &[(char, u8)] = &[
375 ('\u{019B}', 0x44),
376 ('\u{0300}', 0x23),
377 ('\u{0302}', 0x24),
378 ('\u{0303}', 0x25),
379 ('\u{0307}', 0x26),
380 ('\u{2026}', 0x4B),
381 ('\u{2035}', 0x60),
382 ('\u{20D0}', 0x77),
383 ('\u{20D1}', 0x76),
384 ('\u{20D6}', 0x73),
385 ('\u{20D7}', 0x72),
386 ('\u{20E1}', 0x74),
387 ('\u{2102}', 0xA3),
388 ('\u{210F}', 0x68),
389 ('\u{2113}', 0x6C),
390 ('\u{2115}', 0xA5),
391 ('\u{211A}', 0xA4),
392 ('\u{211D}', 0xA1),
393 ('\u{2124}', 0xA2),
394 ('\u{2195}', 0x62),
395 ('\u{21A6}', 0x61),
396 ('\u{21D5}', 0x63),
397 ('\u{2210}', 0x43),
398 ('\u{2213}', 0x6D),
399 ('\u{2218}', 0x6F),
400 ('\u{2229}', 0x49),
401 ('\u{222A}', 0x55),
402 ('\u{2235}', 0x51),
403 ('\u{225C}', 0x40),
404 ('\u{227A}', 0x70),
405 ('\u{227B}', 0x66),
406 ('\u{22C2}', 0x49),
407 ('\u{22C3}', 0x55),
408 ('\u{22EE}', 0x4D),
409 ('\u{22EF}', 0x4C),
410 ('\u{22F0}', 0x4E),
411 ('\u{22F1}', 0x4F),
412 ('\u{25B9}', 0x3E),
413 ('\u{25C3}', 0x3C),
414 ('\u{FE36}', 0x7B),
415 ('\u{FE38}', 0x7D),
416];
417
418pub fn is_cjk(ch: char) -> bool {
424 matches!(
425 ch as u32,
426 0x1100..=0x11FF | 0x2E80..=0x2FDF | 0x2FF0..=0x2FFF | 0x3000..=0x30FF | 0x3100..=0x312F | 0x3130..=0x318F | 0x3190..=0x319F | 0x31A0..=0x31BF | 0x31C0..=0x31EF | 0x31F0..=0x31FF | 0x3200..=0x33FF | 0x3400..=0x4DBF | 0x4E00..=0x9FFF | 0xA960..=0xA97F | 0xAC00..=0xD7AF | 0xD7B0..=0xD7FF | 0xF900..=0xFAFF | 0xFE10..=0xFE1F | 0xFE30..=0xFE4F | 0xFE50..=0xFE6F | 0xFF00..=0xFFEF | 0x1B000..=0x1B16F | 0x1F200..=0x1F2FF | 0x20000..=0x3FFFF )
451}
452
453const EXTRA_LETTERS: [(char, char, Font); 23] = [
463 ('\u{2102}', 'C', Font::DoubleStruck),
464 ('\u{210A}', 'g', Font::Script),
465 ('\u{210B}', 'H', Font::Script),
466 ('\u{210C}', 'H', Font::Fraktur),
467 ('\u{210D}', 'H', Font::DoubleStruck),
468 ('\u{2110}', 'I', Font::Script),
469 ('\u{2111}', 'I', Font::Fraktur),
470 ('\u{2112}', 'L', Font::Script),
471 ('\u{2115}', 'N', Font::DoubleStruck),
472 ('\u{2119}', 'P', Font::DoubleStruck),
473 ('\u{211A}', 'Q', Font::DoubleStruck),
474 ('\u{211B}', 'R', Font::Script),
475 ('\u{211C}', 'R', Font::Fraktur),
476 ('\u{211D}', 'R', Font::DoubleStruck),
477 ('\u{2124}', 'Z', Font::DoubleStruck),
478 ('\u{2128}', 'Z', Font::Fraktur),
479 ('\u{212C}', 'B', Font::Script),
480 ('\u{212D}', 'C', Font::Fraktur),
481 ('\u{212F}', 'e', Font::Script),
482 ('\u{2130}', 'E', Font::Script),
483 ('\u{2131}', 'F', Font::Script),
484 ('\u{2133}', 'M', Font::Script),
485 ('\u{2134}', 'o', Font::Script),
486];
487
488pub fn extra_letter(ch: char) -> Option<(char, Font)> {
490 let index = EXTRA_LETTERS
491 .binary_search_by_key(&ch, |(symbol, _, _)| *symbol)
492 .ok()?;
493 let (_, letter, font) = EXTRA_LETTERS[index];
494 Some((letter, font))
495}
496
497pub fn extra_symbol(letter: char, font: Font) -> Option<char> {
499 EXTRA_LETTERS
500 .iter()
501 .find(|(_, saved, face)| *saved == letter && *face == font)
502 .map(|(symbol, _, _)| *symbol)
503}
504
505pub fn is_extra_face(ch: char) -> bool {
507 extra_letter(ch).is_some()
508}
509
510#[cfg(test)]
511mod tests {
512 use super::{
513 Convention, class_of_char, class_of_char_with, extra_code, is_cjk, is_large_op_with,
514 is_symbol_face, symbol_code, symbol_position,
515 };
516 use crate::{Class, Font};
517
518 #[test]
519 fn cjk_letters_and_punctuation_take_the_cjk_face() {
520 for ch in [
521 '\u{4E3A}',
522 '\u{4E2D}',
523 '\u{3001}',
524 '\u{3002}',
525 '\u{300C}',
526 '\u{3042}',
527 '\u{30A2}',
528 '\u{2FF0}',
529 '\u{31B0}',
530 '\u{31F0}',
531 '\u{FF08}',
532 '\u{FF11}',
533 '\u{FA0E}',
534 '\u{1B000}',
535 '\u{1F200}',
536 '\u{20000}',
537 '\u{1100}',
538 '\u{3131}',
539 '\u{AC00}',
540 '\u{3190}',
541 '\u{FE10}',
542 '\u{FE50}',
543 ] {
544 assert!(is_cjk(ch), "{ch:?} is drawn from the CJK face");
545 }
546 }
547
548 #[test]
549 fn latin_letters_greek_and_math_symbols_stay_out_of_the_cjk_face() {
550 for ch in [
551 'A', 'x', '0', '\u{03B1}', '\u{2211}', '\u{2192}', '\u{00E9}',
552 ] {
553 assert!(!is_cjk(ch), "{ch:?} is not drawn from the CJK face");
554 }
555 }
556
557 #[test]
558 fn operators_relations_and_large_operators_take_the_symbol_face() {
559 for ch in [
560 '\u{2212}', '\u{2211}', '\u{2208}', '\u{2264}', '\u{00B1}', '\u{00D7}', '\u{222B}',
561 '\u{220F}',
562 ] {
563 assert!(is_symbol_face(ch), "{ch:?} is drawn from the Symbol face");
564 }
565 }
566
567 #[test]
568 fn ordinary_symbols_the_text_face_lacks_take_the_symbol_face() {
569 for ch in [
570 '\u{2205}', '\u{221E}', '\u{2202}', '\u{2207}', '\u{2200}', '\u{2203}',
571 ] {
572 assert!(is_symbol_face(ch), "{ch:?} is drawn from the Symbol face");
573 }
574 }
575
576 #[test]
577 fn ascii_and_variable_letters_stay_in_the_text_face() {
578 for ch in [
579 '-', '+', '=', 'x', 'A', '0', '\u{03B1}', '\u{03C6}', '\u{221A}',
580 ] {
581 assert!(!is_symbol_face(ch), "{ch:?} is drawn from the text face");
582 }
583 }
584
585 #[test]
586 fn the_symbol_table_names_the_legacy_positions() {
587 assert_eq!(symbol_code('A'), Some(0x41));
588 assert_eq!(symbol_code('\u{03B1}'), Some(0x61));
589 assert_eq!(symbol_code('\u{0394}'), Some(0x44));
590 assert_eq!(symbol_code('\u{03BC}'), Some(0x6D));
591 assert_eq!(symbol_code('\u{03A9}'), Some(0x57));
592 assert_eq!(symbol_code('\u{03C2}'), Some(0x56));
593 assert_eq!(
594 symbol_code('\u{03C6}'),
595 Some(0x6A),
596 "the loopy phi takes the position the Symbol font draws it at"
597 );
598 assert_eq!(
599 symbol_code('\u{03D5}'),
600 Some(0x66),
601 "the straight phi takes the position the Symbol font draws it at"
602 );
603 assert_eq!(symbol_code('\u{2211}'), Some(0xE5));
604 assert_eq!(symbol_code('\u{222B}'), Some(0xF2));
605 assert_eq!(symbol_code('\u{2264}'), Some(0xA3));
606 assert_eq!(symbol_code('\u{1D465}'), None);
607 }
608
609 #[test]
610 fn a_bare_character_classifies_by_the_latex_conventions() {
611 assert_eq!(class_of_char('\u{2211}'), Class::Op);
612 assert_eq!(class_of_char('\u{2212}'), Class::Bin);
613 assert_eq!(class_of_char('\u{2208}'), Class::Rel);
614 assert_eq!(class_of_char('('), Class::Open);
615 assert_eq!(class_of_char(']'), Class::Close);
616 assert_eq!(class_of_char(','), Class::Punct);
617 assert_eq!(class_of_char('x'), Class::Ord);
618 assert_eq!(class_of_char('0'), Class::Ord);
619 }
620
621 #[test]
622 fn the_succeeds_or_equal_relation_is_a_relation() {
623 assert_eq!(class_of_char('\u{227D}'), Class::Rel);
624 assert!(
625 is_symbol_face('\u{227D}'),
626 "MathType draws the relation from a face other than the text face"
627 );
628 }
629
630 #[test]
631 fn the_euclid_math_two_encoding_names_the_succeeds_or_equal_position() {
632 use super::euclid_math_two_position;
633 assert_eq!(euclid_math_two_position('\u{227D}'), Some(0xB1));
634 assert_eq!(euclid_math_two_position('\u{227C}'), None);
635 assert_eq!(euclid_math_two_position('Q'), None);
636 }
637
638 #[test]
639 fn the_markup_convention_takes_the_slash_as_binary_and_the_colon_as_punctuation() {
640 assert_eq!(class_of_char_with('/', Convention::MathType), Class::Ord);
641 assert_eq!(class_of_char_with('/', Convention::Markup), Class::Bin);
642 assert_eq!(class_of_char_with(':', Convention::MathType), Class::Rel);
643 assert_eq!(class_of_char_with(':', Convention::Markup), Class::Punct);
644 }
645
646 #[test]
647 fn the_markup_convention_leaves_the_arrows_and_the_extra_relations_ordinary() {
648 for ch in [
649 '\u{2191}', '\u{2193}', '\u{2194}', '\u{21A6}', '\u{27F9}', '\u{27FA}', '\u{220B}',
650 '\u{2225}', '\u{2223}', '\u{2224}', '\u{22A5}', '\u{224D}', '\u{226A}', '\u{226B}',
651 ] {
652 assert_eq!(class_of_char_with(ch, Convention::MathType), Class::Rel);
653 assert_eq!(
654 class_of_char_with(ch, Convention::Markup),
655 Class::Ord,
656 "{ch:?} is ordinary in the markup convention"
657 );
658 }
659 }
660
661 #[test]
662 fn the_markup_convention_leaves_the_union_intersection_and_the_circled_operators_ordinary() {
663 for ch in ['\u{2229}', '\u{222A}'] {
664 assert_eq!(class_of_char_with(ch, Convention::MathType), Class::Bin);
665 assert_eq!(class_of_char_with(ch, Convention::Markup), Class::Ord);
666 }
667 for ch in ['\u{2A00}', '\u{2A03}', '\u{2A04}', '\u{2A05}', '\u{2A06}'] {
668 assert!(is_large_op_with(ch, Convention::MathType), "{ch:?}");
669 assert!(!is_large_op_with(ch, Convention::Markup), "{ch:?}");
670 assert_eq!(class_of_char_with(ch, Convention::Markup), Class::Ord);
671 }
672 }
673
674 #[test]
675 fn both_conventions_agree_on_the_shared_operators_and_the_delimiters() {
676 for ch in [
677 '\u{2211}', '\u{220F}', '\u{2210}', '\u{222B}', '\u{2230}', '\u{22C0}', '\u{22C1}',
678 '\u{22C2}', '\u{22C3}', '\u{2A01}', '\u{2A02}',
679 ] {
680 assert!(is_large_op_with(ch, Convention::MathType), "{ch:?}");
681 assert!(is_large_op_with(ch, Convention::Markup), "{ch:?}");
682 }
683 for (ch, class) in [
684 ('(', Class::Open),
685 (')', Class::Close),
686 ('[', Class::Open),
687 (']', Class::Close),
688 ('{', Class::Open),
689 ('}', Class::Close),
690 ('\u{27E8}', Class::Open),
691 ('\u{27E9}', Class::Close),
692 ('+', Class::Bin),
693 ('=', Class::Rel),
694 (',', Class::Punct),
695 (';', Class::Punct),
696 ('x', Class::Ord),
697 ('0', Class::Ord),
698 ] {
699 assert_eq!(class_of_char_with(ch, Convention::MathType), class);
700 assert_eq!(class_of_char_with(ch, Convention::Markup), class);
701 }
702 }
703
704 #[test]
705 fn the_letterlike_table_is_sorted_for_the_binary_search() {
706 assert!(
707 super::EXTRA_LETTERS
708 .windows(2)
709 .all(|pair| pair[0].0 < pair[1].0),
710 "the table is searched by character, so it must stay sorted"
711 );
712 }
713
714 #[test]
715 fn letterlike_symbols_name_the_letter_and_face_math_type_saved_them_for() {
716 use super::extra_letter;
717 assert_eq!(
718 extra_letter('\u{211D}'),
719 Some(('R', crate::Font::DoubleStruck))
720 );
721 assert_eq!(extra_letter('\u{212C}'), Some(('B', crate::Font::Script)));
722 assert_eq!(extra_letter('\u{212D}'), Some(('C', crate::Font::Fraktur)));
723 assert_eq!(extra_letter('R'), None);
724 assert_eq!(
725 extra_letter('\u{1D54D}'),
726 None,
727 "the block has no BMP character"
728 );
729 }
730
731 #[test]
732 fn the_extra_face_covers_the_letterlike_symbols_in_the_bmp() {
733 use super::is_extra_face;
734 for ch in ['\u{211D}', '\u{212C}', '\u{212D}', '\u{2102}', '\u{2134}'] {
735 assert!(is_extra_face(ch), "{ch:?} is saved in the extra face");
736 }
737 for ch in ['R', '\u{1D54D}', '\u{2113}', '\u{210F}'] {
738 assert!(!is_extra_face(ch), "{ch:?} is not saved in the extra face");
739 }
740 }
741
742 #[test]
743 fn the_symbol_encoding_names_the_legacy_positions() {
744 assert_eq!(symbol_code('\u{03B1}'), Some(0x61));
745 assert_eq!(symbol_code('\u{0394}'), Some(0x44));
746 assert_eq!(symbol_code('\u{03BC}'), Some(0x6D));
747 assert_eq!(symbol_code('\u{03A9}'), Some(0x57));
748 assert_eq!(symbol_code('\u{03C2}'), Some(0x56));
749 assert_eq!(symbol_code('\u{2211}'), Some(0xE5));
750 assert_eq!(symbol_code('\u{222B}'), Some(0xF2));
751 assert_eq!(symbol_code('\u{2264}'), Some(0xA3));
752 assert_eq!(
753 symbol_code('\u{2223}'),
754 Some(0x7C),
755 "the relation takes the bar glyph's position"
756 );
757 assert_eq!(symbol_code('A'), Some(0x41), "ASCII sits at its own code");
758 assert_eq!(symbol_code('\u{1D465}'), None);
759 }
760
761 #[test]
762 fn the_extra_encoding_names_the_math_type_positions() {
763 assert_eq!(extra_code('\u{019B}'), Some(0x44));
764 assert_eq!(extra_code('\u{2113}'), Some(0x6C));
765 assert_eq!(extra_code('\u{210F}'), Some(0x68));
766 assert_eq!(extra_code('\u{2213}'), Some(0x6D));
767 assert_eq!(extra_code('\u{20D7}'), Some(0x72));
768 assert_eq!(extra_code('\u{211D}'), Some(0xA1));
769 assert_eq!(extra_code('\u{2115}'), Some(0xA5));
770 assert_eq!(extra_code('\u{22C3}'), Some(0x55));
771 assert_eq!(extra_code('\u{22C2}'), Some(0x49));
772 assert_eq!(extra_code('\u{225C}'), Some(0x40));
773 assert_eq!(extra_code('\u{22EF}'), Some(0x4C));
774 assert_eq!(extra_code('\u{212C}'), None, "the face has no script B");
775 assert_eq!(extra_code('\u{1D465}'), None);
776 }
777
778 #[test]
779 fn a_symbol_takes_the_symbol_face_unless_only_the_extra_encoding_places_it() {
780 assert_eq!(symbol_position('\u{2211}'), Some((Font::Symbol, 0xE5)));
781 assert_eq!(symbol_position('\u{2229}'), Some((Font::Symbol, 0xC7)));
782 assert_eq!(symbol_position('\u{2113}'), Some((Font::Extra, 0x6C)));
783 assert_eq!(symbol_position('\u{210F}'), Some((Font::Extra, 0x68)));
784 assert_eq!(symbol_position('\u{2213}'), Some((Font::Extra, 0x6D)));
785 assert_eq!(symbol_position('\u{22C3}'), Some((Font::Extra, 0x55)));
786 assert_eq!(symbol_position('\u{22C2}'), Some((Font::Extra, 0x49)));
787 assert_eq!(symbol_position('\u{225C}'), Some((Font::Extra, 0x40)));
788 assert_eq!(symbol_position('\u{22EF}'), Some((Font::Extra, 0x4C)));
789 assert_eq!(
790 symbol_position('\u{222A}'),
791 Some((Font::Symbol, 0xC8)),
792 "a character the Symbol encoding places stays in that face"
793 );
794 assert_eq!(
795 symbol_position('\u{2223}'),
796 Some((Font::Symbol, 0x7C)),
797 "the relation takes the Symbol face's bar"
798 );
799 assert_eq!(symbol_position('\u{2225}'), None);
800 }
801}