From 6702d11ec4ffa9b4a03c659cf4ba8b63b07902cf Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 4 Mar 2022 09:38:31 -0600 Subject: [PATCH] add unit tests for tags.scm queries (#27) --- package-lock.json | 14 +++++++------- package.json | 2 +- test/tags/module.ex | 31 +++++++++++++++++++++++++++++++ test/tags/protocol.ex | 21 +++++++++++++++++++++ 4 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 test/tags/module.ex create mode 100644 test/tags/protocol.ex diff --git a/package-lock.json b/package-lock.json index d8b76f7..23ccd63 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ }, "devDependencies": { "prettier": "^2.3.2", - "tree-sitter-cli": "^0.20.1" + "tree-sitter-cli": "^0.20.6" } }, "node_modules/nan": { @@ -34,9 +34,9 @@ } }, "node_modules/tree-sitter-cli": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.1.tgz", - "integrity": "sha512-I0Gp4ThRp39TDnBAaZKiogvoE85MSeL6/ILZMXbzeEo8hUsudpVhEHRE4CU+Bk5QUaiMiDkD+ZIL3gT2zZ++wg==", + "version": "0.20.6", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.6.tgz", + "integrity": "sha512-tjbAeuGSMhco/EnsThjWkQbDIYMDmdkWsTPsa/NJAW7bjaki9P7oM9TkLxfdlnm4LXd1wR5wVSM2/RTLtZbm6A==", "dev": true, "hasInstallScript": true, "bin": { @@ -57,9 +57,9 @@ "dev": true }, "tree-sitter-cli": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.1.tgz", - "integrity": "sha512-I0Gp4ThRp39TDnBAaZKiogvoE85MSeL6/ILZMXbzeEo8hUsudpVhEHRE4CU+Bk5QUaiMiDkD+ZIL3gT2zZ++wg==", + "version": "0.20.6", + "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.20.6.tgz", + "integrity": "sha512-tjbAeuGSMhco/EnsThjWkQbDIYMDmdkWsTPsa/NJAW7bjaki9P7oM9TkLxfdlnm4LXd1wR5wVSM2/RTLtZbm6A==", "dev": true } } diff --git a/package.json b/package.json index 51bba35..878d0fc 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "devDependencies": { "prettier": "^2.3.2", - "tree-sitter-cli": "^0.20.1" + "tree-sitter-cli": "^0.20.6" }, "tree-sitter": [ { diff --git a/test/tags/module.ex b/test/tags/module.ex new file mode 100644 index 0000000..e9f4cf2 --- /dev/null +++ b/test/tags/module.ex @@ -0,0 +1,31 @@ +defmodule Foo.Bar.Baz do + # ^ definition.module + # ^ definition.module + # ^ definition.module + + def init(arg) do + # ^ definition.function + state = + arg + |> map(&(&1 * 2)) + # ^ reference.call + |> map(&(&1 + 1)) + # ^ reference.call + + {:ok, arg} + end + + def map(list, fun, acc \\ []) + # ^ definition.function + + def map([head | rest], fun, acc) do + # ^ definition.function + map(rest, fun, [fun.(head) | acc]) + # <- reference.call + end + + def map([], _fun, acc), do: Enum.reverse(acc) + # ^ definition.function + # ^ reference.module + # ^ reference.call +end diff --git a/test/tags/protocol.ex b/test/tags/protocol.ex new file mode 100644 index 0000000..62acd87 --- /dev/null +++ b/test/tags/protocol.ex @@ -0,0 +1,21 @@ +defprotocol Countable do + # ^ definition.module + def count(data) + # ^ definition.function +end + +defimpl Countable, for: Binary do + # ^ reference.module + # ^ reference.module + def count(binary), do: byte_size(binary) + # ^ definition.function + # ^ reference.call +end + +defimpl Countable, for: List do + # ^ reference.module + # ^ reference.module + def count(list), do: length(list) + # ^ definition.function + # ^ reference.call +end