|
| 1 | +## Description ############################################################################# |
| 2 | +# |
| 3 | +# Markdown Back End: Test the compact option. |
| 4 | +# |
| 5 | +############################################################################################ |
| 6 | + |
| 7 | +@testset "Compact Table" verbose = true begin |
| 8 | + matrix = [(i, j) for i in 1:3, j in 1:3] |
| 9 | + |
| 10 | + @testset "Without Cropping" begin |
| 11 | + expected = """ |
| 12 | +# Table Title |
| 13 | +
|
| 14 | +## Table Subtitle |
| 15 | +
|
| 16 | +| **Row** | **Rows** | **Col. 1**<br>`1` | **Merged Column[^1]**<br>`2` | ─ | |
| 17 | +|--:|--:|--:|--:|--:| |
| 18 | +| 1 | **Row 1** | (1, 1) | (1, 2) | (1, 3) | |
| 19 | +| **Row Group** | ─ | ─ | ─ | ─ | |
| 20 | +| 2 | **Row 2** | (2, 1) | (2, 2)[^2] | (2, 3) | |
| 21 | +| 3 | **Row 3** | (3, 1) | (3, 2) | (3, 3) | |
| 22 | +| ─ | ─ | ─ | ─ | ─ | |
| 23 | +| | **Summary 1** | 10 | 20 | 30 | |
| 24 | +| | **Summary 2** | 20 | 40 | 60 | |
| 25 | +
|
| 26 | +[^1]: Footnote in column label |
| 27 | +[^2]: Footnote in data |
| 28 | +
|
| 29 | +Source Notes |
| 30 | +""" |
| 31 | + |
| 32 | + result = pretty_table( |
| 33 | + String, |
| 34 | + matrix; |
| 35 | + backend = :markdown, |
| 36 | + column_labels = [["Col. $i" for i in 1:3], ["$i" for i in 1:3]], |
| 37 | + footnotes = [(:column_label, 1, 2) => "Footnote in column label", (:data, 2, 2) => "Footnote in data"], |
| 38 | + merge_column_label_cells = [MergeCells(1, 2, 2, "Merged Column", :c)], |
| 39 | + row_group_labels = [2 => "Row Group"], |
| 40 | + row_labels = ["Row $i" for i in 1:5], |
| 41 | + show_row_number_column = true, |
| 42 | + source_notes = "Source Notes", |
| 43 | + stubhead_label = "Rows", |
| 44 | + subtitle = "Table Subtitle", |
| 45 | + summary_rows = [(data, i) -> 10i, (data, i) -> 20i], |
| 46 | + table_format = MarkdownTableFormat(compact_table = true), |
| 47 | + title = "Table Title", |
| 48 | + ) |
| 49 | + |
| 50 | + @test result == expected |
| 51 | + |
| 52 | + expected = """ |
| 53 | +# Table Title |
| 54 | +
|
| 55 | +## Table Subtitle |
| 56 | +
|
| 57 | +| **Rows** | **Col. 1**<br>`1` | **Merged Column[^1]**<br>`2` | ─ | |
| 58 | +|--:|--:|--:|--:| |
| 59 | +| **Row 1** | (1, 1) | (1, 2) | (1, 3) | |
| 60 | +| **Row Group** | ─ | ─ | ─ | |
| 61 | +| **Row 2** | (2, 1) | (2, 2)[^2] | (2, 3) | |
| 62 | +| **Row 3** | (3, 1) | (3, 2) | (3, 3) | |
| 63 | +| ─ | ─ | ─ | ─ | |
| 64 | +| **Summary 1** | 10 | 20 | 30 | |
| 65 | +| **Summary 2** | 20 | 40 | 60 | |
| 66 | +
|
| 67 | +[^1]: Footnote in column label |
| 68 | +[^2]: Footnote in data |
| 69 | +
|
| 70 | +Source Notes |
| 71 | +""" |
| 72 | + |
| 73 | + result = pretty_table( |
| 74 | + String, |
| 75 | + matrix; |
| 76 | + backend = :markdown, |
| 77 | + column_labels = [["Col. $i" for i in 1:3], ["$i" for i in 1:3]], |
| 78 | + footnotes = [(:column_label, 1, 2) => "Footnote in column label", (:data, 2, 2) => "Footnote in data"], |
| 79 | + merge_column_label_cells = [MergeCells(1, 2, 2, "Merged Column", :c)], |
| 80 | + row_group_labels = [2 => "Row Group"], |
| 81 | + row_labels = ["Row $i" for i in 1:5], |
| 82 | + show_row_number_column = false, |
| 83 | + source_notes = "Source Notes", |
| 84 | + stubhead_label = "Rows", |
| 85 | + subtitle = "Table Subtitle", |
| 86 | + summary_rows = [(data, i) -> 10i, (data, i) -> 20i], |
| 87 | + table_format = MarkdownTableFormat(compact_table = true), |
| 88 | + title = "Table Title", |
| 89 | + ) |
| 90 | + |
| 91 | + @test result == expected |
| 92 | + end |
| 93 | + |
| 94 | + @testset "With Bottom Cropping" begin |
| 95 | + expected = """ |
| 96 | +# Table Title |
| 97 | +
|
| 98 | +## Table Subtitle |
| 99 | +
|
| 100 | +| **Row** | **Rows** | **Col. 1** | **Merged Column[^1]** | ⋯ | |
| 101 | +|--:|--:|--:|--:|---| |
| 102 | +| 1 | **Row 1** | (1, 1) | (1, 2) | ⋯ | |
| 103 | +| **Row Group** | ─ | ─ | ─ | ⋯ | |
| 104 | +| 2 | **Row 2** | (2, 1) | (2, 2)[^2] | ⋯ | |
| 105 | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋱ | |
| 106 | +| ─ | ─ | ─ | ─ | ─ | |
| 107 | +| | **Summary 1** | 10 | 20 | ⋯ | |
| 108 | +| | **Summary 2** | 20 | 40 | ⋯ | |
| 109 | +
|
| 110 | +*1 column and 1 row omitted* |
| 111 | +
|
| 112 | +[^1]: Footnote in column label |
| 113 | +[^2]: Footnote in data |
| 114 | +
|
| 115 | +Source Notes |
| 116 | +""" |
| 117 | + |
| 118 | + result = pretty_table( |
| 119 | + String, |
| 120 | + matrix; |
| 121 | + backend = :markdown, |
| 122 | + footnotes = [(:column_label, 1, 2) => "Footnote in column label", (:data, 2, 2) => "Footnote in data"], |
| 123 | + maximum_number_of_columns = 2, |
| 124 | + maximum_number_of_rows = 2, |
| 125 | + merge_column_label_cells = [MergeCells(1, 2, 2, "Merged Column", :c)], |
| 126 | + row_group_labels = [2 => "Row Group"], |
| 127 | + row_labels = ["Row $i" for i in 1:5], |
| 128 | + show_row_number_column = true, |
| 129 | + source_notes = "Source Notes", |
| 130 | + stubhead_label = "Rows", |
| 131 | + subtitle = "Table Subtitle", |
| 132 | + summary_rows = [(data, i) -> 10i, (data, i) -> 20i], |
| 133 | + table_format = MarkdownTableFormat(compact_table = true), |
| 134 | + title = "Table Title", |
| 135 | + ) |
| 136 | + |
| 137 | + @test result == expected |
| 138 | + end |
| 139 | + |
| 140 | + @testset "With Middle Cropping" begin |
| 141 | + expected = """ |
| 142 | +# Table Title |
| 143 | +
|
| 144 | +## Table Subtitle |
| 145 | +
|
| 146 | +| **Row** | **Rows** | **Col. 1** | **Merged Column[^1]** | ⋯ | |
| 147 | +|--:|--:|--:|--:|---| |
| 148 | +| 1 | **Row 1** | (1, 1) | (1, 2) | ⋯ | |
| 149 | +| ⋮ | ⋮ | ⋮ | ⋮ | ⋱ | |
| 150 | +| 3 | **Row 3** | (3, 1) | (3, 2) | ⋯ | |
| 151 | +| ─ | ─ | ─ | ─ | ─ | |
| 152 | +| | **Summary 1** | 10 | 20 | ⋯ | |
| 153 | +| | **Summary 2** | 20 | 40 | ⋯ | |
| 154 | +
|
| 155 | +*1 column and 1 row omitted* |
| 156 | +
|
| 157 | +[^1]: Footnote in column label |
| 158 | +[^2]: Footnote in data |
| 159 | +
|
| 160 | +Source Notes |
| 161 | +""" |
| 162 | + |
| 163 | + result = pretty_table( |
| 164 | + String, |
| 165 | + matrix; |
| 166 | + backend = :markdown, |
| 167 | + footnotes = [(:column_label, 1, 2) => "Footnote in column label", (:data, 2, 2) => "Footnote in data"], |
| 168 | + maximum_number_of_columns = 2, |
| 169 | + maximum_number_of_rows = 2, |
| 170 | + merge_column_label_cells = [MergeCells(1, 2, 2, "Merged Column", :c)], |
| 171 | + row_group_labels = [2 => "Row Group"], |
| 172 | + row_labels = ["Row $i" for i in 1:5], |
| 173 | + show_row_number_column = true, |
| 174 | + source_notes = "Source Notes", |
| 175 | + stubhead_label = "Rows", |
| 176 | + subtitle = "Table Subtitle", |
| 177 | + summary_rows = [(data, i) -> 10i, (data, i) -> 20i], |
| 178 | + table_format = MarkdownTableFormat(compact_table = true), |
| 179 | + title = "Table Title", |
| 180 | + vertical_crop_mode = :middle |
| 181 | + ) |
| 182 | + |
| 183 | + @test result == expected |
| 184 | + end |
| 185 | +end |
0 commit comments