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

@ -455,6 +455,8 @@ pub fn convert_sqlite_value_to_nu_value(value: ValueRef, span: Span) -> Value {
#[cfg(test)]
mod test {
use nu_protocol::record;
use super::*;
#[test]
@ -482,9 +484,8 @@ mod test {
.unwrap();
let converted_db = read_entire_sqlite_db(db, Span::test_data(), None).unwrap();
let expected = Value::test_record(Record {
cols: vec!["person".to_string()],
vals: vec![Value::list(vec![], Span::test_data())],
let expected = Value::test_record(record! {
"person" => Value::test_list(vec![]),
});
assert_eq!(converted_db, expected);
@ -512,24 +513,19 @@ mod test {
let converted_db = read_entire_sqlite_db(db, span, None).unwrap();
let expected = Value::test_record(Record {
cols: vec!["item".to_string()],
vals: vec![Value::list(
let expected = Value::test_record(record! {
"item" => Value::test_list(
vec![
Value::test_record(Record {
cols: vec!["id".to_string(), "name".to_string()],
vals: vec![Value::int(123, span), Value::nothing(span)],
Value::test_record(record! {
"id" => Value::test_int(123),
"name" => Value::nothing(span),
}),
Value::test_record(Record {
cols: vec!["id".to_string(), "name".to_string()],
vals: vec![
Value::int(456, span),
Value::string("foo bar".to_string(), span),
],
Value::test_record(record! {
"id" => Value::test_int(456),
"name" => Value::test_string("foo bar"),
}),
],
span,
)],
]
),
});
assert_eq!(converted_db, expected);