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 } => { Value::List { vals, span } => {
let mut output = vec![]; let mut output = vec![];
let mut hasvalue = false;
let mut temp: Result<Value, ShellError> = Err(ShellError::NotFound(*span));
for val in vals { 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(), val: column_name.clone(),
span: *origin_span, span: *origin_span,
}])?); }]);
// if let Value::Record { cols, vals, .. } = val { if let Ok(result) = temp.clone() {
// for col in cols.iter().enumerate() { hasvalue = true;
// if col.1 == column_name { output.push(result);
// output.push(vals[col.0].clone()); } 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, .. } => { Value::CustomValue { val, .. } => {
current = val.follow_path_string(column_name.clone(), *origin_span)?; 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] #[test]
fn cell_path_subexpr1() -> TestResult { fn cell_path_subexpr1() -> TestResult {
@ -153,10 +153,11 @@ fn update_cell_path_1() -> TestResult {
} }
#[test] #[test]
fn missing_column_error() -> TestResult { fn missing_column_fills_in_nothing() -> TestResult {
fail_test( // The empty value will be replaced with $nothing when fetching a column
r#"([([[name, size]; [ABC, 10], [DEF, 20]]).1, ([[name]; [HIJ]]).0]).size | table"#, run_test(
"did you mean 'name'?", r#"[ { name: ABC, size: 20 }, { name: HIJ } ].size.1 == $nothing"#,
"true",
) )
} }