| 441 | |
| 442 | |
| 443 | def test_unit_strip(): |
| 444 | # Test with whitespace (default behavior) |
| 445 | native_whitespace = " \t\n hello world \r\f\v " |
| 446 | big_whitespace = Str(native_whitespace) |
| 447 | |
| 448 | # Test lstrip |
| 449 | assert native_whitespace.lstrip() == str(sz.lstrip(big_whitespace)) |
| 450 | assert native_whitespace.lstrip() == str(big_whitespace.lstrip()) |
| 451 | |
| 452 | # Test rstrip |
| 453 | assert native_whitespace.rstrip() == str(sz.rstrip(big_whitespace)) |
| 454 | assert native_whitespace.rstrip() == str(big_whitespace.rstrip()) |
| 455 | |
| 456 | # Test strip |
| 457 | assert native_whitespace.strip() == str(sz.strip(big_whitespace)) |
| 458 | assert native_whitespace.strip() == str(big_whitespace.strip()) |
| 459 | |
| 460 | # Test with custom character set |
| 461 | native_custom = "aaabbbhello worldcccaaa" |
| 462 | big_custom = Str(native_custom) |
| 463 | chars = "abc" |
| 464 | |
| 465 | # Test lstrip with custom chars |
| 466 | assert native_custom.lstrip(chars) == str(sz.lstrip(big_custom, chars)) |
| 467 | assert native_custom.lstrip(chars) == str(big_custom.lstrip(chars)) |
| 468 | |
| 469 | # Test rstrip with custom chars |
| 470 | assert native_custom.rstrip(chars) == str(sz.rstrip(big_custom, chars)) |
| 471 | assert native_custom.rstrip(chars) == str(big_custom.rstrip(chars)) |
| 472 | |
| 473 | # Test strip with custom chars |
| 474 | assert native_custom.strip(chars) == str(sz.strip(big_custom, chars)) |
| 475 | assert native_custom.strip(chars) == str(big_custom.strip(chars)) |
| 476 | |
| 477 | # Test edge cases |
| 478 | # Empty string |
| 479 | empty = "" |
| 480 | big_empty = Str(empty) |
| 481 | assert empty.strip() == str(sz.strip(big_empty)) |
| 482 | assert empty.strip() == str(big_empty.strip()) |
| 483 | |
| 484 | # String with only whitespace |
| 485 | only_whitespace = " \t\n\r\f\v " |
| 486 | big_only_whitespace = Str(only_whitespace) |
| 487 | assert only_whitespace.strip() == str(sz.strip(big_only_whitespace)) |
| 488 | assert only_whitespace.strip() == str(big_only_whitespace.strip()) |
| 489 | |
| 490 | # String with only custom chars |
| 491 | only_custom = "aaabbbccc" |
| 492 | big_only_custom = Str(only_custom) |
| 493 | assert only_custom.strip("abc") == str(sz.strip(big_only_custom, "abc")) |
| 494 | assert only_custom.strip("abc") == str(big_only_custom.strip("abc")) |
| 495 | |
| 496 | # String with no chars to strip |
| 497 | no_strip = "hello world" |
| 498 | big_no_strip = Str(no_strip) |
| 499 | assert no_strip.strip() == str(sz.strip(big_no_strip)) |
| 500 | assert no_strip.strip() == str(big_no_strip.strip()) |