Fix typos and use more idiomatic assertions (#7755)

I have changed `assert!(a == b)` calls to `assert_eq!(a, b)`, which give
better error messages. Similarly for `assert!(a != b)` and
`assert_ne!(a, b)`. Basically all instances were comparing primitives
(string slices or integers), so there is no loss of generality from
special-case macros,

I have also fixed a number of typos in comments, variable names, and a
few user-facing messages.
This commit is contained in:
Anton
2023-01-15 05:03:32 +03:00
committed by GitHub
parent b0b0482d71
commit 7221eb7f39
32 changed files with 143 additions and 143 deletions

View File

@ -263,12 +263,12 @@ fn build_expanded_table(
// check whether we need to expand table or not,
// todo: we can make it more effitient
const EXPAND_TREASHHOLD: f32 = 0.80;
const EXPAND_THRESHOLD: f32 = 0.80;
let width = string_width(&s);
let used_percent = width as f32 / term_width as f32;
if width < term_width && used_percent > EXPAND_TREASHHOLD {
if width < term_width && used_percent > EXPAND_THRESHOLD {
let table_config = table_config.expand();
table.draw(table_config, term_width)
} else {
@ -419,12 +419,12 @@ fn convert_to_table2<'a>(
for (col, header) in headers.into_iter().enumerate() {
let is_last_col = col + 1 == count_columns;
let mut nessary_space = PADDING_SPACE;
let mut necessary_space = PADDING_SPACE;
if !is_last_col {
nessary_space += SPLIT_LINE_SPACE;
necessary_space += SPLIT_LINE_SPACE;
}
if available_width == 0 || available_width <= nessary_space {
if available_width == 0 || available_width <= necessary_space {
// MUST NEVER HAPPEN (ideally)
// but it does...
@ -432,7 +432,7 @@ fn convert_to_table2<'a>(
break;
}
available_width -= nessary_space;
available_width -= necessary_space;
let mut column_width = string_width(&header);
@ -474,7 +474,7 @@ fn convert_to_table2<'a>(
}
if column_width >= available_width
|| (!is_last_col && column_width + nessary_space >= available_width)
|| (!is_last_col && column_width + necessary_space >= available_width)
{
// so we try to do soft landing
// by doing a truncating in case there will be enough space for it.
@ -530,7 +530,7 @@ fn convert_to_table2<'a>(
row.pop();
}
available_width += nessary_space;
available_width += necessary_space;
truncate = true;
break;

View File

@ -130,8 +130,8 @@ fn convert_records_to_dataset(cols: &Vec<String>, records: Vec<Value>) -> Vec<Ve
} else if cols.len() == records.len() {
vec![records]
} else {
// I am not sure whether it's good to return records as its length LIKELY will not match columns,
// which makes no scense......
// I am not sure whether it's good to return records as its length LIKELY
// will not match columns, which makes no sense......
//
// BUT...
// we can represent it as a list; which we do

View File

@ -615,7 +615,7 @@ fn highlight_search_results(f: &mut Frame, pager: &Pager, layout: &Layout, style
return;
}
let hightlight_block = Block::default().style(nu_style_to_tui(style));
let highlight_block = Block::default().style(nu_style_to_tui(style));
for e in &layout.data {
let text = ansi_str::AnsiStr::ansi_strip(&e.text);
@ -626,7 +626,7 @@ fn highlight_search_results(f: &mut Frame, pager: &Pager, layout: &Layout, style
let w = pager.search_buf.buf_cmd_input.len() as u16;
let area = Rect::new(e.area.x + p as u16, e.area.y, w, 1);
f.render_widget(hightlight_block.clone(), area);
f.render_widget(highlight_block.clone(), area);
}
}
}

View File

@ -621,21 +621,21 @@ fn convert_records_to_string(
fn highlight_cell(f: &mut Frame, area: Rect, info: ElementInfo, theme: &CursorStyle) {
if let Some(style) = theme.selected_column {
let hightlight_block = Block::default().style(nu_style_to_tui(style));
let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(info.area.x, area.y, info.area.width, area.height);
f.render_widget(hightlight_block.clone(), area);
f.render_widget(highlight_block.clone(), area);
}
if let Some(style) = theme.selected_row {
let hightlight_block = Block::default().style(nu_style_to_tui(style));
let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(area.x, info.area.y, area.width, 1);
f.render_widget(hightlight_block.clone(), area);
f.render_widget(highlight_block.clone(), area);
}
if let Some(style) = theme.selected_cell {
let hightlight_block = Block::default().style(nu_style_to_tui(style));
let highlight_block = Block::default().style(nu_style_to_tui(style));
let area = Rect::new(info.area.x, info.area.y, info.area.width, 1);
f.render_widget(hightlight_block.clone(), area);
f.render_widget(highlight_block.clone(), area);
}
if theme.show_cursor {