Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/mq.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions lib/mq/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 7 additions & 13 deletions lib/mq/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -280,25 +280,25 @@ 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()")

@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")

@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")
Expand Down Expand Up @@ -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})")
Expand Down Expand Up @@ -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()")

Expand Down
12 changes: 5 additions & 7 deletions test/mq_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()"

Expand All @@ -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"
Expand All @@ -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\")"
Expand Down