From 0fd6a48ed2d8198a24f4b147c4e09aad59c7a5d6 Mon Sep 17 00:00:00 2001 From: XeroOl Date: Thu, 28 Mar 2024 22:39:36 -0500 Subject: [PATCH] basic code action test for the (+) -> 0 lint --- test/code-action.fnl | 46 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/test/code-action.fnl b/test/code-action.fnl index fae02ba..22776dd 100644 --- a/test/code-action.fnl +++ b/test/code-action.fnl @@ -1,15 +1,41 @@ -(local _faith (require :faith)) +(local faith (require :faith)) (local {: view} (require :fennel)) (local {: create-client-with-files} (require :test.utils)) +(local {: apply-edits} (require :fennel-ls.utils)) -(fn check [file-contents] - (let [{: self : uri :locations [range]} (create-client-with-files file-contents) - response (self:code-action uri range.range)] -;; (print "hello" (view response)))) - nil)) +(create-client-with-files "(print :hi)") -(fn test-thing [] - (check "(+====)" - "op-with-no-arguments")) +(fn check [file-contents action-I-want-to-take desired-file-contents] + (let [{: self : uri :locations [range] : encoding : text} (create-client-with-files file-contents) + [{:result responses}] (self:code-action uri range.range) + action (accumulate [result nil + _ action (ipairs responses) &until result] + (if (= action.title action-I-want-to-take) + action))] + (if (not action) + (error + (.. "I couldn't find your action \"" action-I-want-to-take "\" in: +" + (view (icollect [_ action (ipairs responses)] + action.title))))) + (let [edits (?. action :edit :changes uri) + edited-text (apply-edits text edits encoding)] + (faith.= desired-file-contents edited-text)))) -{: test-thing} +(fn test-fix-op-no-arguments [] + (check "(let [x (+====)] + (print x))" + "op-with-no-arguments" + "(let [x 0] + (print x))")) + +; (fn test-fix-method-function [] +; (check "(local x {}) +; (fn x:y [a b c] +; (print self a b c))" +; "TO-BE-NAMED" +; "(local x {}) +; (fn x.y [self a b c] +; (print self a b c))")) + +{: test-fix-op-no-arguments}