mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:34:58 +02:00
Convert more examples and tests to record!
macro (#10840)
# Description Use `record!` macro instead of defining two separate `vec!` for `cols` and `vals` when appropriate. This visually aligns the key with the value. Further more you don't have to deal with the construction of `Record { cols, vals }` so we can hide the implementation details in the future. ## State Not covering all possible commands yet, also some tests/examples are better expressed by creating cols and vals separately. # User/Developer-Facing Changes The examples and tests should read more natural. No relevant functional change # Bycatch Where I noticed it I replaced usage of `Value` constructors with `Span::test_data()` or `Span::unknown()` to the `Value::test_...` constructors. This should make things more readable and also simplify changes to the `Span` system in the future.
This commit is contained in:
committed by
GitHub
parent
7d67ca3652
commit
4b301710d3
@ -3,7 +3,7 @@ use crate::math::utils::run_with_function;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, Span, Type, Value,
|
||||
record, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -52,9 +52,9 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Find the maxima of the columns of a table",
|
||||
example: "[{a: 1 b: 3} {a: 2 b: -1}] | math max",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["a".to_string(), "b".to_string()],
|
||||
vals: vec![Value::test_int(2), Value::test_int(3)],
|
||||
result: Some(Value::test_record(record! {
|
||||
"a" => Value::test_int(2),
|
||||
"b" => Value::test_int(3),
|
||||
})),
|
||||
},
|
||||
]
|
||||
|
@ -5,7 +5,7 @@ use crate::math::utils::run_with_function;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, Span, Type, Value,
|
||||
record, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -56,9 +56,9 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Compute the medians of the columns of a table",
|
||||
example: "[{a: 1 b: 3} {a: 2 b: -1} {a: -3 b: 5}] | math median",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["a".to_string(), "b".to_string()],
|
||||
vals: vec![Value::test_int(1), Value::test_int(3)],
|
||||
result: Some(Value::test_record(record! {
|
||||
"a" => Value::test_int(1),
|
||||
"b" => Value::test_int(3),
|
||||
})),
|
||||
},
|
||||
]
|
||||
|
@ -3,7 +3,7 @@ use crate::math::utils::run_with_function;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, Span, Type, Value,
|
||||
record, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -52,9 +52,9 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Compute the minima of the columns of a table",
|
||||
example: "[{a: 1 b: 3} {a: 2 b: -1}] | math min",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["a".to_string(), "b".to_string()],
|
||||
vals: vec![Value::test_int(1), Value::test_int(-1)],
|
||||
result: Some(Value::test_record(record! {
|
||||
"a" => Value::test_int(1),
|
||||
"b" => Value::test_int(-1),
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
|
@ -2,7 +2,7 @@ use crate::math::utils::run_with_function;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, Example, PipelineData, Record, ShellError, Signature, Span, Type, Value,
|
||||
record, Category, Example, PipelineData, ShellError, Signature, Span, Type, Value,
|
||||
};
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
@ -82,23 +82,20 @@ impl Command for SubCommand {
|
||||
Example {
|
||||
description: "Compute the mode(s) of a list of numbers",
|
||||
example: "[3 3 9 12 12 15] | math mode",
|
||||
result: Some(Value::list(
|
||||
vec![Value::test_int(3), Value::test_int(12)],
|
||||
Span::test_data(),
|
||||
)),
|
||||
result: Some(Value::test_list(vec![
|
||||
Value::test_int(3),
|
||||
Value::test_int(12),
|
||||
])),
|
||||
},
|
||||
Example {
|
||||
description: "Compute the mode(s) of the columns of a table",
|
||||
example: "[{a: 1 b: 3} {a: 2 b: -1} {a: 1 b: 5}] | math mode",
|
||||
result: Some(Value::test_record(Record {
|
||||
cols: vec!["a".to_string(), "b".to_string()],
|
||||
vals: vec![
|
||||
Value::list(vec![Value::test_int(1)], Span::test_data()),
|
||||
Value::list(
|
||||
result: Some(Value::test_record(record! {
|
||||
"a" => Value::list(vec![Value::test_int(1)], Span::test_data()),
|
||||
"b" => Value::list(
|
||||
vec![Value::test_int(-1), Value::test_int(3), Value::test_int(5)],
|
||||
Span::test_data(),
|
||||
),
|
||||
],
|
||||
})),
|
||||
},
|
||||
]
|
||||
|
Reference in New Issue
Block a user