Repository: zhiburt/tabled
Pull request #301 (2023-03-11 22:50:41)

Fix qc tests


Patch:
diff --git a/README.md b/README.md
index 7f2fc1e..3119687 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 [<img alt="github" src="https://img.shields.io/badge/github-zhiburt/tabled-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/zhiburt/tabled/)
 [<img alt="crates.io" src="https://img.shields.io/crates/v/tabled.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/tabled)
 [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-tabled-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/tabled)
-[<img alt="build status" src="https://img.shields.io/github/workflow/status/zhiburt/tabled/Continuous%20integration/master?style=for-the-badge" height="20">](https://github.com/zhiburt/tabled/actions)
+[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/zhiburt/tabled/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/zhiburt/tabled/actions)
 [<img alt="coverage" src="https://img.shields.io/coveralls/github/zhiburt/tabled/master?style=for-the-badge" height="20">](https://coveralls.io/github/zhiburt/tabled)
 [<img alt="dependency status" src="https://deps.rs/repo/github/zhiburt/tabled/status.svg?style=for-the-badge" height="20">](https://deps.rs/repo/github/zhiburt/tabled)
 
diff --git a/tabled/src/settings/span/column.rs b/tabled/src/settings/span/column.rs
index 7054c65..b8ee0ba 100644
--- a/tabled/src/settings/span/column.rs
+++ b/tabled/src/settings/span/column.rs
@@ -35,6 +35,7 @@ where
         let count_cols = records.count_columns();
 
         set_col_spans(cfg, self.size, entity, (count_rows, count_cols));
+        remove_false_spans(cfg);
     }
 }
 
@@ -104,3 +105,19 @@ fn span_has_intersections(cfg: &GridConfig, (row, col): Position, span: usize) -
 
     false
 }
+
+fn remove_false_spans(cfg: &mut GridConfig) {
+    for (pos, _) in cfg.iter_span_columns().collect::<Vec<_>>() {
+        if !cfg.is_cell_visible(pos) {
+            cfg.set_row_span(pos, 1);
+            cfg.set_column_span(pos, 1);
+        }
+    }
+
+    for (pos, _) in cfg.iter_span_rows().collect::<Vec<_>>() {
+        if !cfg.is_cell_visible(pos) {
+            cfg.set_row_span(pos, 1);
+            cfg.set_column_span(pos, 1);
+        }
+    }
+}
diff --git a/tabled/src/settings/span/row.rs b/tabled/src/settings/span/row.rs
index 683a64e..cfca5d8 100644
--- a/tabled/src/settings/span/row.rs
+++ b/tabled/src/settings/span/row.rs
@@ -35,6 +35,7 @@ where
         let count_cols = records.count_columns();
 
         set_row_spans(cfg, self.size, entity, (count_rows, count_cols));
+        remove_false_spans(cfg);
     }
 }
 
@@ -105,3 +106,19 @@ fn span_has_intersections(cfg: &GridConfig, (row, col): Position, span: usize) -
 
     false
 }
+
+fn remove_false_spans(cfg: &mut GridConfig) {
+    for (pos, _) in cfg.iter_span_columns().collect::<Vec<_>>() {
+        if !cfg.is_cell_visible(pos) {
+            cfg.set_row_span(pos, 1);
+            cfg.set_column_span(pos, 1);
+        }
+    }
+
+    for (pos, _) in cfg.iter_span_rows().collect::<Vec<_>>() {
+        if !cfg.is_cell_visible(pos) {
+            cfg.set_row_span(pos, 1);
+            cfg.set_column_span(pos, 1);
+        }
+    }
+}
diff --git a/tabled/src/settings/table_option.rs b/tabled/src/settings/table_option.rs
index c601950..d29af1e 100644
--- a/tabled/src/settings/table_option.rs
+++ b/tabled/src/settings/table_option.rs
@@ -14,3 +14,26 @@ where
         T::change(self, records, cfg, dimension);
     }
 }
+
+impl<T, R, D, C> TableOption<R, D, C> for [T]
+where
+    T: TableOption<R, D, C>,
+{
+    fn change(&mut self, records: &mut R, cfg: &mut C, dimension: &mut D) {
+        for opt in self {
+            opt.change(records, cfg, dimension)
+        }
+    }
+}
+
+#[cfg(feature = "std")]
+impl<T, R, D, C> TableOption<R, D, C> for Vec<T>
+where
+    T: TableOption<R, D, C>,
+{
+    fn change(&mut self, records: &mut R, cfg: &mut C, dimension: &mut D) {
+        for opt in self {
+            opt.change(records, cfg, dimension)
+        }
+    }
+}


