mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 21:49:08 +00:00
Renaming.
This commit is contained in:
parent
6209ada254
commit
f153702409
@ -56,7 +56,7 @@ const DEFAULT_COLUMN: Column = Column {
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct AsciiTable {
|
||||
pub width: usize,
|
||||
pub max_width: usize,
|
||||
pub columns: BTreeMap<usize, Column>
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ impl Default for AsciiTable {
|
||||
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
width: 80,
|
||||
max_width: 80,
|
||||
columns: BTreeMap::new()
|
||||
}
|
||||
}
|
||||
@ -151,7 +151,7 @@ impl AsciiTable {
|
||||
fn valid(&self, data: &Vec<Vec<String>>, num_cols: usize) -> bool {
|
||||
if data.len() == 0 {
|
||||
false
|
||||
} else if self.width < 4 {
|
||||
} else if self.max_width < 4 {
|
||||
false
|
||||
} else if num_cols == 0 {
|
||||
false
|
||||
@ -186,7 +186,7 @@ impl AsciiTable {
|
||||
}
|
||||
|
||||
fn truncate_widths(&self, mut widths: Vec<usize>) -> Vec<usize> {
|
||||
let max_width = self.width;
|
||||
let max_width = self.max_width;
|
||||
let table_padding = ((widths.len() - 1) * 3) + 4;
|
||||
while widths.iter().sum::<usize>() + table_padding > max_width &&
|
||||
*widths.iter().max().unwrap() > 0 {
|
||||
|
16
src/test.rs
16
src/test.rs
@ -96,7 +96,7 @@ fn one_cell() {
|
||||
#[test]
|
||||
fn smallest_cell() {
|
||||
let config = AsciiTable {
|
||||
width: 4,
|
||||
max_width: 4,
|
||||
..default_config()
|
||||
};
|
||||
let input = vec![&[123]];
|
||||
@ -110,7 +110,7 @@ fn smallest_cell() {
|
||||
#[test]
|
||||
fn smallest_cube() {
|
||||
let config = AsciiTable {
|
||||
width: 4,
|
||||
max_width: 4,
|
||||
..default_config()
|
||||
};
|
||||
let input = vec![&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
|
||||
@ -126,7 +126,7 @@ fn smallest_cube() {
|
||||
#[test]
|
||||
fn show_no_content_for_cell() {
|
||||
let config = AsciiTable {
|
||||
width: 5,
|
||||
max_width: 5,
|
||||
..default_config()
|
||||
};
|
||||
let input = vec![&[123]];
|
||||
@ -140,7 +140,7 @@ fn show_no_content_for_cell() {
|
||||
#[test]
|
||||
fn show_one_character_for_cell() {
|
||||
let config = AsciiTable {
|
||||
width: 6,
|
||||
max_width: 6,
|
||||
..default_config()
|
||||
};
|
||||
let input = vec![&[123]];
|
||||
@ -154,7 +154,7 @@ fn show_one_character_for_cell() {
|
||||
#[test]
|
||||
fn smallest_cell_with_header() {
|
||||
let mut config = AsciiTable {
|
||||
width: 4,
|
||||
max_width: 4,
|
||||
..default_config()
|
||||
};
|
||||
config.columns.insert(0, Column {header: "foo".to_string(), ..Column::default()});
|
||||
@ -171,7 +171,7 @@ fn smallest_cell_with_header() {
|
||||
#[test]
|
||||
fn smallest_cube_with_header() {
|
||||
let mut config = AsciiTable {
|
||||
width: 4,
|
||||
max_width: 4,
|
||||
..default_config()
|
||||
};
|
||||
config.columns.insert(0, Column {header: "abc".to_string(), ..Column::default()});
|
||||
@ -192,7 +192,7 @@ fn smallest_cube_with_header() {
|
||||
#[test]
|
||||
fn show_no_content_for_header() {
|
||||
let mut config = AsciiTable {
|
||||
width: 5,
|
||||
max_width: 5,
|
||||
..default_config()
|
||||
};
|
||||
config.columns.insert(0, Column {header: "abc".to_string(), ..Column::default()});
|
||||
@ -209,7 +209,7 @@ fn show_no_content_for_header() {
|
||||
#[test]
|
||||
fn show_one_character_for_header() {
|
||||
let mut config = AsciiTable {
|
||||
width: 6,
|
||||
max_width: 6,
|
||||
..default_config()
|
||||
};
|
||||
config.columns.insert(0, Column {header: "abc".to_string(), ..Column::default()});
|
||||
|
Loading…
Reference in New Issue
Block a user