| 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 | fn simple_tablerust-analyzer cargo comfy-table 7.2.2 all/simple_test/simple_table().() { |
| 6 | 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().(); |
| 7 | table |
| 8 | .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"]) |
| 9 | .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!![ |
| 10 | "This is a text", |
| 11 | "This is another text", |
| 12 | "This is the third text", |
| 13 | ]) |
| 14 | .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!![ |
| 15 | "This is another text", |
| 16 | "Now\nadd some\nmulti line stuff", |
| 17 | "This is awesome", |
| 18 | ]); |
| 19 | |
| 20 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 21 | let expected = " |
| 22 | +----------------------+----------------------+------------------------+ |
| 23 | | Header1 | Header2 | Header3 | |
| 24 | +======================================================================+ |
| 25 | | This is a text | This is another text | This is the third text | |
| 26 | |----------------------+----------------------+------------------------| |
| 27 | | This is another text | Now | This is awesome | |
| 28 | | | add some | | |
| 29 | | | multi line stuff | | |
| 30 | +----------------------+----------------------+------------------------+"; |
| 31 | 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().()); |
| 32 | } |
| 33 | |
| 34 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 35 | fn missing_column_tablerust-analyzer cargo comfy-table 7.2.2 all/simple_test/missing_column_table().() { |
| 36 | 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().(); |
| 37 | table |
| 38 | .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"]) |
| 39 | .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!!["One One", "One Two", "One Three"]) |
| 40 | .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!!["Two One", "Two Two"]) |
| 41 | .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!!["Three One"]); |
| 42 | |
| 43 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 44 | let expected = " |
| 45 | +-----------+---------+-----------+ |
| 46 | | Header1 | Header2 | Header3 | |
| 47 | +=================================+ |
| 48 | | One One | One Two | One Three | |
| 49 | |-----------+---------+-----------| |
| 50 | | Two One | Two Two | | |
| 51 | |-----------+---------+-----------| |
| 52 | | Three One | | | |
| 53 | +-----------+---------+-----------+"; |
| 54 | 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().()); |
| 55 | } |
| 56 | |
| 57 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 58 | fn single_column_tablerust-analyzer cargo comfy-table 7.2.2 all/simple_test/single_column_table().() { |
| 59 | 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().(); |
| 60 | table |
| 61 | .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"]) |
| 62 | .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!!["One One"]) |
| 63 | .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!!["Two One"]) |
| 64 | .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!!["Three One"]); |
| 65 | |
| 66 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}"); |
| 67 | let expected = " |
| 68 | +-----------+ |
| 69 | | Header1 | |
| 70 | +===========+ |
| 71 | | One One | |
| 72 | |-----------| |
| 73 | | Two One | |
| 74 | |-----------| |
| 75 | | Three One | |
| 76 | +-----------+"; |
| 77 | 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().()); |
| 78 | } |
| 79 | |
| 80 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 81 | fn linesrust-analyzer cargo comfy-table 7.2.2 all/simple_test/lines().() { |
| 82 | let mut t = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().(); |
| 83 | t.set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(["heading 1", "heading 2", "heading 3"]); |
| 84 | t.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(["test 1,1", "test 1,2", "test 1,3"]); |
| 85 | t.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(["test 2,1", "test 2,2", "test 2,3"]); |
| 86 | t.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(["test 3,1", "test 3,2", "test 3,3"]); |
| 87 | |
| 88 | let actual = t.linesrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]lines().(); |
| 89 | let expected = &[ |
| 90 | "+-----------+-----------+-----------+", |
| 91 | "| heading 1 | heading 2 | heading 3 |", |
| 92 | "+===================================+", |
| 93 | "| test 1,1 | test 1,2 | test 1,3 |", |
| 94 | "|-----------+-----------+-----------|", |
| 95 | "| test 2,1 | test 2,2 | test 2,3 |", |
| 96 | "|-----------+-----------+-----------|", |
| 97 | "| test 3,1 | test 3,2 | test 3,3 |", |
| 98 | "+-----------+-----------+-----------+", |
| 99 | ]; |
| 100 | |
| 101 | assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!(actual.collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>>(), expected); |
| 102 | } |