コード例 #1
0
 def test_do_statement_count(self):
     code = """
         do
             a-- ;
         while ( a );
     """
     node = self.statement(code)
     self.assertEqual(branches(node), 1)
コード例 #2
0
 def test_if_statement_count(self):
     code = """
         if (itr == '\r') {
             int status = 1;
         }
     """
     node = self.statement(code)
     self.assertEqual(branches(node), 1)
コード例 #3
0
 def test_for_statement_count(self):
     code = """
         for (int i = 0; i < amounts.length; i++) {
             result += amounts[i];
         }
     """
     node = self.statement(code)
     self.assertEqual(branches(node), 1)
コード例 #4
0
 def test_while_statement_count(self):
     code = """
         while (i < 5) {
             System.out.println(i);
             i++;
         }
     """
     node = self.statement(code)
     self.assertEqual(branches(node), 1)
コード例 #5
0
 def test_switch_statement_count(self):
     code = """
         switch ( a )
         {
             case 1:
             return ;
         }
     """
     node = self.statement(code)
     self.assertEqual(branches(node.cases[0]), 1)
コード例 #6
0
 def test_catch_statements(self):
     code = """
         try {
             Throwable t = new Exception();
             throw t;
         } catch (RuntimeException e) {
             System.err.println("catch RuntimeException");
         } catch (Exception e) {
             System.err.println("catch Exception");
         } catch (Throwable e) {
             System.err.println("catch Throwable");
         }
         System.err.println("next statement");
     """
     node = self.statement(code)
     self.assertEqual(branches(node), 3)
コード例 #7
0
            for path, node in ast:
                receivedNames += compound(node)

            if (receivedNames != expectedNames):
                raise Exception('\nTest failed. Expected ' +
                                str(expectedNames) + ', received ' +
                                str(receivedNames))
        except Exception as e:
            sys.exit(str(e) + ': ' + java)

for java in glob(os.path.join(fileDir, 'java/cc/*.java')):
    with open(java, encoding='utf-8') as f:
        try:
            ast = javalang.parse.parse(f.read())
            receivedCC = 1
            expectedCC = cc(ast)

            for path, node in ast:
                receivedCC += branches(node)

            if (receivedCC != expectedCC):
                raise Exception('\nTest failed. Expected ' + str(expectedCC) +
                                ', received ' + str(receivedCC))

            print('.', end='', flush=True),
        except Exception as e:
            sys.exit(str(e) + ': ' + java)

print('\nOK')
コード例 #8
0
 def test_ternary_operator(self):
     code = 'value == "uppercase" ? "JOHN" : "john";'
     node = self.expression(code)
     self.assertEqual(branches(node), 1)
コード例 #9
0
 def test_logic_operator_not_count(self):
     code = 'if ( a > b ) {}'
     ifNode = self.statement(code)
     self.assertEqual(branches(ifNode.children[1]), 0)
コード例 #10
0
 def test_branch_not_count(self):
     code = "nextKey = new BlockKey(serialNo, System.currentTimeMillis() + 3.0);"
     node = self.expression(code)
     self.assertEqual(branches(node), 0)