From 7fe702be160a63661e9a896378b9b93f2b4db59e Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Wed, 28 Apr 2021 08:39:12 -0400 Subject: [PATCH 1/4] Support Range in :values --- lib/surface/api.ex | 6 ++++-- test/api_test.exs | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/surface/api.ex b/lib/surface/api.ex index 1f01f222..e9690fee 100644 --- a/lib/surface/api.ex +++ b/lib/surface/api.ex @@ -421,9 +421,11 @@ defmodule Surface.API do end defp validate_opt(_func, _name, _type, _opts, :values, value, _caller) - when not is_list(value) do + when not is_list(value) and not is_struct(value, Range) do {:error, - "invalid value for option :values. Expected a list of values, got: #{inspect(value)}"} + "invalid value for option :values. Expected a list of values or a Range, got: #{ + inspect(value) + }"} end defp validate_opt(:prop, _name, _type, _opts, :accumulate, value, _caller) diff --git a/test/api_test.exs b/test/api_test.exs index a5e8ceb6..89223c1d 100644 --- a/test/api_test.exs +++ b/test/api_test.exs @@ -50,6 +50,12 @@ defmodule Surface.APITest do assert_raise(CompileError, message, fn -> eval(code) end) end + test "validate :values when using a range" do + code = "prop age, :integer, values: 1..100" + + {:ok, _module} = eval(code) + end + test "validate :as in slot" do code = "slot label, as: \"default_label\"" message = ~r/invalid value for option :as in slot. Expected an atom, got: \"default_label\"/ From 7b7426ca48ce04f8374107ca8d81c0d21d912800 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Wed, 28 Apr 2021 09:02:17 -0400 Subject: [PATCH 2/4] fix tests, change minimum supported elixir version --- .github/workflows/ci.yml | 9 --------- mix.exs | 2 +- test/api_test.exs | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64f70a43..5c348f3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,15 +14,6 @@ jobs: fail-fast: false matrix: include: - - elixir: 1.8.2 - otp: 21.3.8.17 - - elixir: 1.9.4 - otp: 21.3.8.17 - warnings_as_errors: true # not 1.10 as its --warnigs-as-errors has bugs https://github.com/elixir-lang/elixir/issues/10073 - - elixir: 1.10.4 - otp: 21.3.8.17 - - elixir: 1.10.4 - otp: 23.1.1 - elixir: 1.11.1 otp: 21.3.8.17 - elixir: 1.11.4 diff --git a/mix.exs b/mix.exs index e508d4b0..2fb833bb 100644 --- a/mix.exs +++ b/mix.exs @@ -7,7 +7,7 @@ defmodule Surface.MixProject do [ app: :surface, version: @version, - elixir: "~> 1.8", + elixir: "~> 1.11", description: "A component based library for Phoenix LiveView", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix] ++ Mix.compilers(), diff --git a/test/api_test.exs b/test/api_test.exs index 89223c1d..eabf1753 100644 --- a/test/api_test.exs +++ b/test/api_test.exs @@ -45,7 +45,7 @@ defmodule Surface.APITest do test "validate :values" do code = "prop label, :string, values: 1" - message = ~r/invalid value for option :values. Expected a list of values, got: 1/ + message = ~r/invalid value for option :values. Expected a list of values or a Range, got: 1/ assert_raise(CompileError, message, fn -> eval(code) end) end From a9573287a62a237f8e1da8f97d6a3ddae075dc81 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Fri, 30 Apr 2021 13:03:01 -0400 Subject: [PATCH 3/4] expand test --- test/api_test.exs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/api_test.exs b/test/api_test.exs index eabf1753..4f726c8d 100644 --- a/test/api_test.exs +++ b/test/api_test.exs @@ -51,7 +51,10 @@ defmodule Surface.APITest do end test "validate :values when using a range" do - code = "prop age, :integer, values: 1..100" + code = """ + prop age, :integer, values: 1..100 + data items, :integer, values: 1..3 + """ {:ok, _module} = eval(code) end From 35e0ffa035c20caf41abff1cdb7c19263604c0d2 Mon Sep 17 00:00:00 2001 From: Dave Lucia Date: Sun, 2 May 2021 08:34:14 -0400 Subject: [PATCH 4/4] formatter --- test/components/form/label_test.exs | 14 ++++---------- test/components/link_test.exs | 3 +-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/test/components/form/label_test.exs b/test/components/form/label_test.exs index 849787aa..23161b3a 100644 --- a/test/components/form/label_test.exs +++ b/test/components/form/label_test.exs @@ -98,17 +98,13 @@ defmodule Surface.Components.Form.LabelTest do html = render_surface(do: ~H[