Add double byte string format
This commit is contained in:
66
tests/double_byte_string_format/double_byte_string_format.py
Normal file
66
tests/double_byte_string_format/double_byte_string_format.py
Normal file
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env -S uv run --script
|
||||
|
||||
"""
|
||||
Test for double byte format
|
||||
"""
|
||||
|
||||
from corelibs.string_handling.double_byte_string_format import DoubleByteFormatString
|
||||
|
||||
|
||||
def main():
|
||||
"""
|
||||
Main call
|
||||
"""
|
||||
string = [
|
||||
"Some string 123 other text",
|
||||
"Some string 日本語 other text",
|
||||
"日本語は string 123 other text",
|
||||
"あいうえおかきくけこさしすせそなにぬねのまみむめも〜",
|
||||
"あいうえおかきくけこさしす 1 other text",
|
||||
"Some string すせそなにぬねのまみむめも〜",
|
||||
"SOME OTHER STRING THAT IS LONGER THAN TWENTYSIX CHARACTERS",
|
||||
"日本語は string 123 other text Some string 日本語 other text"
|
||||
]
|
||||
|
||||
format_str = "{{:<{len}}}"
|
||||
|
||||
length_set = [
|
||||
(26, 25),
|
||||
(26, 26),
|
||||
(26, 60),
|
||||
(26, 20),
|
||||
(26, -5),
|
||||
(-6, -5),
|
||||
]
|
||||
|
||||
for _length_set in length_set:
|
||||
cut_length = _length_set[0]
|
||||
format_length = _length_set[1]
|
||||
print(f"========= Cut: {cut_length} | Format: {format_length} ==> ")
|
||||
for _string in string:
|
||||
string_test = DoubleByteFormatString(_string, cut_length, format_length)
|
||||
formated = format_str.format(
|
||||
len=string_test.get_format_length()
|
||||
).format(
|
||||
string_test.get_string_short()
|
||||
)
|
||||
|
||||
print(
|
||||
"* Shorten string: shorten length: "
|
||||
f"Req: {string_test.get_requested_cut_length()} ({cut_length}) / "
|
||||
f"Set: {string_test.get_cut_length()}, "
|
||||
"format length: "
|
||||
f"Req: {string_test.get_requested_format_length()} ({format_length}) / "
|
||||
f"Set: {string_test.get_format_length()}"
|
||||
f"\nOrig: |{_string}|"
|
||||
f"\nGSS : |{string_test.get_string_short()}|"
|
||||
f"\nF : |{formated}|"
|
||||
f"\nGSSF: |{string_test.get_string_short_formated()}|"
|
||||
)
|
||||
print("-------")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# __END__
|
||||
Reference in New Issue
Block a user