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

@ -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);

View File

@ -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()))

View File

@ -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))),
}]

View File

@ -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))),
}]

View File

@ -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)),
}]

View File

@ -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")),
},

View File

@ -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

View File

@ -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 {

View File

@ -9,7 +9,7 @@ fn for_auto_print_in_each_iteration() {
echo 1
}"#
);
// Note: nu! macro auto repalce "\n" and "\r\n" with ""
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `11`
// that's ok, our main concern is it auto print value in each iteration.
assert_eq!(actual.out, "11");
@ -25,7 +25,7 @@ fn for_break_on_external_failed() {
nu --testbin fail
}"#
);
// Note: nu! macro auto repalce "\n" and "\r\n" with ""
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1`
assert_eq!(actual.out, "1");
}

View File

@ -15,7 +15,7 @@ fn loop_auto_print_in_each_iteration() {
echo 1
}"#
);
// Note: nu! macro auto repalce "\n" and "\r\n" with ""
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `111`
// that's ok, our main concern is it auto print value in each iteration.
assert_eq!(actual.out, "111");
@ -37,7 +37,7 @@ fn loop_break_on_external_failed() {
nu --testbin fail;
}"#
);
// Note: nu! macro auto repalce "\n" and "\r\n" with ""
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1`.
assert_eq!(actual.out, "1");
}

View File

@ -479,25 +479,25 @@ fn can_list_system_folder() {
cwd: "C:\\Windows\\System32", pipeline(
r#"ls Configuration* | where name == "Configuration" | get size.0"#
));
assert!(file_size.out.trim() != "");
assert_ne!(file_size.out.trim(), "");
let file_modified = nu!(
cwd: "C:\\Windows\\System32", pipeline(
r#"ls Configuration* | where name == "Configuration" | get modified.0"#
));
assert!(file_modified.out.trim() != "");
assert_ne!(file_modified.out.trim(), "");
let file_accessed = nu!(
cwd: "C:\\Windows\\System32", pipeline(
r#"ls -l Configuration* | where name == "Configuration" | get accessed.0"#
));
assert!(file_accessed.out.trim() != "");
assert_ne!(file_accessed.out.trim(), "");
let file_created = nu!(
cwd: "C:\\Windows\\System32", pipeline(
r#"ls -l Configuration* | where name == "Configuration" | get created.0"#
));
assert!(file_created.out.trim() != "");
assert_ne!(file_created.out.trim(), "");
let ls_with_filter = nu!(
cwd: "C:\\Windows\\System32", pipeline(

View File

@ -41,7 +41,7 @@ fn port_with_already_usage() {
return;
}
}
panic!("already check port report AddrInUse for seveval times, but still failed.");
panic!("already check port report AddrInUse for several times, but still failed.");
}
#[test]

View File

@ -34,7 +34,7 @@ mod simple {
}
#[test]
fn double_open_curly_evalutes_to_a_single_curly() {
fn double_open_curly_evaluates_to_a_single_curly() {
Playground::setup("parse_test_regex_2", |dirs, _sandbox| {
let actual = nu!(
cwd: dirs.test(), pipeline(

View File

@ -41,9 +41,9 @@ fn table_expand_0() {
);
}
// I am not sure whether the test is platform depent, cause we don't set a term_width on our own
// I am not sure whether the test is platform dependent, cause we don't set a term_width on our own
#[test]
fn table_expand_exeed_overlap_0() {
fn table_expand_exceed_overlap_0() {
// no expand
let actual = nu!(r#"[[a b, c]; [xxxxxxxxxxxxxxxxxxxxxx 2 3] [4 5 [1 2 3]]] | table --expand"#);

View File

@ -16,7 +16,7 @@ fn while_auto_print_in_each_iteration() {
cwd: ".",
"mut total = 0; while $total < 2 { $total = $total + 1; echo 1 }"
);
// Note: nu! macro auto repalce "\n" and "\r\n" with ""
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `11`
// that's ok, our main concern is it auto print value in each iteration.
assert_eq!(actual.out, "11");
@ -28,7 +28,7 @@ fn while_break_on_external_failed() {
cwd: ".",
"mut total = 0; while $total < 2 { $total = $total + 1; echo 1; nu --testbin fail }"
);
// Note: nu! macro auto repalce "\n" and "\r\n" with ""
// Note: nu! macro auto replace "\n" and "\r\n" with ""
// so our output will be `1`
assert_eq!(actual.out, "1");
}