mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 15:44:59 +02:00
Move Value to helpers, separate span call (#10121)
# Description As part of the refactor to split spans off of Value, this moves to using helper functions to create values, and using `.span()` instead of matching span out of Value directly. Hoping to get a few more helping hands to finish this, as there are a lot of commands to update :) # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. --> --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> Co-authored-by: WindSoilder <windsoilder@outlook.com>
This commit is contained in:
@ -79,7 +79,7 @@ fn convert_gjson_value_to_nu_value(v: &gjValue, span: Span) -> Value {
|
||||
true
|
||||
});
|
||||
|
||||
Value::List { vals, span }
|
||||
Value::list(vals, span)
|
||||
}
|
||||
gjson::Kind::Null => Value::nothing(span),
|
||||
gjson::Kind::False => Value::bool(false, span),
|
||||
|
@ -59,12 +59,13 @@ pub fn parse_selector_params(call: &EvaluatedCall, input: &Value) -> Result<Valu
|
||||
inspect,
|
||||
};
|
||||
|
||||
let span = input.span();
|
||||
match input {
|
||||
Value::String { val, span } => Ok(begin_selector_query(val.to_string(), selector, *span)),
|
||||
Value::String { val, .. } => Ok(begin_selector_query(val.to_string(), selector, span)),
|
||||
_ => Err(LabeledError {
|
||||
label: "requires text input".to_string(),
|
||||
msg: "Expected text from pipeline".to_string(),
|
||||
span: Some(input.span()),
|
||||
span: Some(span),
|
||||
}),
|
||||
}
|
||||
}
|
||||
@ -140,7 +141,7 @@ pub fn retrieve_tables(
|
||||
.map(move |table| retrieve_table(table, columns, span))
|
||||
.collect();
|
||||
|
||||
Value::List { vals, span }
|
||||
Value::list(vals, span)
|
||||
}
|
||||
|
||||
fn retrieve_table(mut table: WebTable, columns: &Value, span: Span) -> Value {
|
||||
@ -211,10 +212,7 @@ fn retrieve_table(mut table: WebTable, columns: &Value, span: Span) -> Value {
|
||||
}
|
||||
// table_out
|
||||
|
||||
Value::List {
|
||||
vals: table_out,
|
||||
span,
|
||||
}
|
||||
Value::list(table_out, span)
|
||||
}
|
||||
|
||||
fn execute_selector_query_with_attribute(
|
||||
@ -235,7 +233,7 @@ fn execute_selector_query_with_attribute(
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
Value::List { vals, span }
|
||||
Value::list(vals, span)
|
||||
}
|
||||
|
||||
fn execute_selector_query(
|
||||
@ -265,7 +263,7 @@ fn execute_selector_query(
|
||||
.collect(),
|
||||
};
|
||||
|
||||
Value::List { vals, span }
|
||||
Value::list(vals, span)
|
||||
}
|
||||
|
||||
pub fn css(selector: &str, inspect: bool) -> ScraperSelector {
|
||||
|
@ -79,10 +79,7 @@ pub fn execute_xpath_query(
|
||||
records.push(Value::record(record! { k => v }, call.head))
|
||||
}
|
||||
|
||||
Ok(Value::List {
|
||||
vals: records,
|
||||
span: call.head,
|
||||
})
|
||||
Ok(Value::list(records, call.head))
|
||||
}
|
||||
Err(_) => Err(LabeledError {
|
||||
label: "xpath query error".to_string(),
|
||||
@ -135,13 +132,13 @@ mod tests {
|
||||
};
|
||||
|
||||
let actual = query("", &call, &text, Some(spanned_str)).expect("test should not fail");
|
||||
let expected = Value::List {
|
||||
vals: vec![Value::test_record(Record {
|
||||
let expected = Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["count(//a/*[posit...".to_string()],
|
||||
vals: vec![Value::test_float(1.0)],
|
||||
})],
|
||||
span: Span::test_data(),
|
||||
};
|
||||
Span::test_data(),
|
||||
);
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
@ -165,13 +162,13 @@ mod tests {
|
||||
};
|
||||
|
||||
let actual = query("", &call, &text, Some(spanned_str)).expect("test should not fail");
|
||||
let expected = Value::List {
|
||||
vals: vec![Value::test_record(Record {
|
||||
let expected = Value::list(
|
||||
vec![Value::test_record(Record {
|
||||
cols: vec!["count(//*[contain...".to_string()],
|
||||
vals: vec![Value::test_float(1.0)],
|
||||
})],
|
||||
span: Span::test_data(),
|
||||
};
|
||||
Span::test_data(),
|
||||
);
|
||||
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
Reference in New Issue
Block a user