pinchflat/test/pinchflat/utils/string_utils_test.exs
Kieran 060e340558
Search v1 (#19)
* Adds description to media items; hooks it up to indexing/media downloading

* Added a search method using postgres fulltext search

* Hooked up search functionality to the search form

* Added persistence to the search form when on search page
2024-02-13 14:46:14 -08:00

44 lines
1.3 KiB
Elixir

defmodule Pinchflat.Utils.StringUtilsTest do
use ExUnit.Case, async: true
alias Pinchflat.Utils.StringUtils
describe "to_kebab_case/1" do
test "converts a space-delimited string to kebab-case" do
assert StringUtils.to_kebab_case("hello world") == "hello-world"
end
test "converts an underscore-delimited string to kebab-case" do
assert StringUtils.to_kebab_case("hello_world") == "hello-world"
end
end
describe "random_string/1" do
test "generates a random string" do
assert is_binary(StringUtils.random_string())
assert StringUtils.random_string() != StringUtils.random_string()
end
test "has a defined default length" do
assert String.length(StringUtils.random_string()) == 32
end
test "can generate a string of a given length" do
assert String.length(StringUtils.random_string(64)) == 64
end
end
describe "truncate/2" do
test "truncates a string to the given length and adds ..." do
assert StringUtils.truncate("hello world", 5) == "hello..."
end
test "breaks on a word boundary" do
assert StringUtils.truncate("hello world", 7) == "hello..."
end
test "does not truncate a string shorter than the given length" do
assert StringUtils.truncate("hello", 10) == "hello"
end
end
end