Skip to content

Commit 0f6a9cb

Browse files
committed
Added related field equal test
1 parent adc02ef commit 0f6a9cb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

test/validators_test.exs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule ValidatorsTest do
33
use ExUnit.Case, async: true
44
use PropCheck
55

6-
alias Validatex.Validators
6+
alias Validatex.{Validators, Validation}
77

88
@error_msg "ERROR"
99

@@ -67,6 +67,14 @@ defmodule ValidatorsTest do
6767
end
6868
end
6969

70+
property "should verify if input value is equal to related field" do
71+
forall {value, field} <- field() do
72+
value
73+
|> Validators.equal_to?(field, @error_msg)
74+
|> check_result(value, @error_msg)
75+
end
76+
end
77+
7078
property "should verify if input value is true or false" do
7179
forall value <- boolean() do
7280
value |> Validators.true?(@error_msg) |> check_result(value, @error_msg)
@@ -90,7 +98,20 @@ defmodule ValidatorsTest do
9098
end
9199
end
92100

93-
# Generator
101+
# Generators
102+
103+
def field() do
104+
let {value, other} <- {generate_data(), generate_data()} do
105+
let field <-
106+
oneof([
107+
value |> to_string() |> Validation.field(),
108+
Validation.pre_validated_field(value, &to_string/1),
109+
value |> to_string() |> Validation.field() |> Validation.invalidate("Bad field.")
110+
]) do
111+
{Enum.random([value, other]), field}
112+
end
113+
end
114+
end
94115

95116
def generate_data() do
96117
only_string =

0 commit comments

Comments
 (0)