@@ -11,6 +11,7 @@ import { GoMetricsAnalyzer } from "../metricsAnalyzer/languages/goAnalyzer";
1111import {
1212 MetricsAnalyzerFactory ,
1313 UnifiedFunctionMetrics ,
14+ UnifiedMetricsDetail ,
1415} from "../metricsAnalyzer/metricsAnalyzerFactory" ;
1516import { SampleCSharpCode } from "../test/testUtils" ;
1617
@@ -123,11 +124,11 @@ func Method() {
123124 assert . strictEqual ( results . length , 1 ) ;
124125 assert . ok ( results [ 0 ] . complexity > 0 ) ;
125126
126- const forLoop = results [ 0 ] . details . find ( ( d : any ) =>
127- d . reason . includes ( "for" )
127+ const forLoop = results [ 0 ] . details . find (
128+ ( d : UnifiedMetricsDetail ) => d . reason . includes ( "for" )
128129 ) ;
129130 const innerForLoop = results [ 0 ] . details . find (
130- ( d : any ) => d . reason . includes ( "for" ) && d . nesting > 0
131+ ( d : UnifiedMetricsDetail ) => d . reason . includes ( "for" ) && d . nesting > 0
131132 ) ;
132133
133134 assert . ok ( forLoop ) ;
@@ -156,8 +157,8 @@ func Method(val int) string {
156157
157158 assert . strictEqual ( results . length , 1 ) ;
158159 assert . ok ( results [ 0 ] . complexity > 0 ) ;
159- const switchDetail = results [ 0 ] . details . find ( ( d : any ) =>
160- d . reason . includes ( "switch" )
160+ const switchDetail = results [ 0 ] . details . find (
161+ ( d : UnifiedMetricsDetail ) => d . reason . includes ( "switch" )
161162 ) ;
162163 assert . ok ( switchDetail ) ;
163164 } ) ;
@@ -181,8 +182,8 @@ func Method(ch1, ch2 chan int) {
181182
182183 assert . strictEqual ( results . length , 1 ) ;
183184 assert . ok ( results [ 0 ] . complexity > 0 ) ;
184- const selectDetail = results [ 0 ] . details . find ( ( d : any ) =>
185- d . reason . includes ( "select" )
185+ const selectDetail = results [ 0 ] . details . find (
186+ ( d : UnifiedMetricsDetail ) => d . reason . includes ( "select" )
186187 ) ;
187188 assert . ok ( selectDetail ) ;
188189 } ) ;
@@ -310,100 +311,11 @@ func Subtract(a, b int) int {
310311 assert . strictEqual ( results . length , 1 ) ;
311312 assert . ok ( results [ 0 ] . complexity > 0 ) ;
312313
313- const forLoop = results [ 0 ] . details . find ( ( d : any ) =>
314- d . reason . includes ( "for" )
314+ const forLoop = results [ 0 ] . details . find (
315+ ( d : UnifiedMetricsDetail ) => d . reason . includes ( "for" )
315316 ) ;
316- const whileLoop = results [ 0 ] . details . find ( ( d : any ) =>
317- d . reason . includes ( "while" )
318- ) ;
319-
320- assert . ok ( forLoop ) ;
321- assert . ok ( whileLoop ) ;
322- assert . ok ( whileLoop . nesting > forLoop . nesting ) ;
323- } ) ;
324- } ) ;
325-
326- describe ( "CSharp Analyzer Core Logic" , ( ) => {
327- it ( "should analyze simple method correctly" , ( ) => {
328- const analyzer = new CSharpMetricsAnalyzer ( ) ;
329- const results = analyzer . analyzeFunctions ( SampleCSharpCode . SIMPLE_METHOD ) ;
330-
331- assert . strictEqual ( results . length , 1 ) ;
332- assert . strictEqual ( results [ 0 ] . name , "Add" ) ;
333- assert . strictEqual ( results [ 0 ] . complexity , 0 ) ;
334- assert . strictEqual ( results [ 0 ] . details . length , 0 ) ;
335- } ) ;
336-
337- it ( "should analyze if statement correctly" , ( ) => {
338- const analyzer = new CSharpMetricsAnalyzer ( ) ;
339- const results = analyzer . analyzeFunctions ( SampleCSharpCode . SINGLE_IF ) ;
340-
341- assert . strictEqual ( results . length , 1 ) ;
342- assert . strictEqual ( results [ 0 ] . name , "Max" ) ;
343- assert . strictEqual ( results [ 0 ] . complexity , 1 ) ;
344- assert . strictEqual ( results [ 0 ] . details . length , 1 ) ;
345- assert . strictEqual ( results [ 0 ] . details [ 0 ] . reason , "if statement" ) ;
346- } ) ;
347-
348- it ( "should analyze nested complexity correctly" , ( ) => {
349- const analyzer = new CSharpMetricsAnalyzer ( ) ;
350- const results = analyzer . analyzeFunctions (
351- SampleCSharpCode . NESTED_COMPLEX
352- ) ;
353-
354- assert . ok ( results . length > 0 ) ;
355- const mainMethod = results . find (
356- ( r : UnifiedFunctionMetrics ) => r . name === "ComplexMethod"
357- ) ;
358- assert . ok ( mainMethod ) ;
359- assert . ok ( mainMethod . complexity > 5 ) ; // Should have significant complexity
360- } ) ;
361-
362- it ( "should handle logical operators" , ( ) => {
363- const sourceCode = `
364- public class Test {
365- public void Method(bool a, bool b, bool c) {
366- if (a && b) {
367- return;
368- }
369- if (b || c) {
370- return;
371- }
372- }
373- }
374- ` ;
375-
376- const analyzer = new CSharpMetricsAnalyzer ( ) ;
377- const results = analyzer . analyzeFunctions ( sourceCode ) ;
378-
379- assert . strictEqual ( results . length , 1 ) ;
380- assert . strictEqual ( results [ 0 ] . complexity , 4 ) ; // 2 ifs + 1 && + 1 ||
381- } ) ;
382-
383- it ( "should handle loops correctly" , ( ) => {
384- const sourceCode = `
385- public class Test {
386- public void Method() {
387- for (int i = 0; i < 10; i++) {
388- while (true) {
389- break;
390- }
391- }
392- }
393- }
394- ` ;
395-
396- const analyzer = new CSharpMetricsAnalyzer ( ) ;
397- const results = analyzer . analyzeFunctions ( sourceCode ) ;
398-
399- assert . strictEqual ( results . length , 1 ) ;
400- assert . ok ( results [ 0 ] . complexity > 0 ) ;
401-
402- const forLoop = results [ 0 ] . details . find ( ( d : any ) =>
403- d . reason . includes ( "for" )
404- ) ;
405- const whileLoop = results [ 0 ] . details . find ( ( d : any ) =>
406- d . reason . includes ( "while" )
317+ const whileLoop = results [ 0 ] . details . find (
318+ ( d : UnifiedMetricsDetail ) => d . reason . includes ( "while" )
407319 ) ;
408320
409321 assert . ok ( forLoop ) ;
0 commit comments