bytes_split.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Test splitting with a single character separator
  2. assert b"hello world".split(
  3. b" ") == [b"hello", b"world"], "Single space separator failed"
  4. # Test splitting with a multi-character separator
  5. assert b"hello##world".split(
  6. b"##") == [b"hello", b"world"], "Multi-character separator failed"
  7. # Test splitting with no occurrences of the separator
  8. assert b"hello world".split(
  9. b"x") == [b"hello world"], "Non-existent separator failed"
  10. # Test splitting with an empty separator should raise ValueError
  11. try:
  12. b"hello world".split(b"")
  13. assert False, "Empty separator did not raise ValueError"
  14. except:
  15. assert True, "Empty separator raised ValueError correctly"
  16. # Test splitting with a maximum split parameter
  17. assert b"one two three".split(
  18. b" ", 1) == [b"one", b"two three"], "Max split parameter failed"
  19. # Test splitting an empty bytes object
  20. assert b"".split(b"-") == [b""], "Empty input failed"
  21. # print(b"----".split(b"-"))
  22. # Test splitting when the entire input is the separator
  23. assert b"----".split(b"-") == [b"", b"", b"", b"",
  24. b""], "Input is all separators failed"
  25. # Test splitting with trailing separators
  26. assert b"this is a test---".split(
  27. b"-") == [b"this is a test", b"", b"", b""], "Trailing separators failed"
  28. # Test splitting with leading separators
  29. assert b"---this is a test".split(b"-") == [b"", b"",
  30. b"", b"this is a test"], "Leading separators failed"
  31. print("PASS")