Maybe solve the none bug? (#860)

* Maybe solve the none bug?

* cargo fmt

* use nothing, not string

* check at last

* I check it at last

* Use error which has span

* use not found error

* fix error

* use a empty value length?

* * Add commit about what I change and fmt

Now all test passed, but I do not know if it is right

* update the test

* check if it is nothing

* update commit

* Rename test

Co-authored-by: Jakub Žádník <kubouch@gmail.com>
This commit is contained in:
Access 2022-01-30 21:23:28 +08:00 committed by GitHub
parent 060a4b3f48
commit 1fd0ddb52c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 19 deletions

View File

@ -632,24 +632,28 @@ impl Value {
}
Value::List { vals, span } => {
let mut output = vec![];
let mut hasvalue = false;
let mut temp: Result<Value, ShellError> = Err(ShellError::NotFound(*span));
for val in vals {
output.push(val.clone().follow_cell_path(&[PathMember::String {
temp = val.clone().follow_cell_path(&[PathMember::String {
val: column_name.clone(),
span: *origin_span,
}])?);
// if let Value::Record { cols, vals, .. } = val {
// for col in cols.iter().enumerate() {
// if col.1 == column_name {
// output.push(vals[col.0].clone());
// }
// }
// }
}]);
if let Ok(result) = temp.clone() {
hasvalue = true;
output.push(result);
} else {
output.push(Value::Nothing { span: *span });
}
}
if hasvalue {
current = Value::List {
vals: output,
span: *span,
};
} else {
return temp;
}
current = Value::List {
vals: output,
span: *span,
};
}
Value::CustomValue { val, .. } => {
current = val.follow_path_string(column_name.clone(), *origin_span)?;

View File

@ -1,4 +1,4 @@
use crate::tests::{fail_test, run_test, TestResult};
use crate::tests::{run_test, TestResult};
#[test]
fn cell_path_subexpr1() -> TestResult {
@ -153,10 +153,11 @@ fn update_cell_path_1() -> TestResult {
}
#[test]
fn missing_column_error() -> TestResult {
fail_test(
r#"([([[name, size]; [ABC, 10], [DEF, 20]]).1, ([[name]; [HIJ]]).0]).size | table"#,
"did you mean 'name'?",
fn missing_column_fills_in_nothing() -> TestResult {
// The empty value will be replaced with $nothing when fetching a column
run_test(
r#"[ { name: ABC, size: 20 }, { name: HIJ } ].size.1 == $nothing"#,
"true",
)
}