Skip to content

Commit

Permalink
Fix QC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt committed Aug 5, 2024
1 parent dbc235b commit 59c4b54
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 33 deletions.
51 changes: 24 additions & 27 deletions tabled/examples/builder_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
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}");
}
4 changes: 2 additions & 2 deletions tabled/tests/qc/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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));
}
}

Expand Down
8 changes: 4 additions & 4 deletions tabled/tests/qc/tests/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand All @@ -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));
}
}

Expand Down

0 comments on commit 59c4b54

Please sign in to comment.