forked from pikasTech/PikaPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbytes_split.py
More file actions
41 lines (31 loc) · 1.46 KB
/
bytes_split.py
File metadata and controls
41 lines (31 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Test splitting with a single character separator
assert b"hello world".split(
b" ") == [b"hello", b"world"], "Single space separator failed"
# Test splitting with a multi-character separator
assert b"hello##world".split(
b"##") == [b"hello", b"world"], "Multi-character separator failed"
# Test splitting with no occurrences of the separator
assert b"hello world".split(
b"x") == [b"hello world"], "Non-existent separator failed"
# Test splitting with an empty separator should raise ValueError
try:
b"hello world".split(b"")
assert False, "Empty separator did not raise ValueError"
except:
assert True, "Empty separator raised ValueError correctly"
# Test splitting with a maximum split parameter
assert b"one two three".split(
b" ", 1) == [b"one", b"two three"], "Max split parameter failed"
# Test splitting an empty bytes object
assert b"".split(b"-") == [b""], "Empty input failed"
# print(b"----".split(b"-"))
# Test splitting when the entire input is the separator
assert b"----".split(b"-") == [b"", b"", b"", b"",
b""], "Input is all separators failed"
# Test splitting with trailing separators
assert b"this is a test---".split(
b"-") == [b"this is a test", b"", b"", b""], "Trailing separators failed"
# Test splitting with leading separators
assert b"---this is a test".split(b"-") == [b"", b"",
b"", b"this is a test"], "Leading separators failed"
print("PASS")