-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_string_utils.py
More file actions
50 lines (30 loc) · 1.17 KB
/
test_string_utils.py
File metadata and controls
50 lines (30 loc) · 1.17 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
42
43
44
45
46
47
48
49
50
"""Tests for utils.string_utils."""
from utils.string_utils import (
slugify, truncate, camel_to_snake,
snake_to_camel, indent, remove_prefix, remove_suffix,
)
def test_slugify_basic():
assert slugify("Hello World!") == "hello-world"
def test_slugify_unicode():
result = slugify("Ångström")
assert result == "angstrom"
def test_slugify_custom_separator():
assert slugify("Hello World", separator="_") == "hello_world"
def test_truncate_short():
assert truncate("Hi", 10) == "Hi"
def test_truncate_long():
assert truncate("Hello World", 8) == "Hello..."
def test_camel_to_snake():
assert camel_to_snake("camelCase") == "camel_case"
assert camel_to_snake("HTTPSRequest") == "https_request"
def test_snake_to_camel():
assert snake_to_camel("hello_world") == "helloWorld"
def test_indent():
result = indent("line1\nline2", spaces=2)
assert result == " line1\n line2"
def test_remove_prefix():
assert remove_prefix("foobar", "foo") == "bar"
assert remove_prefix("foobar", "baz") == "foobar"
def test_remove_suffix():
assert remove_suffix("foobar", "bar") == "foo"
assert remove_suffix("foobar", "baz") == "foobar"