Repository: nushell/nushell
File: tests/repl/test_parser.rs (Rust)

Code before:

#[test]
fn filesize_is_not_hex() -> TestResult {
    run_test("0x42b", "1067")
}

#[test]
fn let_variable_type_mismatch() -> TestResult {
    fail_test(r#"let x: int = "foo""#, "expected int, found string")
}

#[test]
fn let_variable_table_runtime_cast() -> TestResult {
    // Type::Any should be accepted by compatible types (record can convert to table)
    run_test(
        r#"let x: table = ([[a]; [1]] | to nuon | from nuon); $x | describe"#,
        "table<a: int>",
    )
}

#[test]
fn let_variable_table_runtime_mismatch() -> TestResult {
    // This conversion should fail due to a key mismatch
    fail_test(
        r#"let x: table<b: int> = ([[a]; [1]]  | to nuon | from nuon); $x | describe"#,
        "can't convert table<a: int> to table<b: int>",
    )
}

#[test]
fn mut_variable_table_runtime_mismatch() -> TestResult {
    fail_test(
        r#"mut x: table<b: int> = ([[b]; [1]]  | to nuon | from nuon); $x = [[a]; [1]]"#,
        "can't convert table<a: int> to table<b: int>",
    )
}

#[test]
fn let_variable_record_runtime_cast() -> TestResult {
    // Records from Type::Any sources should be convertible to tables when field types match
    run_test(
        r#"let x: record<a: int> = ({a: 1} | to nuon | from nuon); $x | describe"#,
        "record<a: int>",
    )
}

#[test]
fn let_variable_record_runtime_mismatch() -> TestResult {
    // This conversion should fail due to a key mismatch
    fail_test(
        r#"let x: record<b: int> = ({a: 1} | to nuon | from nuon); $x | describe"#,

Review comment (bug):
There should probably be a record to table failure here
```suggestion
        r#"let x: table<a: int> = ({a : 1}  | to nuon | from nuon); $x | describe"#,
        "can't convert record<a: int> to table<a: int>",
```

Code after:

#[test]
fn filesize_with_underscores_2() -> TestResult {
    run_test("1_000_000B", "1.0 MB")
}

#[test]
fn filesize_with_underscores_3() -> TestResult {
    fail_test("42m_b", "Command `42m_b` not found")
}

#[test]
fn filesize_is_not_hex() -> TestResult {
    run_test("0x42b", "1067")
}

#[test]
fn let_variable_type_mismatch() -> TestResult {
    fail_test(r#"let x: int = "foo""#, "expected int, found string")
}

#[test]
fn let_variable_table_runtime_cast() -> TestResult {
    let outcome = nu!(
        experimental: vec!["enforce-runtime-annotations".to_string()],
        r#"let x: table = ([[a]; [1]] | to nuon | from nuon); $x | describe"#,
    );

    // Type::Any should be accepted by compatible types (record can convert to table)
    assert!(outcome.out.contains("table<a: int>"));
    Ok(())
}

#[test]
fn let_variable_table_runtime_mismatch() -> TestResult {
    let outcome = nu!(
        experimental: vec!["enforce-runtime-annotations".to_string()],
        r#"mut x: table<b: int> = ([[b]; [1]]  | to nuon | from nuon); $x = [[a]; [1]]"#,
    );

    // This conversion should fail due to a key mismatch
    assert!(
        outcome
            .err
            .contains("does not operate between 'table<b: int>' and 'table<a: int>'")
    );
    Ok(())
}

#[test]
fn mut_variable_table_runtime_mismatch() -> TestResult {