branch: elpa/inf-clojure
commit cb2947faec4c2209b9d22cf90af92fb6f0af199e
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Expand test coverage for pure utility functions
Add specs for: inf-clojure--get-feature, inf-clojure--endpoint-p,
inf-clojure--project-name, inf-clojure-chomp,
inf-clojure-remove-subprompts, inf-clojure--nil-string-match-p,
inf-clojure--some, inf-clojure--list-or-nil,
inf-clojure--read-or-nil, inf-clojure-list-completions, and
inf-clojure--string-boundaries.
Test count goes from 23 to 56. Also update the copyright year.
---
test/inf-clojure-tests.el | 111 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 110 insertions(+), 1 deletion(-)
diff --git a/test/inf-clojure-tests.el b/test/inf-clojure-tests.el
index ffe29d75f8..c73b65696d 100644
--- a/test/inf-clojure-tests.el
+++ b/test/inf-clojure-tests.el
@@ -1,6 +1,6 @@
;;; inf-clojure-tests.el --- Tests for Inf-Clojure -*- lexical-binding: t; -*-
;;
-;; Copyright © 2014-2021 Bozhidar Batsov
+;; Copyright © 2014-2025 Bozhidar Batsov
;; Authors: Bozhidar Batsov <[email protected]>
;; Andrea Richiardi <[email protected]>
@@ -193,4 +193,113 @@ is a string\")
(expect clr-arglists :to-equal lein-clr-arglists)
(expect clr-arglists :to-match "Exception"))))
+(describe "inf-clojure--get-feature"
+ (it "returns the feature form for a known repl type and feature"
+ (expect (inf-clojure--get-feature 'clojure 'doc nil)
+ :to-equal "(clojure.repl/doc %s)"))
+ (it "returns nil for a missing feature when no-error is truthy"
+ (expect (inf-clojure--get-feature 'joker 'source t)
+ :to-be nil))
+ (it "signals an error for a missing feature when no-error is nil"
+ (expect (inf-clojure--get-feature 'joker 'source nil)
+ :to-throw)))
+
+(describe "inf-clojure--endpoint-p"
+ (it "returns non-nil for a valid host/port cons"
+ (expect (inf-clojure--endpoint-p '("localhost" . 5555)) :to-be-truthy))
+ (it "returns nil for non-endpoints"
+ (expect (inf-clojure--endpoint-p nil) :to-be nil)
+ (expect (inf-clojure--endpoint-p "localhost:5555") :to-be nil)
+ (expect (inf-clojure--endpoint-p '(5555 . "localhost")) :to-be nil)
+ (expect (inf-clojure--endpoint-p '("localhost" . "5555")) :to-be nil)))
+
+(describe "inf-clojure--project-name"
+ (it "extracts the final path segment"
+ (expect (inf-clojure--project-name "/home/user/projects/my-app")
+ :to-equal "my-app"))
+ (it "handles trailing slashes"
+ (expect (inf-clojure--project-name "/home/user/projects/my-app/")
+ :to-equal "my-app")))
+
+(describe "inf-clojure-chomp"
+ (it "removes a trailing newline"
+ (expect (inf-clojure-chomp "hello\n") :to-equal "hello"))
+ (it "removes only the final trailing newline"
+ (expect (inf-clojure-chomp "hello\n\n\n") :to-equal "hello\n\n"))
+ (it "returns unchanged string when no trailing newline"
+ (expect (inf-clojure-chomp "hello") :to-equal "hello"))
+ (it "preserves internal newlines"
+ (expect (inf-clojure-chomp "hello\nworld\n") :to-equal "hello\nworld")))
+
+(describe "inf-clojure-remove-subprompts"
+ (it "removes subprompts from a string"
+ (expect (inf-clojure-remove-subprompts "foo #_=> bar")
+ :to-equal "foobar"))
+ (it "returns unchanged string when no subprompts"
+ (expect (inf-clojure-remove-subprompts "hello world")
+ :to-equal "hello world")))
+
+(describe "inf-clojure--nil-string-match-p"
+ (it "matches the string nil"
+ (expect (inf-clojure--nil-string-match-p "nil") :to-be-truthy))
+ (it "matches nil with surrounding whitespace"
+ (expect (inf-clojure--nil-string-match-p " nil ") :to-be-truthy)
+ (expect (inf-clojure--nil-string-match-p "nil\n") :to-be-truthy))
+ (it "does not match nil as part of a larger word"
+ (expect (inf-clojure--nil-string-match-p "not-nil") :not :to-be-truthy)
+ (expect (inf-clojure--nil-string-match-p "nilable") :not :to-be-truthy)))
+
+(describe "inf-clojure--some"
+ (it "returns nil for nil"
+ (expect (inf-clojure--some nil) :to-be nil))
+ (it "returns nil for the string nil"
+ (expect (inf-clojure--some "nil") :to-be nil)
+ (expect (inf-clojure--some " nil ") :to-be nil))
+ (it "returns data for non-nil values"
+ (expect (inf-clojure--some "([x] [x y])") :to-equal "([x] [x y])")
+ (expect (inf-clojure--some 42) :to-equal 42)
+ (expect (inf-clojure--some "") :to-equal "")))
+
+(describe "inf-clojure--list-or-nil"
+ (it "returns a list unchanged"
+ (expect (inf-clojure--list-or-nil '("a" "b")) :to-equal '("a" "b")))
+ (it "returns nil for the empty list"
+ ;; Note: nil IS a list in elisp, so (listp nil) => t
+ (expect (inf-clojure--list-or-nil nil) :to-be nil))
+ (it "returns nil for non-list data"
+ (expect (inf-clojure--list-or-nil "string") :to-be nil)
+ (expect (inf-clojure--list-or-nil 42) :to-be nil)))
+
+(describe "inf-clojure--read-or-nil"
+ (it "reads a lisp form from a string"
+ (expect (inf-clojure--read-or-nil "([x] [x y])") :to-equal '([x] [x y])))
+ (it "returns nil for the string nil"
+ (expect (inf-clojure--read-or-nil "nil") :to-be nil))
+ (it "returns nil for nil input"
+ (expect (inf-clojure--read-or-nil nil) :to-be nil))
+ (it "returns nil for unparseable input"
+ (expect (inf-clojure--read-or-nil ")") :to-be nil))
+ (it "reads only the first sexp"
+ (expect (inf-clojure--read-or-nil "(a b) (c d)") :to-equal '(a b))))
+
+(describe "inf-clojure-list-completions"
+ (it "parses a list of completion strings"
+ (expect (inf-clojure-list-completions "(\"defn\" \"def\" \"defmacro\")")
+ :to-equal '("defn" "def" "defmacro")))
+ (it "returns nil for nil response"
+ (expect (inf-clojure-list-completions "nil") :to-be nil))
+ (it "returns nil for non-list response"
+ (expect (inf-clojure-list-completions "42") :to-be nil)))
+
+(describe "inf-clojure--string-boundaries"
+ (it "returns full string bounds when no regexps given"
+ (expect (inf-clojure--string-boundaries "hello" "=>")
+ :to-equal '(0 5 5)))
+ (it "finds prompt position"
+ (expect (inf-clojure--string-boundaries "result\nuser=>" "=>")
+ :to-equal '(0 13 11)))
+ (it "respects beg-regexp and end-regexp"
+ (expect (inf-clojure--string-boundaries "foo(bar)baz" "=>" "(" ")")
+ :to-equal '(3 8 11))))
+
;;; inf-clojure-tests.el ends here