From 28fc827ebd99061677165465fc7ebf7dfae1f8bc Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 4 Jan 2024 21:48:12 +0800 Subject: [PATCH] chore: update chapi to 2.2.3 for fix testing annotation position issue --- gradle/libs.versions.toml | 2 +- .../unitmesh/pick/ext/CodeDataStructUtil.kt | 8 ++------ .../unittest/rust/RustTestCodeServiceTest.kt | 20 ++++++++++--------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 76cc632..9da607d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ clikt = "4.2.1" chocolate-factory = "0.4.5" -chapi = "2.2.2" +chapi = "2.2.3" archguard = "2.1.2" codedb = "0.1.3" diff --git a/unit-picker/src/main/kotlin/cc/unitmesh/pick/ext/CodeDataStructUtil.kt b/unit-picker/src/main/kotlin/cc/unitmesh/pick/ext/CodeDataStructUtil.kt index 8043ca1..c0826cf 100644 --- a/unit-picker/src/main/kotlin/cc/unitmesh/pick/ext/CodeDataStructUtil.kt +++ b/unit-picker/src/main/kotlin/cc/unitmesh/pick/ext/CodeDataStructUtil.kt @@ -14,12 +14,8 @@ fun CodeContainer.buildSourceCode(codeLines: List) { val position = it.Position if (it.Annotations.isNotEmpty()) { val annotationPos = it.Annotations.first().Position - if (annotationPos.StartLine != 0) { - position.StartLine = annotationPos.StartLine - position.StartLinePosition = annotationPos.StartLinePosition - } else { - position.StartLine -= 2 - } + position.StartLine = annotationPos.StartLine + position.StartLinePosition = annotationPos.StartLinePosition } it.Content = CodeDataStructUtil.contentByPosition(codeLines, it.Position) diff --git a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/unittest/rust/RustTestCodeServiceTest.kt b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/unittest/rust/RustTestCodeServiceTest.kt index 49ca948..320fdbd 100644 --- a/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/unittest/rust/RustTestCodeServiceTest.kt +++ b/unit-picker/src/test/kotlin/cc/unitmesh/pick/builder/unittest/rust/RustTestCodeServiceTest.kt @@ -44,7 +44,7 @@ class RustTestCodeServiceTest { assert_eq!(embedding.len(), 128); } } - """.trimIndent() + """.trimIndent() val container = RustAnalyser().analysis(testCode, "lib.rs") container.buildSourceCode(testCode.lines()) @@ -75,14 +75,16 @@ class RustTestCodeServiceTest { let result = Semantic::init_semantic(model, tokenizer_data)?; Ok(Arc::new(result)) }""", build[0].underTestCode) - assertEquals("fn test_init_semantic() {\n" + - " let model = std::fs::read(\"../model/model.onnx\").unwrap();\n" + - " let tokenizer_data = std::fs::read(\"../model/tokenizer.json\").unwrap();\n" + - "\n" + - " let semantic = init_semantic(model, tokenizer_data).unwrap();\n" + - " let embedding = semantic.embed(\"hello world\").unwrap();\n" + - " assert_eq!(embedding.len(), 128);\n" + - "}", build[0].generatedCode) + assertEquals("""#[test] + #[cfg_attr(feature = "ci", ignore)] + fn test_init_semantic() { + let model = std::fs::read("../model/model.onnx").unwrap(); + let tokenizer_data = std::fs::read("../model/tokenizer.json").unwrap(); + + let semantic = init_semantic(model, tokenizer_data).unwrap(); + let embedding = semantic.embed("hello world").unwrap(); + assert_eq!(embedding.len(), 128); +}""", build[0].generatedCode) } }