Test patch:
diff --git a/tabled/tests/span_test.rs b/tabled/tests/span_test.rs
index cef8f59..8e7822e 100644
--- a/tabled/tests/span_test.rs
+++ b/tabled/tests/span_test.rs
@@ -1,7 +1,11 @@
 #![cfg(feature = "std")]
 #![allow(clippy::redundant_clone)]
 
+use std::iter::FromIterator;
+
+use papergrid::config::Position;
 use tabled::{
+    builder::Builder,
     settings::{
         object::{Columns, Segment},
         style::{Border, BorderSpanCorrection, Style},
@@ -1212,3 +1216,27 @@ test_table!(
     "| 2 |   2-0    |   2-1    |   2-2    |"
     "+---+----------+----------+----------+"
 );
+
+test_table!(
+    fix_qc_0,
+    {
+        let data: [[i64; 39]; 2] = [[2542785870, 2382388818, 2879895075, 2885436543, 2331131758, 219892320, 2503640226, 3754929678, 2206481860, 686909682, 3456499235, 931699300, 1556722454, 958179233, 3896072307, 2042612749, 3354379549, 3272539286, 3926297167, 4294967295, 1650407458, 3322068437, 4294967295, 446762625, 829020202, 4150192304, 3430619243, 3460609391, 2992017103, 513091574, 1514148367, 2166549688, 1401371431, 2854075038, 1286733939, 2959901405, 4152658371, 0, 4224074215], [360331598, 3736108702, 2948800064, 2121584548, 1609988995, 469935087, 3974876615, 2193609088, 3568111892, 732365859, 0, 4294967295, 2994498036, 198522721, 1784359340, 1, 2732726754, 592359359, 3016729802, 878533877, 2997437699, 3573361662, 1111570515, 4294967295, 2245782848, 1383106893, 0, 0, 2869976103, 1611436878, 1682224972, 3249055253, 1562255501, 1370527728, 240481955, 334260406, 2247343342, 3000635978, 395723768]];
+        let row_spans = [2, 1, 27, 111, 226, 221, 121, 22, 252, 30, 115, 85, 255, 126, 26, 245, 36, 50, 255, 211, 47, 114, 174, 173, 145, 138, 78, 198, 253, 229, 151, 243, 242, 30, 52, 116, 177, 25, 1, 32, 28, 48, 225, 103, 17, 243, 0, 128, 69, 206, 221, 105, 239, 74, 184, 48, 178, 237, 120, 228, 184, 1, 132, 118, 14, 187];
+        let col_spans = [7, 91, 56, 246, 73];
+
+        let data = data.iter().map(|row| row.iter().map(ToString::to_string));
+        let rspans = create_span_list(2, 39).zip(row_spans.iter()).map(|(pos, span)| Modify::new(pos).with(Span::horizontal(*span))).collect::<Vec<_>>();
+        let cspans = create_span_list(2, 39).zip(col_spans.iter()).map(|(pos, span)| Modify::new(pos).with(Span::vertical(*span))).collect::<Vec<_>>();
+
+        Builder::from_iter(data).build().with(Style::ascii()).with(rspans).with(cspans).to_string()
+    },
+    "+------+-----++++++++++++++++++++++++++++------------+------------+------------+------------+------------+-----------+-----------+------------+------------+-----------+"
+    "| 2542785870 | 2879895075               | 513091574                                                                                                                    |"
+    "+            +                          +------------+------------+------------+------------+------------+-----------+-----------+------------+------------+-----------+"
+    "|            |                          | 1611436878 | 1682224972 | 3249055253 | 1562255501 | 1370527728 | 240481955 | 334260406 | 2247343342 | 3000635978 | 395723768 |"
+    "+------+-----++++++++++++++++++++++++++++------------+------------+------------+------------+------------+-----------+-----------+------------+------------+-----------+"
+);
+
+fn create_span_list(count_rows: usize, count_cols: usize) -> impl Iterator<Item = Position> {
+    (0..count_rows).flat_map(move |r| (0..count_cols).map(move |c| (r, c)))
+}