summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormarcin mikołajczak <git@mkljczk.pl>2023-08-11 13:44:30 +0200
committermarcin mikołajczak <git@mkljczk.pl>2023-08-11 13:44:30 +0200
commit04c8f6b4d1e2a9a30f66b0ffb99d7a17a1510a3e (patch)
tree1cde0fb615327b8b6a6f7c6d4bbc6b4b650d2639 /test
parent049045cf2ac90dcca074be9b5cf2d8264828f834 (diff)
downloadpleroma-04c8f6b4d1e2a9a30f66b0ffb99d7a17a1510a3e.tar.gz
pleroma-04c8f6b4d1e2a9a30f66b0ffb99d7a17a1510a3e.zip
Add ObjectValidators.LanguageCode type
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
Diffstat (limited to 'test')
-rw-r--r--test/pleroma/ecto_type/activity_pub/object_validators/bare_uri_test.exs (renamed from test/pleroma/ecto_type/activity_pub/object_validators/bare_uri_test.ex)10
-rw-r--r--test/pleroma/ecto_type/activity_pub/object_validators/language_code.exs28
2 files changed, 33 insertions, 5 deletions
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/bare_uri_test.ex b/test/pleroma/ecto_type/activity_pub/object_validators/bare_uri_test.exs
index 226383c3c..760ecb465 100644
--- a/test/pleroma/ecto_type/activity_pub/object_validators/bare_uri_test.ex
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/bare_uri_test.exs
@@ -9,17 +9,17 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.BareUriTest do
test "diaspora://" do
text = "diaspora://alice@fediverse.example/post/deadbeefdeadbeefdeadbeefdeadbeef"
- assert {:ok, text} = BareUri.cast(text)
+ assert {:ok, ^text} = BareUri.cast(text)
end
test "nostr:" do
text = "nostr:note1gwdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
- assert {:ok, text} = BareUri.cast(text)
+ assert {:ok, ^text} = BareUri.cast(text)
end
test "errors for non-URIs" do
- assert :error == SafeText.cast(1)
- assert :error == SafeText.cast("foo")
- assert :error == SafeText.cast("foo bar")
+ assert :error == BareUri.cast(1)
+ assert :error == BareUri.cast("foo")
+ assert :error == BareUri.cast("foo bar")
end
end
diff --git a/test/pleroma/ecto_type/activity_pub/object_validators/language_code.exs b/test/pleroma/ecto_type/activity_pub/object_validators/language_code.exs
new file mode 100644
index 000000000..2261cc209
--- /dev/null
+++ b/test/pleroma/ecto_type/activity_pub/object_validators/language_code.exs
@@ -0,0 +1,28 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.LanguageCodeTest do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.EctoType.ActivityPub.ObjectValidators.LanguageCode
+
+ test "it accepts language code" do
+ text = "pl"
+ assert {:ok, ^text} = LanguageCode.cast(text)
+ end
+
+ test "it accepts language code with region" do
+ text = "pl-PL"
+ assert {:ok, ^text} = LanguageCode.cast(text)
+ end
+
+ test "errors for invalid language code" do
+ assert {:error, :invalid_language} = LanguageCode.cast("ru_RU")
+ assert {:error, :invalid_language} = LanguageCode.cast(" ")
+ end
+
+ test "errors for non-text" do
+ assert :error == LanguageCode.cast(42)
+ end
+end