11import * as assert from 'assert' ;
22import * as vscode from 'vscode' ;
33import { applyGlobalReplace , normalizeInput } from '../cvbManager' ;
4+ import { normalizeContent , removeComments , normalizeWhitespace , normalizePattern , removeSymbolSpaces } from '../fuzzyMatch' ;
45
56// 定义 GlobalReplaceOperation 接口
67
@@ -34,7 +35,7 @@ function normalizeData(operation: GlobalReplaceOperation): GlobalReplaceOperatio
3435 operation . m_strNewContent = normalizeInput ( operation . m_strNewContent ) ;
3536 return operation ;
3637}
37-
38+
3839suite ( 'Extension Test Suite' , ( ) => {
3940 vscode . window . showInformationMessage ( 'Start all tests.' ) ;
4041
@@ -261,4 +262,153 @@ function empty() {}
261262 applyGlobalReplace ( content , normalizeData ( op ) ) ;
262263 } , / G L O B A L - R E P L A C E 失 败 : F I L E : " t e s t .j s " O L D _ C O N T E N T 是 空 的 / ) ;
263264 } ) ;
264- } ) ;
265+ } ) ;
266+
267+ suite ( 'Normalization Full Coverage Test Suite' , ( ) =>
268+ {
269+ // 1. 测试 removeComments:多行混合注释的情况
270+ test ( 'removeComments - 多行代码包含注释' , ( ) =>
271+ {
272+ const strInput : string = `function test() { // 这是一个函数
273+ let nValue = 10; // 这里初始化变量
274+ // 这是一整行注释
275+ return nValue; // 返回变量
276+ } // 结束函数
277+ ` ;
278+
279+ const stResult = removeComments ( strInput ) ;
280+ const strContent : string = stResult . content ;
281+ const arrMapping : number [ ] = stResult . mapping ;
282+
283+ const strExpectedContent : string =
284+ "function test() { \n" +
285+ " let nValue = 10; \n" +
286+ " \n" +
287+ " return nValue; \n" +
288+ "} \n" ;
289+
290+ assert . strictEqual ( strContent , strExpectedContent , "removeComments 多行内容不正确" ) ;
291+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "removeComments 多行 mapping 长度不正确" ) ;
292+ } ) ;
293+
294+ // 2. 测试 removeSymbolSpaces:符号前后空格
295+ test ( 'removeSymbolSpaces - 符号前后带空格' , ( ) =>
296+ {
297+ const strInput : string = `a + b
298+ ( x - y )
299+ { c * d }` ;
300+ const stResult = removeSymbolSpaces ( strInput ) ;
301+ const strContent : string = stResult . content ;
302+ const arrMapping : number [ ] = stResult . mapping ;
303+
304+ const strExpectedContent : string =
305+ "a+b\n" +
306+ "(x-y)\n" +
307+ "{c*d}" ;
308+
309+ assert . strictEqual ( strContent , strExpectedContent , "removeSymbolSpaces 符号空格去除不正确" ) ;
310+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "removeSymbolSpaces mapping 长度不正确" ) ;
311+ } ) ;
312+
313+ // 3. 测试 normalizeWhitespace:空白字符处理
314+ test ( 'normalizeWhitespace - 处理换行符、tab 和连续空格' , ( ) =>
315+ {
316+ const strInput : string = `abc def
317+ ghi\t\tjkl
318+ mno pqr` ;
319+ const stResult = normalizeWhitespace ( strInput ) ;
320+ const strContent : string = stResult . content ;
321+ const arrMapping : number [ ] = stResult . mapping ;
322+
323+ const strExpectedContent : string = "abc def\nghi jkl\nmno pqr" ;
324+
325+ assert . strictEqual ( strContent , strExpectedContent , "normalizeWhitespace 处理空白字符错误" ) ;
326+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "normalizeWhitespace mapping 长度错误" ) ;
327+ } ) ;
328+
329+ // 4. 测试 removeComments 对全是注释的代码
330+ test ( 'removeComments - 代码全是注释' , ( ) =>
331+ {
332+ const strInput : string = `// 这是注释
333+ // 这也是注释
334+ // 还有注释
335+ ` ;
336+
337+ const stResult = removeComments ( strInput ) ;
338+ const strContent : string = stResult . content ;
339+ const arrMapping : number [ ] = stResult . mapping ;
340+
341+ const strExpectedContent : string = "\n\n\n" ;
342+
343+ assert . strictEqual ( strContent , strExpectedContent , "removeComments 全注释去除不正确" ) ;
344+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "removeComments 全注释 mapping 错误" ) ;
345+ } ) ;
346+
347+ // 5. 测试 normalizeWhitespace 处理连续换行
348+ test ( 'normalizeWhitespace - 处理连续换行' , ( ) =>
349+ {
350+ const strInput : string = `abc
351+
352+
353+ def` ;
354+ const stResult = normalizeWhitespace ( strInput ) ;
355+ const strContent : string = stResult . content ;
356+ const arrMapping : number [ ] = stResult . mapping ;
357+
358+ const strExpectedContent : string = "abc\ndef" ;
359+
360+ assert . strictEqual ( strContent , strExpectedContent , "normalizeWhitespace 处理连续换行错误" ) ;
361+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "normalizeWhitespace mapping 长度错误" ) ;
362+ } ) ;
363+
364+ // 6. 测试 removeSymbolSpaces 处理特殊符号混合情况
365+ test ( 'removeSymbolSpaces - 复杂符号空格情况' , ( ) =>
366+ {
367+ const strInput : string = `a + ( b * c ) / [ d - e ]` ;
368+ const stResult = removeSymbolSpaces ( strInput ) ;
369+ const strContent : string = stResult . content ;
370+ const arrMapping : number [ ] = stResult . mapping ;
371+
372+ const strExpectedContent : string = "a+(b*c)/[d-e]" ;
373+
374+ assert . strictEqual ( strContent , strExpectedContent , "removeSymbolSpaces 复杂符号空格处理错误" ) ;
375+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "removeSymbolSpaces mapping 长度错误" ) ;
376+ } ) ;
377+
378+ // 7. 测试 normalizeWhitespace 处理只有空格和换行符的输入
379+ test ( 'normalizeWhitespace - 只有空格和换行符' , ( ) =>
380+ {
381+ const strInput : string = " \n \n " ;
382+ const stResult = normalizeWhitespace ( strInput ) ;
383+ const strContent : string = stResult . content ;
384+ const arrMapping : number [ ] = stResult . mapping ;
385+
386+ const strExpectedContent : string = "\n" ;
387+
388+ assert . strictEqual ( strContent , strExpectedContent , "normalizeWhitespace 纯空格处理错误" ) ;
389+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "normalizeWhitespace mapping 长度错误" ) ;
390+ } ) ;
391+
392+ // 8. 综合测试 normalizeContent
393+ test ( 'normalizeContent - 复杂综合测试' , ( ) =>
394+ {
395+ const strInput : string = `function test() { // 这是注释
396+ let a = 5 + 6 ; // 多个空格
397+ let b = a * 2; // 还有注释
398+ return b;
399+ }` ;
400+ const stResult = normalizeContent ( strInput ) ;
401+ const strContent : string = stResult . content ;
402+ const arrMapping : number [ ] = stResult . mapping ;
403+
404+ const strExpectedContent : string =
405+ "function test(){\n" +
406+ "let a=5+6;\n" +
407+ "let b=a*2;\n" +
408+ "return b;\n" +
409+ "}" ;
410+
411+ assert . strictEqual ( strContent , strExpectedContent , "normalizeContent 复杂测试错误" ) ;
412+ assert . strictEqual ( arrMapping . length , strExpectedContent . length , "normalizeContent mapping 长度错误" ) ;
413+ } ) ;
414+ } ) ;
0 commit comments