61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
"""Tests for capnp_stubgen.utils."""
|
|
|
|
from capnp_stubgen.utils import (
|
|
filename_to_module_name,
|
|
get_display_name,
|
|
get_node_kind,
|
|
type_id_to_int,
|
|
)
|
|
|
|
|
|
class TestFilenameToModuleName:
|
|
def test_simple(self):
|
|
assert filename_to_module_name("foo.capnp") == "foo_capnp"
|
|
|
|
def test_path(self):
|
|
assert filename_to_module_name("path/to/bar.capnp") == "bar_capnp"
|
|
|
|
def test_no_extension(self):
|
|
assert filename_to_module_name("foo") == "foo_capnp"
|
|
|
|
|
|
class TestGetDisplayName:
|
|
def test_extracts_name(self):
|
|
node = {
|
|
"displayName": "path/to/file.capnp:MyType",
|
|
"displayNamePrefixLength": 19, # "path/to/file.capnp:" = 19 chars
|
|
}
|
|
assert get_display_name(node) == "MyType"
|
|
|
|
def test_nested_type(self):
|
|
node = {
|
|
"displayName": "path/to/file.capnp:OuterType.InnerType",
|
|
"displayNamePrefixLength": 19, # "path/to/file.capnp:" = 19 chars
|
|
}
|
|
assert get_display_name(node) == "OuterType.InnerType"
|
|
|
|
|
|
class TestGetNodeKind:
|
|
def test_struct(self):
|
|
assert get_node_kind({"struct": {}, "id": "1"}) == "struct"
|
|
|
|
def test_enum(self):
|
|
assert get_node_kind({"enum": {}, "id": "1"}) == "enum"
|
|
|
|
def test_file(self):
|
|
assert get_node_kind({"file": {}, "id": "1"}) == "file"
|
|
|
|
def test_interface(self):
|
|
assert get_node_kind({"interface": {}, "id": "1"}) == "interface"
|
|
|
|
def test_unknown(self):
|
|
assert get_node_kind({"id": "1"}) == "unknown"
|
|
|
|
|
|
class TestTypeIdToInt:
|
|
def test_converts(self):
|
|
assert type_id_to_int("12345") == 12345
|
|
|
|
def test_large_id(self):
|
|
assert type_id_to_int("15491878201996422075") == 15491878201996422075
|