kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.42k stars 110 forks source link

[Refactor] refactor lsp unit test #1374

Closed He1pa closed 1 month ago

He1pa commented 1 month ago

Enhancement

  1. split test file, each test function corresponds to a test code file
    - gotodef
    - case1
    - case1.k
    - case2
    - case2.k
    - ...
    - hover
    - ...
fn case1_test(){
}

fn case2_test(){
}
  1. use macros or help functions to remove duplicate test code
  2. use insta pkg instead of assert in test code

e.g. from

    #[test]
    #[bench_test]
    fn lambda_local_var_test() {
        let (file, _program, _, gs) = compile_test_file("src/test_data/goto_def_test/goto_def.k");

        let pos = KCLPos {
            filename: file.clone(),
            line: 96,
            column: Some(9),
        };

        let res = goto_def(&pos, &gs);
        compare_goto_res(res, (&file, 94, 11, 94, 12));
    }

to

    #[macro_export]
    macro_rules! goto_def_test_snapshot {
        ($name:ident, $file:expr, $line:expr, $column: expr) => {
            #[test]
            fn $name() {
                insta::assert_snapshot!(format!("{:?}", {
                    let (file, _program, _, gs) = compile_test_file($file);

                    let pos = KCLPos {
                        filename: file.clone(),
                        line: $line,
                        column: Some($column),
                    };
                    goto_def(&pos, &gs)
                }));
            }
        };
    }

    goto_def_test_snapshot!(
        lambda_local_var_test,
        "src/test_data/goto_def_test/goto_def.k",
        96,
        9
    );
Wck-iipi commented 1 month ago

@He1pa I would like to work on this issue