From 833e34410768886f2167a51aba5b1798e15abdd2 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Fri, 26 Jul 2024 08:47:41 +0800 Subject: [PATCH] add tests --- .../test/definition/select-package-with.md | 82 +++++++++++++++++++ .../nixd/test/definition/select-package.md | 82 +++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 nixd/tools/nixd/test/definition/select-package-with.md create mode 100644 nixd/tools/nixd/test/definition/select-package.md diff --git a/nixd/tools/nixd/test/definition/select-package-with.md b/nixd/tools/nixd/test/definition/select-package-with.md new file mode 100644 index 000000000..1ba092ecf --- /dev/null +++ b/nixd/tools/nixd/test/definition/select-package-with.md @@ -0,0 +1,82 @@ +# RUN: nixd --nixpkgs-expr="{ x.y.meta.position = \"/foo:33\"; }" --lit-test < %s | FileCheck %s + +Similar to [package.md](./package.md), but testing that we can do "selection" + "with". +i.e. testing if `with pkgs; [x.y]` works. + +<-- initialize(0) + +```json +{ + "jsonrpc":"2.0", + "id":0, + "method":"initialize", + "params":{ + "processId":123, + "rootPath":"", + "capabilities":{ + }, + "trace":"off" + } +} +``` + + +<-- textDocument/didOpen + +```json +{ + "jsonrpc":"2.0", + "method":"textDocument/didOpen", + "params":{ + "textDocument":{ + "uri":"file:///basic.nix", + "languageId":"nix", + "version":1, + "text":"with pkgs; [x.y]" + } + } +} +``` + +<-- textDocument/definition(2) + + +```json +{ + "jsonrpc":"2.0", + "id":2, + "method":"textDocument/definition", + "params":{ + "textDocument":{ + "uri":"file:///basic.nix" + }, + "position":{ + "line": 0, + "character":15 + } + } +} +``` + +``` + CHECK: "id": 2, +CHECK-NEXT: "jsonrpc": "2.0", +CHECK-NEXT: "result": { +CHECK-NEXT: "range": { +CHECK-NEXT: "end": { +CHECK-NEXT: "character": 0, +CHECK-NEXT: "line": 33 +CHECK-NEXT: }, +CHECK-NEXT: "start": { +CHECK-NEXT: "character": 0, +CHECK-NEXT: "line": 33 +CHECK-NEXT: } +CHECK-NEXT: }, +CHECK-NEXT: "uri": "file:///foo" +CHECK-NEXT: } +``` + + +```json +{"jsonrpc":"2.0","method":"exit"} +``` diff --git a/nixd/tools/nixd/test/definition/select-package.md b/nixd/tools/nixd/test/definition/select-package.md new file mode 100644 index 000000000..ff38fcc6b --- /dev/null +++ b/nixd/tools/nixd/test/definition/select-package.md @@ -0,0 +1,82 @@ +# RUN: nixd --nixpkgs-expr="{ x.meta.position = \"/foo:33\"; }" --lit-test < %s | FileCheck %s + +Similar to [package.md](./package.md), but testing that we can do "selection". +i.e. testing if `pkgs.x` works. + +<-- initialize(0) + +```json +{ + "jsonrpc":"2.0", + "id":0, + "method":"initialize", + "params":{ + "processId":123, + "rootPath":"", + "capabilities":{ + }, + "trace":"off" + } +} +``` + + +<-- textDocument/didOpen + +```json +{ + "jsonrpc":"2.0", + "method":"textDocument/didOpen", + "params":{ + "textDocument":{ + "uri":"file:///basic.nix", + "languageId":"nix", + "version":1, + "text":"pkgs.x" + } + } +} +``` + +<-- textDocument/definition(2) + + +```json +{ + "jsonrpc":"2.0", + "id":2, + "method":"textDocument/definition", + "params":{ + "textDocument":{ + "uri":"file:///basic.nix" + }, + "position":{ + "line": 0, + "character":5 + } + } +} +``` + +``` + CHECK: "id": 2, +CHECK-NEXT: "jsonrpc": "2.0", +CHECK-NEXT: "result": { +CHECK-NEXT: "range": { +CHECK-NEXT: "end": { +CHECK-NEXT: "character": 0, +CHECK-NEXT: "line": 33 +CHECK-NEXT: }, +CHECK-NEXT: "start": { +CHECK-NEXT: "character": 0, +CHECK-NEXT: "line": 33 +CHECK-NEXT: } +CHECK-NEXT: }, +CHECK-NEXT: "uri": "file:///foo" +CHECK-NEXT: } +``` + + +```json +{"jsonrpc":"2.0","method":"exit"} +```