mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
Allow complex types in input/output and let (#10405)
# Description This PR fixes #9702 on the side of parse. I.e. input/output types in signature and type annotations in `let` now should correctly parse with type annotations that contain commas and spaces:  # User-Facing Changes Return values and let type annotations now can contain stuff like `table<a: int b: record<c: string d: datetime>>` e.t.c
This commit is contained in:
@ -2,6 +2,7 @@ use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use pretty_assertions::assert_eq;
|
||||
use rstest::rstest;
|
||||
|
||||
#[test]
|
||||
fn source_file_relative_to_file() {
|
||||
@ -244,3 +245,29 @@ fn parse_long_duration() {
|
||||
|
||||
assert_eq!(actual.out, "1min 18sec 797ms");
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("def test []: int -> int { 1 }")]
|
||||
#[case("def test []: string -> string { 'qwe' }")]
|
||||
#[case("def test []: nothing -> nothing { null }")]
|
||||
#[case("def test []: list<string> -> list<string> { [] }")]
|
||||
#[case("def test []: record<a: int b: int> -> record<c: int e: int> { {c: 1 e: 1} }")]
|
||||
#[case("def test []: table<a: int b: int> -> table<c: int e: int> { [ {c: 1 e: 1} ] }")]
|
||||
#[case("def test []: nothing -> record<c: int e: int> { {c: 1 e: 1} }")]
|
||||
fn parse_function_signature(#[case] phrase: &str) {
|
||||
let actual = nu!(phrase);
|
||||
assert!(actual.err.is_empty());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case("let a: int = 1")]
|
||||
#[case("let a: string = 'qwe'")]
|
||||
#[case("let a: nothing = null")]
|
||||
#[case("let a: list<string> = []")]
|
||||
#[case("let a: record<a: int b: int> = {a: 1 b: 1}")]
|
||||
#[case("let a: table<a: int b: int> = [[a b]; [1 2] [3 4]]")]
|
||||
#[case("let a: record<a: record<name: string> b: int> = {a: {name: bob} b: 1}")]
|
||||
fn parse_let_signature(#[case] phrase: &str) {
|
||||
let actual = nu!(phrase);
|
||||
assert!(actual.err.is_empty());
|
||||
}
|
||||
|
Reference in New Issue
Block a user