Debian Codegraph @

tests/all/utf_8_characters.rs

raw symbols SCIP
1 use comfy_tablerust-analyzer cargo comfy-table 7.2.2 crate/::*;
2 use pretty_assertionsrust-analyzer cargo pretty_assertions 1.4.1 crate/::assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!;
3
4 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
5 /// UTF-8 symbols that are longer than a single character are properly handled.
6 /// This means, that comfy-table detects that they're longer than 1 character and styles/arranges
7 /// the table accordingly.
8 fn multi_character_utf8_symbolsrust-analyzer cargo comfy-table 7.2.2 all/utf_8_characters/multi_character_utf8_symbols().() {
9 let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().();
10 table
11 .set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["Header1", "Header2", "Header3"])
12 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
13 "This is a text",
14 "This is another text",
15 "This is the third text",
16 ])
17 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![
18 "This is another text",
19 "Now\nadd some\nmulti line stuff",
20 "✅",
21 ]);
22
23 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}");
24 let expected = "
25 +----------------------+----------------------+------------------------+
26 | Header1 | Header2 | Header3 |
27 +======================================================================+
28 | This is a text | This is another text | This is the third text |
29 |----------------------+----------------------+------------------------|
30 | This is another text | Now | ✅ |
31 | | add some | |
32 | | multi line stuff | |
33 +----------------------+----------------------+------------------------+";
34 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(expected, "\n".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). &table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
35 }
36
37 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
38 fn multi_character_utf8_word_splittingrust-analyzer cargo comfy-table 7.2.2 all/utf_8_characters/multi_character_utf8_word_splitting().() {
39 let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().();
40 table
41 .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(8)
42 .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#)
43 .set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"])
44 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["abc✅def"]);
45
46 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}");
47 let expected = "
48 +------+
49 | test |
50 +======+
51 | abc |
52 | ✅de |
53 | f |
54 +------+";
55 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}");
56 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(expected, "\n".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). &table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
57 }
58
59 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
60 fn multi_character_cjk_word_splittingrust-analyzer cargo comfy-table 7.2.2 all/utf_8_characters/multi_character_cjk_word_splitting().() {
61 let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().();
62 table
63 .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(8)
64 .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#)
65 .set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"])
66 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["abc新年快乐edf"]);
67
68 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}");
69 let expected = "
70 +------+
71 | test |
72 +======+
73 | abc |
74 | 新年 |
75 | 快乐 |
76 | edf |
77 +------+";
78 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}");
79 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(expected, "\n".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). &table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
80 }
81
82 /// Handle emojis that'd joined via the "zero-width joiner" character U+200D and contain variant
83 /// selectors.
84 ///
85 /// Those composite emojis should be handled as a single grapheme and thereby have their width
86 /// calculated based on the grapheme length instead of the individual chars.
87 ///
88 /// This is also a regression test, as previously emojis were split in the middle of the joiner
89 /// sequence, resulting in two different emojis on different lines.
90 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
91 fn zwj_utf8_word_splittingrust-analyzer cargo comfy-table 7.2.2 all/utf_8_characters/zwj_utf8_word_splitting().() {
92 let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().();
93 table
94 .set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(8)
95 .set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Dynamicrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Dynamic#)
96 .set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["test"])
97 .add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["ab🙂‍↕️def"]);
98
99 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}");
100 let expected = "
101 +------+
102 | test |
103 +======+
104 | ab🙂‍↕️ |
105 | def |
106 +------+";
107 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{expected}");
108 assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(expected, "\n".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().() +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). &table.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
109 }