dotfiles/talon/user/community/test/test_formatters.py

93 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import talon
if hasattr(talon, "test_mode"):
# Only include this when we're running tests
from talon import actions
from core.text import formatters
def setup_function():
actions.reset_test_actions()
actions.register_test_action("user", "add_phrase_to_history", lambda x: None)
def test_snake_case():
result = formatters.Actions.formatted_text("hello world", "SNAKE_CASE")
assert result == "hello_world"
def test_no_spaces():
result = formatters.Actions.formatted_text("hello world", "NO_SPACES")
assert result == "helloworld"
def test_capitalize():
result = formatters.Actions.formatted_text("hello world", "CAPITALIZE")
assert result == "Hello world"
result = formatters.Actions.formatted_text("hEllo wOrld", "CAPITALIZE")
assert result == "HEllo wOrld"
def test_capitalize_first_word():
result = formatters.Actions.formatted_text(
"hello world", "CAPITALIZE_FIRST_WORD"
)
assert result == "Hello world"
result = formatters.Actions.formatted_text(
"hEllo wOrld", "CAPITALIZE_FIRST_WORD"
)
assert result == "hEllo wOrld"
def test_capitalize_all_words():
result = formatters.Actions.formatted_text(
"hello world", "CAPITALIZE_ALL_WORDS"
)
assert result == "Hello World"
result = formatters.Actions.formatted_text(
"hEllo wOrld", "CAPITALIZE_ALL_WORDS"
)
assert result == "hEllo wOrld"
result = formatters.Actions.formatted_text(
"Hello to the world", "CAPITALIZE_ALL_WORDS"
)
assert result == "Hello to the World"
result = formatters.Actions.formatted_text(
"hello: the world", "CAPITALIZE_ALL_WORDS"
)
assert result == "Hello: The World"
result = formatters.Actions.formatted_text(
"down and up", "CAPITALIZE_ALL_WORDS"
)
assert result == "Down and Up"
result = formatters.Actions.formatted_text(
"down-and-up", "CAPITALIZE_ALL_WORDS"
)
assert result == "Down-and-Up"
result = formatters.Actions.formatted_text(
"it's good theyre Bills friends", "CAPITALIZE_ALL_WORDS"
)
assert result == "It's Good Theyre Bills Friends"
result = formatters.Actions.formatted_text(
'"how\'s it going?"', "CAPITALIZE_ALL_WORDS"
)
assert result == '"How\'s It Going?"'