diff --git a/crates/nu-command/tests/commands/select.rs b/crates/nu-command/tests/commands/select.rs index 004aa16d6b..f47845d6ed 100644 --- a/crates/nu-command/tests/commands/select.rs +++ b/crates/nu-command/tests/commands/select.rs @@ -166,7 +166,7 @@ fn select_ignores_errors_successfully1() { fn select_ignores_errors_successfully2() { let actual = nu!("[{a: 1} {a: 2} {a: 3}] | select b? | to nuon"); - assert_eq!(actual.out, "[[b]; [null], [null], [null]]".to_string()); + assert_eq!(actual.out, "[[b?]; [null], [null], [null]]".to_string()); assert!(actual.err.is_empty()); } @@ -174,7 +174,7 @@ fn select_ignores_errors_successfully2() { fn select_ignores_errors_successfully3() { let actual = nu!("{foo: bar} | select invalid_key? | to nuon"); - assert_eq!(actual.out, "{invalid_key: null}".to_string()); + assert_eq!(actual.out, "{invalid_key?: null}".to_string()); assert!(actual.err.is_empty()); } @@ -184,7 +184,10 @@ fn select_ignores_errors_successfully4() { r#""key val\na 1\nb 2\n" | lines | split column --collapse-empty " " | select foo? | to nuon"# ); - assert_eq!(actual.out, r#"[[foo]; [null], [null], [null]]"#.to_string()); + assert_eq!( + actual.out, + r#"[[foo?]; [null], [null], [null]]"#.to_string() + ); assert!(actual.err.is_empty()); } @@ -234,7 +237,7 @@ fn ignore_errors_works() { [{}] | select -i $path | to nuon "#); - assert_eq!(actual.out, "[[foo]; [null]]"); + assert_eq!(actual.out, "[[foo?]; [null]]"); } #[test] diff --git a/crates/nu-protocol/src/ast/cell_path.rs b/crates/nu-protocol/src/ast/cell_path.rs index 0880537557..f208dd8120 100644 --- a/crates/nu-protocol/src/ast/cell_path.rs +++ b/crates/nu-protocol/src/ast/cell_path.rs @@ -182,8 +182,14 @@ impl Display for CellPath { write!(f, ".")?; } match elem { - PathMember::Int { val, .. } => write!(f, "{val}")?, - PathMember::String { val, .. } => write!(f, "{val}")?, + PathMember::Int { val, optional, .. } => { + let question_mark = if *optional { "?" } else { "" }; + write!(f, "{val}{question_mark}")? + } + PathMember::String { val, optional, .. } => { + let question_mark = if *optional { "?" } else { "" }; + write!(f, "{val}{question_mark}")? + } } } Ok(())