diff options
Diffstat (limited to 'bindings/python/tests/cindex/test_tokens.py')
-rw-r--r-- | bindings/python/tests/cindex/test_tokens.py | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/bindings/python/tests/cindex/test_tokens.py b/bindings/python/tests/cindex/test_tokens.py index 688b5c1c900e..c93353dc9da2 100644 --- a/bindings/python/tests/cindex/test_tokens.py +++ b/bindings/python/tests/cindex/test_tokens.py @@ -3,50 +3,52 @@ from clang.cindex import Index from clang.cindex import SourceLocation from clang.cindex import SourceRange from clang.cindex import TokenKind -from nose.tools import eq_ -from nose.tools import ok_ from .util import get_tu -def test_token_to_cursor(): - """Ensure we can obtain a Cursor from a Token instance.""" - tu = get_tu('int i = 5;') - r = tu.get_extent('t.c', (0, 9)) - tokens = list(tu.get_tokens(extent=r)) +import unittest - assert len(tokens) == 4 - assert tokens[1].spelling == 'i' - assert tokens[1].kind == TokenKind.IDENTIFIER - cursor = tokens[1].cursor - assert cursor.kind == CursorKind.VAR_DECL - assert tokens[1].cursor == tokens[2].cursor +class TestTokens(unittest.TestCase): + def test_token_to_cursor(self): + """Ensure we can obtain a Cursor from a Token instance.""" + tu = get_tu('int i = 5;') + r = tu.get_extent('t.c', (0, 9)) + tokens = list(tu.get_tokens(extent=r)) -def test_token_location(): - """Ensure Token.location works.""" + self.assertEqual(len(tokens), 4) + self.assertEqual(tokens[1].spelling, 'i') + self.assertEqual(tokens[1].kind, TokenKind.IDENTIFIER) - tu = get_tu('int foo = 10;') - r = tu.get_extent('t.c', (0, 11)) + cursor = tokens[1].cursor + self.assertEqual(cursor.kind, CursorKind.VAR_DECL) + self.assertEqual(tokens[1].cursor, tokens[2].cursor) - tokens = list(tu.get_tokens(extent=r)) - eq_(len(tokens), 4) + def test_token_location(self): + """Ensure Token.location works.""" - loc = tokens[1].location - ok_(isinstance(loc, SourceLocation)) - eq_(loc.line, 1) - eq_(loc.column, 5) - eq_(loc.offset, 4) + tu = get_tu('int foo = 10;') + r = tu.get_extent('t.c', (0, 11)) -def test_token_extent(): - """Ensure Token.extent works.""" - tu = get_tu('int foo = 10;') - r = tu.get_extent('t.c', (0, 11)) + tokens = list(tu.get_tokens(extent=r)) + self.assertEqual(len(tokens), 4) - tokens = list(tu.get_tokens(extent=r)) - eq_(len(tokens), 4) + loc = tokens[1].location + self.assertIsInstance(loc, SourceLocation) + self.assertEqual(loc.line, 1) + self.assertEqual(loc.column, 5) + self.assertEqual(loc.offset, 4) - extent = tokens[1].extent - ok_(isinstance(extent, SourceRange)) + def test_token_extent(self): + """Ensure Token.extent works.""" + tu = get_tu('int foo = 10;') + r = tu.get_extent('t.c', (0, 11)) - eq_(extent.start.offset, 4) - eq_(extent.end.offset, 7) + tokens = list(tu.get_tokens(extent=r)) + self.assertEqual(len(tokens), 4) + + extent = tokens[1].extent + self.assertIsInstance(extent, SourceRange) + + self.assertEqual(extent.start.offset, 4) + self.assertEqual(extent.end.offset, 7) |