Telethon/generator/tests/utils_test.py

42 lines
1.2 KiB
Python
Raw Permalink Normal View History

2023-07-03 20:19:20 +03:00
from telethon_generator._impl.tl_parser.utils import infer_id, remove_tl_comments
2023-06-13 00:05:53 +03:00
def test_remove_comments_noop() -> None:
data = "hello\nworld"
assert remove_tl_comments(data) == data
data = " \nhello\nworld\n "
assert remove_tl_comments(data) == data
def test_remove_comments_leading() -> None:
input = " // hello\n world "
expected = " \n world "
assert remove_tl_comments(input) == expected
def test_remove_comments_trailing() -> None:
input = " \nhello \n // world \n \n "
expected = " \nhello \n \n \n "
assert remove_tl_comments(input) == expected
def test_remove_comments_many() -> None:
input = "no\n//yes\nno\n//yes\nno\n"
expected = "no\n\nno\n\nno\n"
assert remove_tl_comments(input) == expected
def test_check_infer_id() -> None:
defn = "rpc_answer_dropped msg_id:long seq_no:int bytes:int = RpcDropAnswer"
assert infer_id(defn) == 0xA43AD8B7
defn = "msgs_ack msg_ids:Vector<long> = MsgsAck"
assert infer_id(defn) == 0x62D6B459
defn = "invokeAfterMsg {X:Type} msg_id:long query:!X = X"
assert infer_id(defn) == 0xCB9F372D
defn = "inputMessagesFilterPhoneCalls flags:# missed:flags.0?true = MessagesFilter"
assert infer_id(defn) == 0x80C99768