1from clang.cindex import TokenKind
2from nose.tools import eq_
3from nose.tools import ok_
4from nose.tools import raises
5
6def test_constructor():
7    """Ensure TokenKind constructor works as expected."""
8
9    t = TokenKind(5, 'foo')
10
11    eq_(t.value, 5)
12    eq_(t.name, 'foo')
13
14@raises(ValueError)
15def test_bad_register():
16    """Ensure a duplicate value is rejected for registration."""
17
18    TokenKind.register(2, 'foo')
19
20@raises(ValueError)
21def test_unknown_value():
22    """Ensure trying to fetch an unknown value raises."""
23
24    TokenKind.from_value(-1)
25
26def test_registration():
27    """Ensure that items registered appear as class attributes."""
28    ok_(hasattr(TokenKind, 'LITERAL'))
29    literal = TokenKind.LITERAL
30
31    ok_(isinstance(literal, TokenKind))
32
33def test_from_value():
34    """Ensure registered values can be obtained from from_value()."""
35    t = TokenKind.from_value(3)
36    ok_(isinstance(t, TokenKind))
37    eq_(t, TokenKind.LITERAL)
38
39def test_repr():
40    """Ensure repr() works."""
41
42    r = repr(TokenKind.LITERAL)
43    eq_(r, 'TokenKind.LITERAL')
44