MCPcopy Index your code
hub / github.com/python/mypy / test_c_string

Method test_c_string

mypyc/test/test_emitfunc.py:950–972  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

948 self.assert_emit([b, IncRef(b)], "CPy_INCREF(cpy_r_r0);")
949
950 def test_c_string(self) -> None:
951 s = Register(cstring_rprimitive, "s")
952 self.assert_emit(Assign(s, CString(b"foo")), """cpy_r_s = "foo";""")
953 self.assert_emit(Assign(s, CString(b'foo "o')), r"""cpy_r_s = "foo \"o";""")
954 self.assert_emit(Assign(s, CString(b"\x00")), r"""cpy_r_s = "\x00";""")
955 self.assert_emit(Assign(s, CString(b"\\")), r"""cpy_r_s = "\\";""")
956 for i in range(256):
957 b = bytes([i])
958 if b == b"\n":
959 target = "\\n"
960 elif b == b"\r":
961 target = "\\r"
962 elif b == b"\t":
963 target = "\\t"
964 elif b == b'"':
965 target = '\\"'
966 elif b == b"\\":
967 target = "\\\\"
968 elif i < 32 or i >= 127:
969 target = "\\x%.2x" % i
970 else:
971 target = b.decode("ascii")
972 self.assert_emit(Assign(s, CString(b)), f'cpy_r_s = "{target}";')
973
974 def assert_emit(
975 self,

Callers

nothing calls this directly

Calls 7

assert_emitMethod · 0.95
RegisterClass · 0.90
AssignClass · 0.90
CStringClass · 0.90
rangeClass · 0.85
bytesClass · 0.85
decodeMethod · 0.45

Tested by

no test coverage detected