mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 20:07:42 +02:00
Construct Record
s only through checked helpers (#11386)
# Description Constructing the internals of `Record` without checking the lengths is bad. (also incompatible with changes to how we store records) - Use `Record::from_raw_cols_vals` in dataframe code - Use `record!` macro in dataframe test - Use `record!` in `nu-color-config` tests - Stop direct record construction in `nu-command` - Refactor table construction in `from nuon` # User-Facing Changes None # Tests + Formatting No new tests, updated tests in equal fashion
This commit is contained in:
committed by
GitHub
parent
6f384da57e
commit
8cfa96b4c0
@ -92,7 +92,7 @@ fn color_string_to_nustyle(color_string: String) -> Style {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use nu_ansi_term::{Color, Style};
|
||||
use nu_protocol::{Span, Value};
|
||||
use nu_protocol::{record, Span, Value};
|
||||
|
||||
#[test]
|
||||
fn test_color_string_to_nustyle_empty_string() {
|
||||
@ -120,13 +120,10 @@ mod tests {
|
||||
#[test]
|
||||
fn test_get_style_from_value() {
|
||||
// Test case 1: all values are valid
|
||||
let record = Record {
|
||||
cols: vec!["bg".to_string(), "fg".to_string(), "attr".to_string()],
|
||||
vals: vec![
|
||||
Value::string("red", Span::unknown()),
|
||||
Value::string("blue", Span::unknown()),
|
||||
Value::string("bold", Span::unknown()),
|
||||
],
|
||||
let record = record! {
|
||||
"bg" => Value::test_string("red"),
|
||||
"fg" => Value::test_string("blue"),
|
||||
"attr" => Value::test_string("bold"),
|
||||
};
|
||||
let expected_style = NuStyle {
|
||||
bg: Some("red".to_string()),
|
||||
@ -136,19 +133,15 @@ mod tests {
|
||||
assert_eq!(get_style_from_value(&record), Some(expected_style));
|
||||
|
||||
// Test case 2: no values are valid
|
||||
let record = Record {
|
||||
cols: vec!["invalid".to_string()],
|
||||
vals: vec![Value::nothing(Span::unknown())],
|
||||
let record = record! {
|
||||
"invalid" => Value::nothing(Span::test_data()),
|
||||
};
|
||||
assert_eq!(get_style_from_value(&record), None);
|
||||
|
||||
// Test case 3: some values are valid
|
||||
let record = Record {
|
||||
cols: vec!["bg".to_string(), "invalid".to_string()],
|
||||
vals: vec![
|
||||
Value::string("green", Span::unknown()),
|
||||
Value::nothing(Span::unknown()),
|
||||
],
|
||||
let record = record! {
|
||||
"bg" => Value::test_string("green"),
|
||||
"invalid" => Value::nothing(Span::unknown()),
|
||||
};
|
||||
let expected_style = NuStyle {
|
||||
bg: Some("green".to_string()),
|
||||
|
Reference in New Issue
Block a user