From 59c4b54c72e000c08676c0fcda4101f732a64873 Mon Sep 17 00:00:00 2001 From: Maxim Zhiburt Date: Mon, 5 Aug 2024 23:05:59 +0300 Subject: [PATCH] Fix QC tests --- tabled/examples/builder_index.rs | 51 +++++++++++++++----------------- tabled/tests/qc/tests/builder.rs | 4 +-- tabled/tests/qc/tests/span.rs | 8 ++--- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/tabled/examples/builder_index.rs b/tabled/examples/builder_index.rs index b5e3d1ac..109eab3c 100644 --- a/tabled/examples/builder_index.rs +++ b/tabled/examples/builder_index.rs @@ -9,45 +9,42 @@ //! * Note that like with any builder pattern the [`IndexBuilder::build()`] function //! is necessary to produce a displayable [`Table`]. -use tabled::{ - settings::{object::Columns, Alignment, Style}, - Table, Tabled, -}; +use tabled::{settings::Style, Table, Tabled}; #[derive(Tabled)] -#[tabled(rename_all = "PascalCase")] -struct Post { - title: String, - #[tabled(format("{} @{}", self.writer, self.team.as_deref().unwrap_or("")))] - writer: String, - #[tabled(skip)] - team: Option, +struct Distribution { + name: String, + based_on: String, + is_active: bool, + is_cool: bool, } -impl Post { - fn new(title: &str, writer: &str, team: Option<&str>) -> Self { +impl Distribution { + fn new(name: &str, based: &str, is_active: bool, is_cool: bool) -> Self { Self { - title: title.to_string(), - writer: writer.to_string(), - team: team.map(ToString::to_string), + name: name.to_string(), + based_on: based.to_string(), + is_active, + is_cool, } } } fn main() { - let content = vec![ - Post::new( - "crates.io: development update", - "Tobias Bieniek", - Some("crates.io"), - ), - Post::new("Announcing Rust 1.80.0", "", Some("The Rust Release Team")), - Post::new("Types Team Update and Roadmap", "lcnr", None), + let data = vec![ + Distribution::new("Manjaro", "Arch", true, true), + Distribution::new("Arch", "None", true, true), + Distribution::new("Debian", "None", true, true), ]; - let mut table = Table::new(content); - table.with(Style::rounded()); - table.modify(Columns::last(), Alignment::right()); + let mut table = Table::builder(data) + .index() + .column(0) + .transpose() + .name(None) + .build(); + + table.with(Style::modern_rounded()); println!("{table}"); } diff --git a/tabled/tests/qc/tests/builder.rs b/tabled/tests/qc/tests/builder.rs index cb9356d6..3a2b9492 100644 --- a/tabled/tests/qc/tests/builder.rs +++ b/tabled/tests/qc/tests/builder.rs @@ -2,7 +2,7 @@ use quickcheck::Arbitrary; use quickcheck_macros::quickcheck; use tabled::{ builder::Builder, - grid::util::string::{get_line_width, get_string_width}, + grid::util::string::{get_line_width, get_text_width}, settings::Style, Table, }; @@ -37,7 +37,7 @@ fn qc_table_is_consistent_with_borders(table_structure: TableStructure) { let output = table.to_string(); if let Some(line) = output.lines().next() { - assert_eq!(get_line_width(line), get_string_width(&output)); + assert_eq!(get_line_width(line), get_text_width(&output)); } } diff --git a/tabled/tests/qc/tests/span.rs b/tabled/tests/qc/tests/span.rs index db28403f..182b3358 100644 --- a/tabled/tests/qc/tests/span.rs +++ b/tabled/tests/qc/tests/span.rs @@ -3,7 +3,7 @@ use quickcheck_macros::quickcheck; use tabled::{ builder::Builder, - grid::util::string::{get_line_width, get_string_width}, + grid::util::string::{get_line_width, get_text_width}, settings::{Modify, Span, Style}, Table, }; @@ -18,7 +18,7 @@ fn qc_tget_string_widthable_is_consistent_with_hspan_and_vspan(table_structure: let output = table.to_string(); if let Some(line) = output.lines().next() { - assert_eq!(get_line_width(line), get_string_width(&output)); + assert_eq!(get_line_width(line), get_text_width(&output)); } } @@ -31,7 +31,7 @@ fn qc_table_is_consistent_with_hspan(table_structure: TableStructure) { let output = table.to_string(); if let Some(line) = output.lines().next() { - assert_eq!(get_line_width(line), get_string_width(&output)); + assert_eq!(get_line_width(line), get_text_width(&output)); } } @@ -44,7 +44,7 @@ fn qc_table_is_consistent_with_vspan(table_structure: TableStructure) { let output = table.to_string(); if let Some(line) = output.lines().next() { - assert_eq!(get_line_width(line), get_string_width(&output)); + assert_eq!(get_line_width(line), get_text_width(&output)); } }