Hey folks,
I’ve written a regular expression for validating input strings. For testing purposes, I want to setup a scenario where a set of test vectors can be automatically injected as input into a new test and match against the regex. I’m currently testing each vector manually. I’ve written the code below. I was also thinking of using a file as opposed to hard coding the strings. Is there a nice way to this? Any feedback is much appreciated.
setup_all do
sample_strings = %{
sample_str1: "test_string",
sample_str2: "cz-dev",
sample_str3: "new___cczdj",
sample_str4: "czar,,,nic",
}
end
defp input_length_valid(inp) do
case String.length(inp) > 100 do
true -> false
false -> true
end
end
test "Regular expression for string - test #1", sample_strings
do
assert sample_strings.sample_str3
|> String.replace("_", "-")
|> String.match?( ~r/^(my-regex)*$/)
assert sample_strings.sample_str3 |> input_length_valid() == true
end
test "Regular expression for string - test #2", sample_strings
do
assert sample_strings.sample_str2
|> String.replace("_", "-")
|> String.match?( ~r/^(my-regex)*$/)
assert sample_strings.sample_str2 |> input_length_valid() == true
end