Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/string_length_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule AshPostgres.StringLengthTest do
use AshPostgres.RepoCase, async: false

alias Ash.Query.Function.StringLength
alias AshPostgres.Test.Post

require Ash.Query
import Ash.Expr

# Decomposed, so the stored value is 11 codepoints and its NFC form is 7.
@decomposed :unicode.characters_to_nfd_binary("ünïcödé")

test "string_length counts codepoints on the stored value" do

Check failure on line 13 in test/string_length_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (17) / mix test

test string_length counts codepoints on the stored value (AshPostgres.StringLengthTest)

Check failure on line 13 in test/string_length_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (18) / mix test

test string_length counts codepoints on the stored value (AshPostgres.StringLengthTest)

Check failure on line 13 in test/string_length_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test string_length counts codepoints on the stored value (AshPostgres.StringLengthTest)

Check failure on line 13 in test/string_length_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test string_length counts codepoints on the stored value (AshPostgres.StringLengthTest)

Check failure on line 13 in test/string_length_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test string_length counts codepoints on the stored value (AshPostgres.StringLengthTest)
Post |> Ash.Changeset.for_create(:create, %{title: @decomposed}) |> Ash.create!()

expected = StringLength.string_length(@decomposed, :codepoints)

assert %{length: ^expected} =
Post
|> Ash.Query.calculate(:length, :integer, expr(string_length(title, :codepoints)))
|> Ash.read_one!()
|> Map.get(:calculations)
end
end
Loading