Skip to content

Commit

Permalink
Address failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NduatiK committed Nov 15, 2024
1 parent 7f154b6 commit 4081a3d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/live_view_native/swiftui/rules_parser/expressions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Expressions do
end

def key_value_pairs(opts \\ []) do
wrap(comma_separated_list(key_value_pair(opts), opts))
comma_separated_list(key_value_pair(opts), opts)
end
end
2 changes: 1 addition & 1 deletion lib/live_view_native/swiftui/rules_parser/modifiers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser.Modifiers do

defcombinator(
:key_value_list,
enclosed("[", key_value_pairs(generate_error?: true, allow_empty?: false), "]",
enclosed("[", wrap(key_value_pairs(generate_error?: true, allow_empty?: false)), "]",
allow_empty?: false,
error_parser: non_whitespace(also_ignore: String.to_charlist(")],"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ defmodule LiveViewNative.SwiftUI.RulesParser.PostProcessors do

def event_to_ast(rest, [opts, name], context, {line, _}, _byte_offset) do
annotations = context_to_annotation(context.context, line)
{rest, [{:__event__, annotations, [name, opts]}], context}
{rest, [{:__event__, annotations, [name] ++ List.wrap(opts)}], context}
end

def add_annotations(rest, parts, context, {line, _}, _byte_offset) do
Expand Down
31 changes: 18 additions & 13 deletions test/live_view_native/swiftui/rules_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
input = "foregroundStyle(Color(.displayP3, red: 0.4627, green: 0.8392, blue: 1.0).opacity(0.25))"

output =
{:foregroundStyle, [], [{:., [], [{:Color, [], [{:., [], [nil, :displayP3]}, {:red, 0.4627}, {:green, 0.8392}, {:blue, 1.0}]}, {:opacity, [], [0.25]}]}]}
{:foregroundStyle, [], [{:., [], [{:Color, [], [
{:., [], [nil, :displayP3]},
{:red, 0.4627},
{:green, 0.8392},
{:blue, 1.0}
]}, {:opacity, [], [0.25]}]}]}

assert parse(input) == output
end
Expand All @@ -147,15 +152,15 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
assert parse(input) == output

input = ~s/Gradient(colors: [0, 1, 2])/
output = {:Gradient, [], [[colors: [0, 1, 2]]]}
output = {:Gradient, [], [{:colors, [0, 1, 2]}]}
assert parse(input) == output

input = ~s/Gradient(colors: [Color.red, Color.blue])/
output = {:Gradient, [], [[colors: [{:., [], [:Color, :red]}, {:., [], [:Color, :blue]}]]]}
output = {:Gradient, [], [{:colors, [{:., [], [:Color, :red]}, {:., [], [:Color, :blue]}]}]}
assert parse(input) == output

input = ~s/Gradient(colors: ["red", "blue"])/
output = {:Gradient, [], [[colors: ["red", "blue"]]]}
output = {:Gradient, [], [{:colors, ["red", "blue"]}]}
assert parse(input) == output
end

Expand Down Expand Up @@ -362,7 +367,7 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
describe "helper functions" do
test "event" do
input = ~s{searchable(change: event("search-event", throttle: 10_000))}
output = {:searchable, [], [{:change, {:__event__, [], ["search-event", [throttle: 10_000]]}}]}
output = {:searchable, [], [{:change, {:__event__, [], ["search-event", {:throttle, 10_000}]}}]}

assert parse(input) == output
end
Expand Down Expand Up @@ -569,8 +574,8 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
assert String.trim(error.description) == error_prefix
end

test "invalid keyword pair: invalid value" do
input = "abc(def: 11, b: [lineWidth: 1lineWidth])"
test "invalid number" do
input = "abc(def: 11, b: 1lineWidth)"

error =
assert_raise SyntaxError, fn ->
Expand All @@ -581,8 +586,8 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
"""
Unsupported input:
|
1 | abc(def: 11, b: [lineWidth: 1lineWidth])
| ^^^^^^^^^
1 | abc(def: 11, b: 1lineWidth)
| ^^^^^^^^^
|
Invalid suffix on number
Expand All @@ -592,8 +597,8 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
assert String.trim(error.description) == error_prefix
end

test "invalid keyword pair: invalid value (2)" do
input = "abc(def: 11, b: [lineWidth: :1])"
test "invalid atom" do
input = "abc(def: 11, b: :1)"

error =
assert_raise SyntaxError, fn ->
Expand All @@ -604,8 +609,8 @@ defmodule LiveViewNative.SwiftUI.RulesParserTest do
"""
Unsupported input:
|
1 | abc(def: 11, b: [lineWidth: :1])
| ^
1 | abc(def: 11, b: :1)
| ^
|
Expected an atom, but got ‘1’
Expand Down

0 comments on commit 4081a3d

Please sign in to comment.