From 36f6d92d987ccfcd3139f090efb449fb3c2f79d7 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Wed, 13 Jul 2022 18:08:33 -0400 Subject: Add tests for translator compiler --- test/pleroma/docs/translator/compiler_test.exs | 55 ++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/pleroma/docs/translator/compiler_test.exs (limited to 'test') diff --git a/test/pleroma/docs/translator/compiler_test.exs b/test/pleroma/docs/translator/compiler_test.exs new file mode 100644 index 000000000..66bb77dc1 --- /dev/null +++ b/test/pleroma/docs/translator/compiler_test.exs @@ -0,0 +1,55 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2022 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Docs.Translator.CompilerTest do + use ExUnit.Case, async: true + + alias Pleroma.Docs.Translator.Compiler + + @descriptions [ + %{ + label: "1", + description: "2", + children: [ + %{ + label: "3", + description: "4" + }, + %{ + label: "5", + description: "6" + } + ] + }, + %{ + label: "7", + description: "8", + children: [ + %{ + description: "9", + children: [ + %{ + description: "10", + children: [ + %{description: "11"}, + %{description: "12"} + ] + } + ] + }, + %{ + label: "13" + } + ] + } + ] + + describe "extract_strings/1" do + test "it extracts all labels and descriptions" do + strings = Compiler.extract_strings(@descriptions) + assert length(strings) == 13 + assert Enum.all?(1..13, &(to_string(&1) in strings)) + end + end +end -- cgit v1.2.3 From 1d7e8d6e013bb39e6ca61bd595a22490412db084 Mon Sep 17 00:00:00 2001 From: Tusooa Zhu Date: Thu, 14 Jul 2022 17:41:33 -0400 Subject: Pass in msgctxt for config translation strings --- test/pleroma/docs/translator/compiler_test.exs | 41 ++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/pleroma/docs/translator/compiler_test.exs b/test/pleroma/docs/translator/compiler_test.exs index 66bb77dc1..d6c3cdd40 100644 --- a/test/pleroma/docs/translator/compiler_test.exs +++ b/test/pleroma/docs/translator/compiler_test.exs @@ -9,30 +9,36 @@ defmodule Pleroma.Docs.Translator.CompilerTest do @descriptions [ %{ + key: "1", label: "1", description: "2", children: [ %{ + key: "3", label: "3", description: "4" }, %{ + key: "5", label: "5", description: "6" } ] }, %{ + key: "7", label: "7", description: "8", children: [ %{ + key: "9", description: "9", children: [ %{ + key: "10", description: "10", children: [ - %{description: "11"}, + %{key: "11", description: "11"}, %{description: "12"} ] } @@ -42,14 +48,43 @@ defmodule Pleroma.Docs.Translator.CompilerTest do label: "13" } ] + }, + %{ + group: "14", + label: "14" + }, + %{ + group: "15", + key: "15", + label: "15" + }, + %{ + group: {":subgroup", "16"}, + label: "16" } ] describe "extract_strings/1" do test "it extracts all labels and descriptions" do strings = Compiler.extract_strings(@descriptions) - assert length(strings) == 13 - assert Enum.all?(1..13, &(to_string(&1) in strings)) + assert length(strings) == 16 + + assert {["1"], "label", "1"} in strings + assert {["1"], "description", "2"} in strings + assert {["1", "3"], "label", "3"} in strings + assert {["1", "3"], "description", "4"} in strings + assert {["1", "5"], "label", "5"} in strings + assert {["1", "5"], "description", "6"} in strings + assert {["7"], "label", "7"} in strings + assert {["7"], "description", "8"} in strings + assert {["7", "9"], "description", "9"} in strings + assert {["7", "9", "10"], "description", "10"} in strings + assert {["7", "9", "10", "11"], "description", "11"} in strings + assert {["7", "9", "10", nil], "description", "12"} in strings + assert {["7", nil], "label", "13"} in strings + assert {["14"], "label", "14"} in strings + assert {["15-15"], "label", "15"} in strings + assert {["16"], "label", "16"} in strings end end end -- cgit v1.2.3