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:
Stefan Holderbach
2023-10-28 14:52:31 +02:00
committed by GitHub
parent 7d67ca3652
commit 4b301710d3
99 changed files with 1592 additions and 2540 deletions

View File

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

View File

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

View File

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

View File

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