363738394041424344
public void testEmptyFunction() throws Exception { TranslationUnit unit = parse( "void foo() { " + "}" ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(1, analyzer.getScore()); }
484950515253545556
"void foo() { " + " int i = 0; " + " i += 1; " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(1, analyzer.getScore()); }
646566676869707172
" } else { " + " a--; " + " } " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(2, analyzer.getScore()); }
787980818283848586
" if (a < 0) { " + " a++; " + " } " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(2, analyzer.getScore()); }
93949596979899100101
" case 0: " + " a = 0; " + " } " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(2, analyzer.getScore()); }
112113114115116117118119120
" a = 1; " + " break; " + " } " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(3, analyzer.getScore()); }
130131132133134135136137138
" default: " + " a = 3; " + " } " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(2, analyzer.getScore()); }
145146147148149150151152153
" ++a; " + " } " + " return a; " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(2, analyzer.getScore()); }
156157158159160161162163164
TranslationUnit unit = parse( "int foo(int a, int b) { " + " return a > 0 ? b : 1; " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(2, analyzer.getScore()); }
167168169170171172173174175
TranslationUnit unit = parse( "int foo(int a, int b) { " + " return a > 0 ? (b < 0 ? -1 : 0) : 1; " + "} " ); FunctionDefinition functionFoo = unit.getChild(0); functionFoo.accept(analyzer); assertEquals(3, analyzer.getScore()); }