mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 01:35:02 +02:00
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:
@ -161,7 +161,7 @@ fn remove_impl(input: &[u8], arg: &Arguments, span: Span) -> Value {
|
||||
|
||||
// Note:
|
||||
// remove_all from start and end will generate the same result.
|
||||
// so we'll put `remove_all` relative logic into else clouse.
|
||||
// so we'll put `remove_all` relative logic into else clause.
|
||||
if arg.end && !remove_all {
|
||||
let (mut left, mut right) = (
|
||||
input.len() as isize - arg.pattern.len() as isize,
|
||||
@ -172,7 +172,7 @@ fn remove_impl(input: &[u8], arg: &Arguments, span: Span) -> Value {
|
||||
left -= 1;
|
||||
right -= 1;
|
||||
}
|
||||
// append the remaining thing to result, this can be happeneed when
|
||||
// append the remaining thing to result, this can be happening when
|
||||
// we have something to remove and remove_all is False.
|
||||
let mut remain = input[..left as usize].iter().copied().rev().collect();
|
||||
result.append(&mut remain);
|
||||
|
@ -23,7 +23,7 @@ impl Command for ExprOtherwise {
|
||||
.required(
|
||||
"otherwise expression",
|
||||
SyntaxShape::Any,
|
||||
"expressioini to apply when no when predicate matches",
|
||||
"expression to apply when no when predicate matches",
|
||||
)
|
||||
.input_type(Type::Any)
|
||||
.output_type(Type::Custom("expression".into()))
|
||||
|
@ -46,7 +46,7 @@ impl Command for SubCommand {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
let e = std::f64::consts::E;
|
||||
vec![Example {
|
||||
description: "Apply the hyperpolic cosine to 1",
|
||||
description: "Apply the hyperbolic cosine to 1",
|
||||
example: "1 | math cosh",
|
||||
result: Some(Value::test_float(((e * e) + 1.0) / (2.0 * e))),
|
||||
}]
|
||||
|
@ -46,7 +46,7 @@ impl Command for SubCommand {
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
let e = std::f64::consts::E;
|
||||
vec![Example {
|
||||
description: "Apply the hyperpolic sine to 1",
|
||||
description: "Apply the hyperbolic sine to 1",
|
||||
example: "1 | math sinh",
|
||||
result: Some(Value::test_float((e * e - 1.0) / (2.0 * e))),
|
||||
}]
|
||||
|
@ -45,7 +45,7 @@ impl Command for SubCommand {
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Apply the hyperpolic tangent to 10*pi",
|
||||
description: "Apply the hyperbolic tangent to 10*pi",
|
||||
example: "(math pi) * 10 | math tanh",
|
||||
result: Some(Value::test_float(1f64)),
|
||||
}]
|
||||
|
@ -81,7 +81,7 @@ impl Command for SubCommand {
|
||||
}),
|
||||
},
|
||||
Example {
|
||||
description: "Encode all non anphanumeric chars with all flag",
|
||||
description: "Encode all non alphanumeric chars with all flag",
|
||||
example: "'https://example.com/foo bar' | url encode --all",
|
||||
result: Some(Value::test_string("https%3A%2F%2Fexample%2Ecom%2Ffoo%20bar")),
|
||||
},
|
||||
|
@ -359,7 +359,7 @@ fn test_count_counts_lines() {
|
||||
const LS: &str = "\u{2028}"; // 0xe280a8
|
||||
const PS: &str = "\u{2029}"; // 0xe280a9
|
||||
|
||||
// * \r\n is a single graheme cluster
|
||||
// * \r\n is a single grapheme cluster
|
||||
// * trailing newlines are counted
|
||||
// * NEL is 2 bytes
|
||||
// * FF is 1 byte
|
||||
|
@ -92,7 +92,7 @@ impl Command for Table {
|
||||
)
|
||||
.switch(
|
||||
"collapse",
|
||||
"expand the table structure in colapse mode.\nBe aware collapse mode currently doesn't support width control",
|
||||
"expand the table structure in collapse mode.\nBe aware collapse mode currently doesn't support width control",
|
||||
Some('c'),
|
||||
)
|
||||
.category(Category::Viewers)
|
||||
@ -1083,12 +1083,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...
|
||||
|
||||
@ -1096,7 +1096,7 @@ fn convert_to_table2<'a>(
|
||||
break;
|
||||
}
|
||||
|
||||
available_width -= nessary_space;
|
||||
available_width -= necessary_space;
|
||||
|
||||
let mut column_width = string_width(&header);
|
||||
|
||||
@ -1136,7 +1136,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.
|
||||
@ -1188,7 +1188,7 @@ fn convert_to_table2<'a>(
|
||||
row.pop();
|
||||
}
|
||||
|
||||
available_width += nessary_space;
|
||||
available_width += necessary_space;
|
||||
|
||||
truncate = true;
|
||||
break;
|
||||
@ -1629,14 +1629,14 @@ impl PagingTableCreator {
|
||||
let table = match table_s {
|
||||
Some(s) => {
|
||||
// check whether we need to expand table or not,
|
||||
// todo: we can make it more effitient
|
||||
// todo: we can make it more efficient
|
||||
|
||||
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 {
|
||||
|
Reference in New Issue
Block a user