use crate::tests::{fail_test, run_test, TestResult};

// TODO: Test the use/hide tests also as separate lines in REPL (i.e., with  merging the delta in between)
#[test]
fn hides_def() -> TestResult {
    fail_test(
        r#"def foo [] { "foo" }; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_env() -> TestResult {
    fail_test(r#"let-env foo = "foo"; hide foo; $env.foo"#, "did you mean")
}

#[test]
fn hides_def_then_redefines() -> TestResult {
    // this one should fail because of predecl -- cannot have more defs with the same name in a
    // block
    fail_test(
        r#"def foo [] { "foo" }; hide foo; def foo [] { "bar" }; foo"#,
        "defined more than once",
    )
}

#[test]
fn hides_alias_then_redefines() -> TestResult {
    run_test(
        r#"alias foo = echo "foo"; hide foo; alias foo = echo "foo"; foo"#,
        "foo",
    )
}

#[test]
fn hides_env_then_redefines() -> TestResult {
    run_test(
        r#"let-env foo = "foo"; hide foo; let-env foo = "bar"; $env.foo"#,
        "bar",
    )
}

#[test]
fn hides_def_in_scope_1() -> TestResult {
    fail_test(
        r#"def foo [] { "foo" }; do { hide foo; foo }"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_in_scope_2() -> TestResult {
    run_test(
        r#"def foo [] { "foo" }; do { def foo [] { "bar" }; hide foo; foo }"#,
        "foo",
    )
}

#[test]
fn hides_def_in_scope_3() -> TestResult {
    fail_test(
        r#"def foo [] { "foo" }; do { hide foo; def foo [] { "bar" }; hide foo; foo }"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_in_scope_4() -> TestResult {
    fail_test(
        r#"def foo [] { "foo" }; do { def foo [] { "bar" }; hide foo; hide foo; foo }"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_in_scope_1() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; do { hide foo; foo }"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_in_scope_2() -> TestResult {
    run_test(
        r#"alias foo = echo "foo"; do { alias foo = echo "bar"; hide foo; foo }"#,
        "foo",
    )
}

#[test]
fn hides_alias_in_scope_3() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; do { hide foo; alias foo = echo "bar"; hide foo; foo }"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_in_scope_4() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; do { alias foo = echo "bar"; hide foo; hide foo; foo }"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_env_in_scope_1() -> TestResult {
    fail_test(
        r#"let-env foo = "foo"; do { hide foo; $env.foo }"#,
        "did you mean",
    )
}

#[test]
fn hides_env_in_scope_2() -> TestResult {
    run_test(
        r#"let-env foo = "foo"; do { let-env foo = "bar"; hide foo; $env.foo }"#,
        "foo",
    )
}

#[test]
fn hides_env_in_scope_3() -> TestResult {
    fail_test(
        r#"let-env foo = "foo"; do { hide foo; let-env foo = "bar"; hide foo; $env.foo }"#,
        "did you mean",
    )
}

#[test]
fn hides_env_in_scope_4() -> TestResult {
    fail_test(
        r#"let-env foo = "foo"; do { let-env foo = "bar"; hide foo; hide foo; $env.foo }"#,
        "did you mean",
    )
}

#[test]
#[ignore]
fn hide_def_twice_not_allowed() -> TestResult {
    fail_test(
        r#"def foo [] { "foo" }; hide foo; hide foo"#,
        "did not find",
    )
}

#[test]
#[ignore]
fn hide_alias_twice_not_allowed() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; hide foo; hide foo"#,
        "did not find",
    )
}

#[test]
#[ignore]
fn hide_env_twice_not_allowed() -> TestResult {
    fail_test(r#"let-env foo = "foo"; hide foo; hide foo"#, "did not find")
}

#[test]
fn hides_def_runs_env_1() -> TestResult {
    run_test(
        r#"let-env foo = "bar"; def foo [] { "foo" }; hide foo; $env.foo"#,
        "bar",
    )
}

#[test]
fn hides_def_runs_env_2() -> TestResult {
    run_test(
        r#"def foo [] { "foo" }; let-env foo = "bar"; hide foo; $env.foo"#,
        "bar",
    )
}

#[test]
fn hides_alias_runs_def_1() -> TestResult {
    run_test(
        r#"def foo [] { "bar" }; alias foo = echo "foo"; hide foo; foo"#,
        "bar",
    )
}

#[test]
fn hides_alias_runs_def_2() -> TestResult {
    run_test(
        r#"alias foo = echo "foo"; def foo [] { "bar" }; hide foo; foo"#,
        "bar",
    )
}

#[test]
fn hides_alias_runs_env_1() -> TestResult {
    run_test(
        r#"let-env foo = "bar"; alias foo = echo "foo"; hide foo; $env.foo"#,
        "bar",
    )
}

#[test]
fn hides_alias_runs_env_2() -> TestResult {
    run_test(
        r#"alias foo = echo "foo"; let-env foo = "bar"; hide foo; $env.foo"#,
        "bar",
    )
}

#[test]
fn hides_def_and_env() -> TestResult {
    fail_test(
        r#"let-env foo = "bar"; def foo [] { "foo" }; hide foo; hide foo; $env.foo"#,
        "did you mean",
    )
}

#[test]
fn hides_alias_and_def() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; def foo [] { "bar" }; hide foo; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_def_and_env_1() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; def foo [] { "foo" }; let-env foo = "bar"; hide foo; hide foo; hide foo; $env.foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_def_and_env_2() -> TestResult {
    fail_test(
        r#"alias foo = echo "foo"; def foo [] { "foo" }; let-env foo = "bar"; hide foo; hide foo; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_1() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "foo" } }; use spam; hide spam foo; spam foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_2() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "foo" } }; use spam; hide spam; spam foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_3() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "foo" } }; use spam; hide spam [foo]; spam foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_4() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "foo" } }; use spam foo; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_5() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "foo" } }; use spam *; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_6() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "foo" } }; use spam *; hide spam *; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_def_import_then_reimports() -> TestResult {
    run_test(
        r#"module spam { export def foo [] { "foo" } }; use spam foo; hide foo; use spam foo; foo"#,
        "foo",
    )
}

#[test]
fn hides_alias_import_1() -> TestResult {
    fail_test(
        r#"module spam { export alias foo = "foo" }; use spam; hide spam foo; spam foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_import_2() -> TestResult {
    fail_test(
        r#"module spam { export alias foo = "foo" }; use spam; hide spam; spam foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_import_3() -> TestResult {
    fail_test(
        r#"module spam { export alias foo = "foo" }; use spam; hide spam [foo]; spam foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_import_4() -> TestResult {
    fail_test(
        r#"module spam { export alias foo = "foo" }; use spam foo; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_import_5() -> TestResult {
    fail_test(
        r#"module spam { export alias foo = "foo" }; use spam *; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_import_6() -> TestResult {
    fail_test(
        r#"module spam { export alias foo = "foo" }; use spam *; hide spam *; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_alias_import_then_reimports() -> TestResult {
    run_test(
        r#"module spam { export alias foo = "foo" }; use spam foo; hide foo; use spam foo; foo"#,
        "foo",
    )
}

#[test]
fn hides_env_import_1() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" } }; use spam; hide spam foo; $env.'spam foo'"#,
        "did you mean",
    )
}

#[test]
fn hides_env_import_2() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" } }; use spam; hide spam; $env.'spam foo'"#,
        "did you mean",
    )
}

#[test]
fn hides_env_import_3() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" } }; use spam; hide spam [foo]; $env.'spam foo'"#,
        "did you mean",
    )
}

#[test]
fn hides_env_import_4() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" } }; use spam foo; hide foo; $env.foo"#,
        "did you mean",
    )
}

#[test]
fn hides_env_import_5() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" } }; use spam *; hide foo; $env.foo"#,
        "did you mean",
    )
}

#[test]
fn hides_env_import_6() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" } }; use spam *; hide spam *; $env.foo"#,
        "did you mean",
    )
}

