Repository: nushell/nushell
File: tests/const_/mod.rs (Rust)

Code before:
    assert_eq!(actual.out, "true");
}

#[test]
fn version_const() {
    let actual = nu!("const x = (version); $x");
    assert!(actual.err.is_empty());
}

#[test]
fn if_const() {
    let actual = nu!("const x = (if 2 < 3 { 'yes!' }); $x");
    assert_eq!(actual.out, "yes!");

    let actual = nu!("const x = (if 5 < 3 { 'yes!' } else { 'no!' }); $x");
    assert_eq!(actual.out, "no!");

    let actual =
        nu!("const x = (if 5 < 3 { 'yes!' } else if 4 < 5 { 'no!' } else { 'okay!' }); $x");
    assert_eq!(actual.out, "no!");
}

#[test]
fn const_glob_type() {
    let actual = nu!("const x: glob = 'aa'; $x | describe");
    assert_eq!(actual.out, "glob");
}

#[test]
fn const_raw_string() {
    let actual = nu!(r#"const x = r#'abcde""fghi"''''jkl'#; $x"#);
    assert_eq!(actual.out, r#"abcde""fghi"''''jkl"#);

    let actual = nu!(r#"const x = r##'abcde""fghi"''''#jkl'##; $x"#);
    assert_eq!(actual.out, r#"abcde""fghi"''''#jkl"#);

    let actual = nu!(r#"const x = r###'abcde""fghi"'''##'#jkl'###; $x"#);
    assert_eq!(actual.out, r#"abcde""fghi"'''##'#jkl"#);

    let actual = nu!(r#"const x = r#'abc'#; $x"#);
    assert_eq!(actual.out, "abc");
}

#[test]
fn const_takes_pipeline() {
    let actual = nu!(r#"const list = 'bar_baz_quux' | split row '_'; $list | length"#);
    assert_eq!(actual.out, "3");
}

#[test]
fn const_const() {

Review comment (suggestion):
No `nu::parser::type_mismatch` for `if true {1: 2}`, even with `Type::Block`.

Which means inconsistent parsing for records started by a number/string typed key.

<img width="523" height="380" alt="Image" src="https://github.com/user-attachments/assets/ef27f2c7-d959-4dab-bbff-50a6409728c7" />

Code after:
    assert_eq!(actual.out, "true");
}

#[test]
fn version_const() {
    let actual = nu!("const x = (version); $x");
    assert!(actual.err.is_empty());
}

#[test]
fn if_const() {
    let actual = nu!("const x = (if 2 < 3 { 'yes!' }); $x");
    assert_eq!(actual.out, "yes!");

    let actual = nu!("const x = (if 5 < 3 { 'yes!' } else { 'no!' }); $x");
    assert_eq!(actual.out, "no!");

    let actual =
        nu!("const x = (if 5 < 3 { 'yes!' } else if 4 < 5 { 'no!' } else { 'okay!' }); $x");
    assert_eq!(actual.out, "no!");
}

#[rstest]
#[case(&"const x = if true ()", "expected block, found nothing")]
#[case(&"const x = if true {foo: bar}", "expected block, found record")]
#[case(&"const x = if true {1: 2}", "expected block")]
fn if_const_error(#[case] inp: &str, #[case] expect: &str) {
    let actual = nu!(inp);
    assert!(actual.err.contains(expect));
}

#[test]
fn const_glob_type() {
    let actual = nu!("const x: glob = 'aa'; $x | describe");
    assert_eq!(actual.out, "glob");
}

#[test]
fn const_raw_string() {
    let actual = nu!(r#"const x = r#'abcde""fghi"''''jkl'#; $x"#);
    assert_eq!(actual.out, r#"abcde""fghi"''''jkl"#);

    let actual = nu!(r#"const x = r##'abcde""fghi"''''#jkl'##; $x"#);
    assert_eq!(actual.out, r#"abcde""fghi"''''#jkl"#);

    let actual = nu!(r#"const x = r###'abcde""fghi"'''##'#jkl'###; $x"#);
    assert_eq!(actual.out, r#"abcde""fghi"'''##'#jkl"#);

    let actual = nu!(r#"const x = r#'abc'#; $x"#);
    assert_eq!(actual.out, "abc");
}