Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interfaces' methods should be parsed as MethodDeclaration.
- Loading branch information
1 parent
3692177
commit 6424cbd
Showing
2 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import unittest | ||
|
||
import plyj.parser as plyj | ||
import plyj.model as model | ||
from plyj.model import * | ||
|
||
class TypeDeclarationTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.parser = plyj.Parser() | ||
|
||
def test_class_method(self): | ||
m = self.parser.parse_string(''' | ||
class Foo { | ||
void foo() {} | ||
} | ||
''') | ||
cls = self._assert_declaration(m, 'Foo') | ||
self.assertEquals(cls.body, [MethodDeclaration('foo', body=[])]) | ||
|
||
def test_interface_method(self): | ||
m = self.parser.parse_string(''' | ||
interface Foo { | ||
void foo(); | ||
} | ||
''') | ||
cls = self._assert_declaration(m, 'Foo', type=model.InterfaceDeclaration) | ||
self.assertEquals(cls.body, [MethodDeclaration('foo', abstract=True)]) | ||
|
||
def test_class_abstract_method(self): | ||
m = self.parser.parse_string(''' | ||
abstract class Foo { | ||
abstract void foo(); | ||
} | ||
''') | ||
cls = self._assert_declaration(m, 'Foo') | ||
self.assertEquals(cls.body, [MethodDeclaration('foo', modifiers=['abstract'], abstract=True)]) | ||
|
||
def _assert_declaration(self, compilation_unit, name, index=0, type=model.ClassDeclaration): | ||
self.assertIsInstance(compilation_unit, model.CompilationUnit) | ||
self.assertTrue(len(compilation_unit.type_declarations) >= index + 1) | ||
|
||
decl = compilation_unit.type_declarations[index] | ||
self.assertIsInstance(decl, type) | ||
|
||
self.assertEqual(decl.name, name) | ||
|
||
return decl |