1
1
package chapi.ast.rustast
2
2
3
+ import kotlinx.serialization.encodeToString
4
+ import kotlinx.serialization.json.Json
3
5
import org.junit.jupiter.api.Test
4
6
import kotlin.test.assertEquals
5
7
@@ -229,7 +231,6 @@ class RustFullIdentListenerTest {
229
231
assertEquals(" p" , functionCalls[1 ].OriginNodeName )
230
232
}
231
233
232
- // self function call, like self.print();
233
234
@Test
234
235
fun should_identify_self_function_call () {
235
236
val code = """
@@ -250,4 +251,39 @@ class RustFullIdentListenerTest {
250
251
assertEquals(" clone" , functionCalls[1 ].FunctionName )
251
252
assertEquals(" id" , functionCalls[1 ].OriginNodeName )
252
253
}
254
+
255
+ @Test
256
+ fun should_handle_system_func () {
257
+ val code = """
258
+ use std::sync::Arc;
259
+
260
+ pub use embedding::Semantic;
261
+ pub use embedding::semantic::SemanticError;
262
+
263
+ pub fn init_semantic_with_path(model_path: &str, tokenizer_path: &str) -> Result<Arc<Semantic>, SemanticError> {
264
+ let model = std::fs::read(model_path).map_err(|_| SemanticError::InitModelReadError)?;
265
+ let tokenizer_data = std::fs::read(tokenizer_path).map_err(|_| SemanticError::InitTokenizerReadError)?;
266
+
267
+ let result = Semantic::init_semantic(model, tokenizer_data)?;
268
+ Ok(Arc::new(result))
269
+ }
270
+ """ .trimIndent()
271
+
272
+ val codeContainer = RustAnalyser ().analysis(code, " lib.rs" )
273
+ val codeDataStruct = codeContainer.DataStructures [0 ]
274
+ val functionCalls = codeDataStruct.Functions [0 ].FunctionCalls
275
+ assertEquals(7 , functionCalls.size)
276
+
277
+ functionCalls.map {
278
+ println (" ${it.NodeName } -> ${it.FunctionName } -> ${it.OriginNodeName } " )
279
+ }
280
+
281
+ assertEquals(" std::fs::read" , functionCalls[0 ].NodeName )
282
+ assertEquals(" map_err" , functionCalls[0 ].FunctionName )
283
+ assertEquals(" std::fs::read" , functionCalls[0 ].OriginNodeName )
284
+
285
+ assertEquals(" std::fs" , functionCalls[1 ].NodeName )
286
+ assertEquals(" read" , functionCalls[1 ].FunctionName )
287
+ assertEquals(" " , functionCalls[1 ].OriginNodeName )
288
+ }
253
289
}
0 commit comments