| 1 | use comfy_table::{presets::*, *}; |
| 2 | use pretty_assertions::assert_eq; |
| 3 | |
| 4 | fn get_preset_table() -> Table { |
| 5 | let mut table = Table::new(); |
| 6 | table |
| 7 | .set_header(vec!["Hello", "there"]) |
| 8 | .add_row(vec!["a", "b"]) |
| 9 | .add_row(vec!["c", "d"]); |
| 10 | |
| 11 | table |
| 12 | } |
| 13 | |
| 14 | #[test] |
| 15 | fn test_ascii_full() { |
| 16 | let mut table = get_preset_table(); |
| 17 | table.load_preset(ASCII_FULL); |
| 18 | println!("{table}"); |
| 19 | let expected = " |
| 20 | +-------+-------+ |
| 21 | | Hello | there | |
| 22 | +===============+ |
| 23 | | a | b | |
| 24 | |-------+-------| |
| 25 | | c | d | |
| 26 | +-------+-------+"; |
| 27 | println!("{expected}"); |
| 28 | assert_eq!(expected, "\n".to_string() + &table.to_string()); |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn test_ascii_full_condensed() { |
| 33 | let mut table = get_preset_table(); |
| 34 | table.load_preset(ASCII_FULL_CONDENSED); |
| 35 | println!("{table}"); |
| 36 | let expected = " |
| 37 | +-------+-------+ |
| 38 | | Hello | there | |
| 39 | +===============+ |
| 40 | | a | b | |
| 41 | | c | d | |
| 42 | +-------+-------+"; |
| 43 | println!("{expected}"); |
| 44 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 45 | } |
| 46 | |
| 47 | #[test] |
| 48 | fn test_ascii_no_borders() { |
| 49 | let mut table = get_preset_table(); |
| 50 | table.load_preset(ASCII_NO_BORDERS); |
| 51 | println!("{table}"); |
| 52 | let expected = " |
| 53 | Hello | there |
| 54 | =============== |
| 55 | a | b |
| 56 | -------+------- |
| 57 | c | d"; |
| 58 | println!("{expected}"); |
| 59 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 60 | } |
| 61 | |
| 62 | #[test] |
| 63 | fn test_ascii_borders_only() { |
| 64 | let mut table = get_preset_table(); |
| 65 | table.load_preset(ASCII_BORDERS_ONLY); |
| 66 | println!("{table}"); |
| 67 | let expected = " |
| 68 | +---------------+ |
| 69 | | Hello there | |
| 70 | +===============+ |
| 71 | | a b | |
| 72 | | | |
| 73 | | c d | |
| 74 | +---------------+"; |
| 75 | println!("{expected}"); |
| 76 | assert_eq!(expected, "\n".to_string() + &table.to_string()); |
| 77 | } |
| 78 | |
| 79 | #[test] |
| 80 | fn test_ascii_borders_only_condensed() { |
| 81 | let mut table = get_preset_table(); |
| 82 | table.load_preset(ASCII_BORDERS_ONLY_CONDENSED); |
| 83 | println!("{table}"); |
| 84 | let expected = " |
| 85 | +---------------+ |
| 86 | | Hello there | |
| 87 | +===============+ |
| 88 | | a b | |
| 89 | | c d | |
| 90 | +---------------+"; |
| 91 | println!("{expected}"); |
| 92 | assert_eq!(expected, "\n".to_string() + &table.to_string()); |
| 93 | } |
| 94 | |
| 95 | #[test] |
| 96 | fn test_ascii_horizontal_only() { |
| 97 | let mut table = get_preset_table(); |
| 98 | table.load_preset(ASCII_HORIZONTAL_ONLY); |
| 99 | println!("{table}"); |
| 100 | let expected = " |
| 101 | --------------- |
| 102 | Hello there |
| 103 | =============== |
| 104 | a b |
| 105 | --------------- |
| 106 | c d |
| 107 | ---------------"; |
| 108 | println!("{expected}"); |
| 109 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 110 | } |
| 111 | |
| 112 | #[test] |
| 113 | fn test_ascii_markdown() { |
| 114 | let mut table = get_preset_table(); |
| 115 | table.load_preset(ASCII_MARKDOWN); |
| 116 | println!("{table}"); |
| 117 | let expected = " |
| 118 | | Hello | there | |
| 119 | |-------|-------| |
| 120 | | a | b | |
| 121 | | c | d |"; |
| 122 | println!("{expected}"); |
| 123 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 124 | } |
| 125 | |
| 126 | #[test] |
| 127 | fn test_utf8_full() { |
| 128 | let mut table = get_preset_table(); |
| 129 | table.load_preset(UTF8_FULL); |
| 130 | println!("{table}"); |
| 131 | let expected = " |
| 132 | ┌───────┬───────┐ |
| 133 | │ Hello ┆ there │ |
| 134 | ╞═══════╪═══════╡ |
| 135 | │ a ┆ b │ |
| 136 | ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ |
| 137 | │ c ┆ d │ |
| 138 | └───────┴───────┘"; |
| 139 | println!("{expected}"); |
| 140 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 141 | } |
| 142 | |
| 143 | #[test] |
| 144 | fn test_utf8_full_condensed() { |
| 145 | let mut table = get_preset_table(); |
| 146 | table.load_preset(UTF8_FULL_CONDENSED); |
| 147 | println!("{table}"); |
| 148 | let expected = " |
| 149 | ┌───────┬───────┐ |
| 150 | │ Hello ┆ there │ |
| 151 | ╞═══════╪═══════╡ |
| 152 | │ a ┆ b │ |
| 153 | │ c ┆ d │ |
| 154 | └───────┴───────┘"; |
| 155 | println!("{expected}"); |
| 156 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 157 | } |
| 158 | |
| 159 | #[test] |
| 160 | fn test_utf8_no_borders() { |
| 161 | let mut table = get_preset_table(); |
| 162 | table.load_preset(UTF8_NO_BORDERS); |
| 163 | println!("{table}"); |
| 164 | let expected = " |
| 165 | Hello ┆ there |
| 166 | ═══════╪═══════ |
| 167 | a ┆ b |
| 168 | ╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌ |
| 169 | c ┆ d"; |
| 170 | println!("{expected}"); |
| 171 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 172 | } |
| 173 | |
| 174 | #[test] |
| 175 | fn test_utf8_horizontal_only() { |
| 176 | let mut table = get_preset_table(); |
| 177 | table.load_preset(UTF8_HORIZONTAL_ONLY); |
| 178 | println!("{table}"); |
| 179 | let expected = " |
| 180 | ─────────────── |
| 181 | Hello there |
| 182 | ═══════════════ |
| 183 | a b |
| 184 | ─────────────── |
| 185 | c d |
| 186 | ───────────────"; |
| 187 | println!("{expected}"); |
| 188 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 189 | } |
| 190 | |
| 191 | #[test] |
| 192 | fn test_nothing() { |
| 193 | let mut table = get_preset_table(); |
| 194 | table.load_preset(NOTHING); |
| 195 | println!("{table}"); |
| 196 | let expected = " |
| 197 | Hello there |
| 198 | a b |
| 199 | c d"; |
| 200 | println!("{expected}"); |
| 201 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 202 | } |
| 203 | |
| 204 | #[test] |
| 205 | fn test_nothing_without_padding() { |
| 206 | let mut table = get_preset_table(); |
| 207 | table.load_preset(NOTHING); |
| 208 | let column = table.column_iter_mut().next().unwrap(); |
| 209 | column.set_padding((0, 1)); |
| 210 | println!("{table}"); |
| 211 | let expected = " |
| 212 | Hello there |
| 213 | a b |
| 214 | c d"; |
| 215 | println!("{expected}"); |
| 216 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 217 | } |
| 218 | |
| 219 | #[test] |
| 220 | fn test_no_vertical_styling() { |
| 221 | let mut table = Table::new(); |
| 222 | table |
| 223 | .set_header(vec!["Hello", "there", "again"]) |
| 224 | .add_row(vec!["a", "b", "something different"]) |
| 225 | .add_row(vec!["omfg why though", "d", "f"]); |
| 226 | |
| 227 | table.load_preset("|| - "); |
| 228 | |
| 229 | println!("{table}"); |
| 230 | let expected = " |
| 231 | | Hello there again | |
| 232 | --------------------------------------------- |
| 233 | | a b something different | |
| 234 | | omfg why though d f |"; |
| 235 | println!("{expected}"); |
| 236 | assert_eq!(expected, "\n".to_string() + &table.trim_fmt()); |
| 237 | } |