#[test]
fn hides_def_runs_env_import() -> TestResult {
    run_test(
        r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; hide foo; $env.foo"#,
        "foo",
    )
}

#[test]
fn hides_def_and_env_import_1() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; hide foo; hide foo; $env.foo"#,
        "did you mean",
    )
}

#[test]
fn hides_def_and_env_import_2() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "foo" }; export def foo [] { "bar" } }; use spam foo; hide foo; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn use_def_import_after_hide() -> TestResult {
    run_test(
        r#"module spam { export def foo [] { "foo" } }; use spam foo; hide foo; use spam foo; foo"#,
        "foo",
    )
}

#[test]
fn use_env_import_after_hide() -> TestResult {
    run_test(
        r#"module spam { export env foo { "foo" } }; use spam foo; hide foo; use spam foo; $env.foo"#,
        "foo",
    )
}

#[test]
fn hide_shadowed_decl() -> TestResult {
    run_test(
        r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; do { use spam foo; hide foo; foo }"#,
        "foo",
    )
}

#[test]
fn hide_shadowed_env() -> TestResult {
    run_test(
        r#"module spam { export env foo { "bar" } }; let-env foo = "foo"; do { use spam foo; hide foo; $env.foo }"#,
        "foo",
    )
}

#[test]
fn hides_all_decls_within_scope() -> TestResult {
    fail_test(
        r#"module spam { export def foo [] { "bar" } }; def foo [] { "foo" }; use spam foo; hide foo; foo"#,
        "", // we just care if it errors
    )
}

#[test]
fn hides_all_envs_within_scope() -> TestResult {
    fail_test(
        r#"module spam { export env foo { "bar" } }; let-env foo = "foo"; use spam foo; hide foo; $env.foo"#,
        "did you mean",
    )
}
