Update tests to use nanoids

This commit is contained in:
Thelonius Kort
2023-01-11 22:08:38 +01:00
parent b40c305af1
commit 2d3a511bff
2 changed files with 29 additions and 29 deletions

View File

@ -7,7 +7,7 @@ defmodule Outlook.InternalTreeTest do
alias Outlook.InternalTree alias Outlook.InternalTree
alias Outlook.InternalTree.{InternalNode,TranslationUnit} alias Outlook.InternalTree.{InternalNode,TranslationUnit}
@default_uuid "11111111-1111-1111-1111-111111111111" @default_nid "xxxxxx"
test "partition_text/1 returns correctly partitioned text without overlapping markup" do test "partition_text/1 returns correctly partitioned text without overlapping markup" do
tree = [ tree = [
@ -15,13 +15,13 @@ defmodule Outlook.InternalTreeTest do
name: "p", name: "p",
attributes: %{}, attributes: %{},
type: :element, type: :element,
uuid: "8293da39-18e3-4695-8ec5-a3a4a06f006c", nid: "8293da39-18e3-4695-8ec5-a3a4a06f006c",
content: [ content: [
%InternalNode{ %InternalNode{
name: "", name: "",
attributes: %{}, attributes: %{},
type: :text, type: :text,
uuid: "1b62b02f-0be1-4ba1-88a1-0f08f5a5254d", nid: "1b62b02f-0be1-4ba1-88a1-0f08f5a5254d",
content: "A sentence with many letters ", content: "A sentence with many letters ",
eph: %{sibling_with: :inline} eph: %{sibling_with: :inline}
}, },
@ -34,7 +34,7 @@ defmodule Outlook.InternalTreeTest do
name: "", name: "",
attributes: %{}, attributes: %{},
type: :text, type: :text,
uuid: "c6816bfe-a660-436b-84ab-64d92417e321", nid: "c6816bfe-a660-436b-84ab-64d92417e321",
content: "and many, many ", content: "and many, many ",
eph: %{sibling_with: :inline} eph: %{sibling_with: :inline}
}, },
@ -47,7 +47,7 @@ defmodule Outlook.InternalTreeTest do
name: "", name: "",
attributes: %{}, attributes: %{},
type: :text, type: :text,
uuid: "abcd5893-d062-4716-9979-4bf1f65d5e17", nid: "abcd5893-d062-4716-9979-4bf1f65d5e17",
content: "words. A", content: "words. A",
eph: %{sibling_with: :inline} eph: %{sibling_with: :inline}
} }
@ -58,7 +58,7 @@ defmodule Outlook.InternalTreeTest do
name: "", name: "",
attributes: %{}, attributes: %{},
type: :text, type: :text,
uuid: "d67f41fe-678a-4e27-99da-00d38decde75", nid: "d67f41fe-678a-4e27-99da-00d38decde75",
content: " sentence", content: " sentence",
eph: %{sibling_with: :inline} eph: %{sibling_with: :inline}
} }
@ -69,7 +69,7 @@ defmodule Outlook.InternalTreeTest do
name: "", name: "",
attributes: %{}, attributes: %{},
type: :text, type: :text,
uuid: "6fc0bf77-4dc6-4828-866e-2933d393f4b9", nid: "6fc0bf77-4dc6-4828-866e-2933d393f4b9",
content: " with many letters and many, many words. ", content: " with many letters and many, many words. ",
eph: %{sibling_with: :inline} eph: %{sibling_with: :inline}
} }
@ -78,12 +78,12 @@ defmodule Outlook.InternalTreeTest do
} }
] ]
assert InternalTree.partition_text(tree) |> unify_uuids_in_tunits() == [ assert InternalTree.partition_text(tree) |> unify_nids_in_tunits() == [
%InternalNode{name: "p", attributes: %{}, type: :element, uuid: "8293da39-18e3-4695-8ec5-a3a4a06f006c", %InternalNode{name: "p", attributes: %{}, type: :element, nid: "8293da39-18e3-4695-8ec5-a3a4a06f006c",
content: [ content: [
%TranslationUnit{status: :untranslated, uuid: @default_uuid, %TranslationUnit{status: :untranslated, nid: @default_nid,
content: "A sentence with many letters <a href=\"dingsda.com\">and many, many <b>words. </b></a>"}, content: "A sentence with many letters <a href=\"dingsda.com\">and many, many <b>words. </b></a>"},
%TranslationUnit{status: :untranslated, uuid: @default_uuid, %TranslationUnit{status: :untranslated, nid: @default_nid,
content: "<a href=\"dingsda.com\"><b>A</b> sentence</a> with many letters and many, many words. "} content: "<a href=\"dingsda.com\"><b>A</b> sentence</a> with many letters and many, many words. "}
], ],
eph: %{sibling_with: :block} eph: %{sibling_with: :block}
@ -97,13 +97,13 @@ defmodule Outlook.InternalTreeTest do
name: "p", name: "p",
attributes: %{}, attributes: %{},
type: :element, type: :element,
uuid: "0248aec7-c525-483d-a472-40a34488478d", nid: "0248aec7-c525-483d-a472-40a34488478d",
content: [ content: [
%InternalNode{ %InternalNode{
name: "", name: "",
attributes: %{}, attributes: %{},
type: :text, type: :text,
uuid: "d35ac56f-bf10-47b1-af19-152e6225bb32", nid: "d35ac56f-bf10-47b1-af19-152e6225bb32",
content: "F. William Engdahl is 3.7 times more likely to write a good article than Mike Adams. But this doesn't mean anything bad about Mike.", content: "F. William Engdahl is 3.7 times more likely to write a good article than Mike Adams. But this doesn't mean anything bad about Mike.",
eph: %{sibling_with: :inline} eph: %{sibling_with: :inline}
} }
@ -111,21 +111,21 @@ defmodule Outlook.InternalTreeTest do
eph: %{sibling_with: :block} eph: %{sibling_with: :block}
} }
] ]
assert InternalTree.partition_text(tree) |> unify_uuids_in_tunits() == [ assert InternalTree.partition_text(tree) |> unify_nids_in_tunits() == [
%InternalNode{ %InternalNode{
name: "p", name: "p",
attributes: %{}, attributes: %{},
type: :element, type: :element,
uuid: "0248aec7-c525-483d-a472-40a34488478d", nid: "0248aec7-c525-483d-a472-40a34488478d",
content: [ content: [
%TranslationUnit{ %TranslationUnit{
status: :untranslated, status: :untranslated,
uuid: @default_uuid, nid: @default_nid,
content: "F. William Engdahl is 3.7 times more likely to write a good article than Mike Adams. " content: "F. William Engdahl is 3.7 times more likely to write a good article than Mike Adams. "
}, },
%TranslationUnit{ %TranslationUnit{
status: :untranslated, status: :untranslated,
uuid: @default_uuid, nid: @default_nid,
content: "But this doesn't mean anything bad about Mike." content: "But this doesn't mean anything bad about Mike."
} }
], ],

View File

@ -1,28 +1,28 @@
defmodule Outlook.InternalTreeTestHelpers do defmodule Outlook.InternalTreeTestHelpers do
@default_uuid "11111111-1111-1111-1111-111111111111" @default_nid "xxxxxx"
alias Outlook.InternalTree.{InternalNode,TranslationUnit} alias Outlook.InternalTree.{InternalNode,TranslationUnit}
@doc "Set uuids to default value to make test results predictable." @doc "Set nids to default value to make test results predictable."
def unify_uuids_in_tunits([ %TranslationUnit{} = node | rest ]) do def unify_nids_in_tunits([ %TranslationUnit{} = node | rest ]) do
[ [
%TranslationUnit{node | %TranslationUnit{node |
uuid: @default_uuid, nid: @default_nid,
content: String.replace(node.content, ~r/ uuid=""/, "") content: String.replace(node.content, ~r/ nid=""/, "")
} }
| unify_uuids_in_tunits(rest) ] | unify_nids_in_tunits(rest) ]
end end
def unify_uuids_in_tunits([ %InternalNode{type: :element} = node | rest ]) do def unify_nids_in_tunits([ %InternalNode{type: :element} = node | rest ]) do
[ %InternalNode{node | [ %InternalNode{node |
content: unify_uuids_in_tunits(node.content) content: unify_nids_in_tunits(node.content)
} }
| unify_uuids_in_tunits(rest) ] | unify_nids_in_tunits(rest) ]
end end
def unify_uuids_in_tunits([ %InternalNode{} = node | rest ]) do def unify_nids_in_tunits([ %InternalNode{} = node | rest ]) do
[ node | unify_uuids_in_tunits(rest) ] [ node | unify_nids_in_tunits(rest) ]
end end
def unify_uuids_in_tunits([]), do: [] def unify_nids_in_tunits([]), do: []
end end