diff --git a/lib/mq.ex b/lib/mq.ex index b43a9eb..722c925 100644 --- a/lib/mq.ex +++ b/lib/mq.ex @@ -232,7 +232,7 @@ defmodule Mq do defdelegate length(query), to: Query defdelegate len(query), to: Query defdelegate utf8bytelen(query), to: Query - defdelegate add(query), to: Query + defdelegate add(query, other), to: Query defdelegate first(query), to: Query defdelegate last(query), to: Query defdelegate empty(query), to: Query @@ -263,8 +263,6 @@ defmodule Mq do defdelegate rtrim(query), to: Query defdelegate downcase(query), to: Query defdelegate upcase(query), to: Query - defdelegate ascii_downcase(query), to: Query - defdelegate ascii_upcase(query), to: Query defdelegate explode(query), to: Query defdelegate implode(query), to: Query defdelegate url_encode(query), to: Query diff --git a/lib/mq/filter.ex b/lib/mq/filter.ex index 1df294d..d6a37d5 100644 --- a/lib/mq/filter.ex +++ b/lib/mq/filter.ex @@ -89,22 +89,16 @@ defmodule Mq.Filter do # Value transforms usable in filter context @doc "The length of the current value." - def length, do: new("length") - - @doc "Lowercase the current value (ASCII only)." - def ascii_downcase, do: new("ascii_downcase()") - - @doc "Uppercase the current value (ASCII only)." - def ascii_upcase, do: new("ascii_upcase()") + def length, do: new("len()") @doc "Trim whitespace from the current value." def trim, do: new("trim()") @doc "Match empty nodes." - def empty, do: new("empty") + def empty, do: new("is_empty()") - @doc "Add/concatenate the current value." - def add, do: new("add") + @doc "Add/concatenate `other` to the current value." + def add(other), do: new("add(#{qv(other)})") # Boolean combinators diff --git a/lib/mq/query.ex b/lib/mq/query.ex index e4ca961..6616137 100644 --- a/lib/mq/query.ex +++ b/lib/mq/query.ex @@ -280,7 +280,7 @@ defmodule Mq.Query do # Collection operations @doc "Return the length of the current value." - def length(%__MODULE__{} = q), do: pipe_expr(q, "length") + def length(%__MODULE__{} = q), do: pipe_expr(q, "len()") @doc "Return the byte length of the current value." def len(%__MODULE__{} = q), do: pipe_expr(q, "len()") @@ -288,8 +288,8 @@ defmodule Mq.Query do @doc "Return the UTF-8 byte length of the current value." def utf8bytelen(%__MODULE__{} = q), do: pipe_expr(q, "utf8bytelen()") - @doc "Add/concatenate the current value." - def add(%__MODULE__{} = q), do: pipe_expr(q, "add") + @doc "Add/concatenate `other` to the current value." + def add(%__MODULE__{} = q, other), do: pipe_expr(q, "add(#{inspect(other)})") @doc "Return the first element." def first(%__MODULE__{} = q), do: pipe_expr(q, "first") @@ -297,8 +297,8 @@ defmodule Mq.Query do @doc "Return the last element." def last(%__MODULE__{} = q), do: pipe_expr(q, "last") - @doc "Emit nothing (empty result)." - def empty(%__MODULE__{} = q), do: pipe_expr(q, "empty") + @doc "Check whether the current value is empty." + def empty(%__MODULE__{} = q), do: pipe_expr(q, "is_empty()") @doc "Reverse the current value." def reverse(%__MODULE__{} = q), do: pipe_expr(q, "reverse") @@ -334,10 +334,10 @@ defmodule Mq.Query do def join(%__MODULE__{} = q, sep), do: pipe_expr(q, "join(#{inspect(sep)})") @doc "Select the nth element (0-based)." - def nth(%__MODULE__{} = q, n), do: pipe_expr(q, "nth(#{n})") + def nth(%__MODULE__{} = q, n), do: pipe_expr(q, "get(#{n})") @doc "Limit output to `n` elements." - def limit(%__MODULE__{} = q, n), do: pipe_expr(q, "limit(#{n})") + def limit(%__MODULE__{} = q, n), do: pipe_expr(q, "take(#{n})") @doc "Take a range of `n` elements." def range(%__MODULE__{} = q, n), do: pipe_expr(q, "range(#{n})") @@ -376,12 +376,6 @@ defmodule Mq.Query do @doc "Convert to uppercase (Unicode-aware)." def upcase(%__MODULE__{} = q), do: pipe_expr(q, "upcase()") - @doc "Convert to lowercase (ASCII only)." - def ascii_downcase(%__MODULE__{} = q), do: pipe_expr(q, "ascii_downcase()") - - @doc "Convert to uppercase (ASCII only)." - def ascii_upcase(%__MODULE__{} = q), do: pipe_expr(q, "ascii_upcase()") - @doc "Explode a string into codepoints." def explode(%__MODULE__{} = q), do: pipe_expr(q, "explode()") diff --git a/test/mq_test.exs b/test/mq_test.exs index 0064ab1..4f86167 100644 --- a/test/mq_test.exs +++ b/test/mq_test.exs @@ -297,8 +297,6 @@ defmodule MqTest do assert to_string(Query.text() |> Query.rtrim()) == ".text | rtrim()" assert to_string(Query.text() |> Query.downcase()) == ".text | downcase()" assert to_string(Query.text() |> Query.upcase()) == ".text | upcase()" - assert to_string(Query.text() |> Query.ascii_downcase()) == ".text | ascii_downcase()" - assert to_string(Query.text() |> Query.ascii_upcase()) == ".text | ascii_upcase()" assert to_string(Query.text() |> Query.len()) == ".text | len()" assert to_string(Query.text() |> Query.utf8bytelen()) == ".text | utf8bytelen()" @@ -316,11 +314,11 @@ defmodule MqTest do end test "collection operations" do - assert to_string(Query.list() |> Query.length()) == ".[] | length" - assert to_string(Query.list() |> Query.add()) == ".[] | add" + assert to_string(Query.list() |> Query.length()) == ".[] | len()" + assert to_string(Query.list() |> Query.add("x")) == ".[] | add(\"x\")" assert to_string(Query.list() |> Query.first()) == ".[] | first" assert to_string(Query.list() |> Query.last()) == ".[] | last" - assert to_string(Query.list() |> Query.empty()) == ".[] | empty" + assert to_string(Query.list() |> Query.empty()) == ".[] | is_empty()" assert to_string(Query.list() |> Query.reverse()) == ".[] | reverse" assert to_string(Query.list() |> Query.sort()) == ".[] | sort" assert to_string(Query.list() |> Query.compact()) == ".[] | compact" @@ -330,8 +328,8 @@ defmodule MqTest do assert to_string(Query.list() |> Query.values()) == ".[] | values" assert to_string(Query.list() |> Query.entries()) == ".[] | entries" assert to_string(Query.list() |> Query.children()) == ".[] | .children" - assert to_string(Query.h2() |> Query.nth(2)) == ".h2 | nth(2)" - assert to_string(Query.h2() |> Query.limit(5)) == ".h2 | limit(5)" + assert to_string(Query.h2() |> Query.nth(2)) == ".h2 | get(2)" + assert to_string(Query.h2() |> Query.limit(5)) == ".h2 | take(5)" assert to_string(Query.h2() |> Query.range(3)) == ".h2 | range(3)" assert to_string(Query.list() |> Query.join(", ")) == ".[] | join(\", \")" assert to_string(Query.list() |> Query.del("item")) == ".[] | del(\"item\")"