generated from kommitters/.template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Santiago Botero
committed
Sep 15, 2022
1 parent
94a130e
commit 972814f
Showing
5 changed files
with
17 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
defmodule Kadena.Types.Base64Url do | ||
@moduledoc """ | ||
`Base64Url` struct definition | ||
`Base64Url` struct definition. | ||
""" | ||
|
||
@behaviour Kadena.Types.Spec | ||
|
||
@type t :: %__MODULE__{value: String.t()} | ||
@type t :: %__MODULE__{url: String.t()} | ||
|
||
defstruct [:value] | ||
defstruct [:url] | ||
|
||
@impl true | ||
def new(str) when is_binary(str), do: %__MODULE__{value: str} | ||
def new(str) when is_binary(str), do: %__MODULE__{url: str} | ||
def new(_str), do: {:error, :invalid_string} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
defmodule Kadena.Types.Base16StringTest do | ||
@moduledoc """ | ||
`Base16String` struct definition tests | ||
`Base16String` struct definition tests. | ||
""" | ||
|
||
use ExUnit.Case | ||
|
||
alias Kadena.Types.Base16String | ||
|
||
setup do | ||
%{valid_param: "valid_param", invalid_param: :atom} | ||
end | ||
|
||
test "new/1 with valid params", %{valid_param: valid_param} do | ||
test "new/1 with valid params" do | ||
valid_param = "valid_param" | ||
%Base16String{value: ^valid_param} = Base16String.new(valid_param) | ||
end | ||
|
||
test "new/1 with invalid params", %{invalid_param: invalid_param} do | ||
{:error, :invalid_string} = Base16String.new(invalid_param) | ||
end | ||
|
||
test "new/1 with nil params" do | ||
test "new/1 with invalid params" do | ||
{:error, :invalid_string} = Base16String.new(:atom) | ||
{:error, :invalid_string} = Base16String.new(nil) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
defmodule Kadena.Types.Base64UrlTest do | ||
@moduledoc """ | ||
`Base64Url` struct definition tests | ||
`Base64Url` struct definition tests. | ||
""" | ||
|
||
use ExUnit.Case | ||
|
||
alias Kadena.Types.Base64Url | ||
|
||
setup do | ||
%{valid_param: "valid_param", invalid_param: :atom} | ||
test "new/1 with valid params" do | ||
valid_param = "valid_param" | ||
%Base64Url{url: ^valid_param} = Base64Url.new(valid_param) | ||
end | ||
|
||
test "new/1 with valid params", %{valid_param: valid_param} do | ||
%Base64Url{value: ^valid_param} = Base64Url.new(valid_param) | ||
end | ||
|
||
test "new/1 with invalid params", %{invalid_param: invalid_param} do | ||
{:error, :invalid_string} = Base64Url.new(invalid_param) | ||
end | ||
|
||
test "new/1 with nil params" do | ||
test "new/1 with invalid params" do | ||
{:error, :invalid_string} = Base64Url.new(:atom) | ||
{:error, :invalid_string} = Base64Url.new(nil) | ||
end | ||
end |