aboutsummaryrefslogtreecommitdiff
path: root/test/projectile-test.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@toptal.com>2026-04-25 23:02:52 +0100
committerBozhidar Batsov <bozhidar@toptal.com>2026-04-25 23:02:52 +0100
commit2b49c82126c12180bbabbd929698dc35192b1a75 (patch)
tree2ec239dc4e1439aa225d23408741e9239002e0b1 /test/projectile-test.el
parent4928cbf3306b4699f6c4a7b63f934b647d545c00 (diff)
Split the dirconfig parser into a pure line classifier
The old parser walked a temp buffer with point and pcase'd on char-after, mixing IO, prefix dispatch, and bucket bookkeeping into one function. Pull the dispatch out into projectile--dirconfig-classify-line, which takes a string and returns a (BUCKET . VALUE) tag. The pure function is unit-testable without buffer plumbing, the IO wrapper shrinks to a one-shot read + dispatch, and the awkward (pcase ((pred (lambda ...)) ...)) for the comment-prefix check becomes a straightforward cond. No behavior change.
Diffstat (limited to 'test/projectile-test.el')
-rw-r--r--test/projectile-test.el31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/projectile-test.el b/test/projectile-test.el
index 30ddaa3..fc6116d 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -527,6 +527,37 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'.
(let ((projectile-globally-unignored-files '("path/unignored-file")))
(expect (projectile-add-unignored nil nil '("file")) :to-equal '("file" "path/unignored-file")))))))
+(describe "projectile--dirconfig-classify-line"
+ (it "returns nil for blank or whitespace-only lines"
+ (expect (projectile--dirconfig-classify-line "") :to-be nil)
+ (expect (projectile--dirconfig-classify-line " ") :to-be nil)
+ (expect (projectile--dirconfig-classify-line "\t") :to-be nil))
+ (it "classifies prefix dispatches"
+ (expect (projectile--dirconfig-classify-line "+/src")
+ :to-equal '(:keep . "/src"))
+ (expect (projectile--dirconfig-classify-line "-/build")
+ :to-equal '(:ignore . "/build"))
+ (expect (projectile--dirconfig-classify-line "!/build/keepme")
+ :to-equal '(:ensure . "/build/keepme")))
+ (it "treats prefix-less lines as ignore for backward compatibility"
+ (expect (projectile--dirconfig-classify-line "stale-pattern")
+ :to-equal '(:ignore . "stale-pattern")))
+ (it "skips leading whitespace before dispatch"
+ (expect (projectile--dirconfig-classify-line " -indented")
+ :to-equal '(:ignore . "indented"))
+ (expect (projectile--dirconfig-classify-line "\t+keep")
+ :to-equal '(:keep . "keep")))
+ (it "honors the comment prefix when configured"
+ (let ((projectile-dirconfig-comment-prefix ?#))
+ (expect (projectile--dirconfig-classify-line "# a comment")
+ :to-equal '(:comment))
+ (expect (projectile--dirconfig-classify-line " # indented comment")
+ :to-equal '(:comment)))
+ ;; Without a comment prefix, # is just a regular character.
+ (let ((projectile-dirconfig-comment-prefix nil))
+ (expect (projectile--dirconfig-classify-line "#may-be-a-comment")
+ :to-equal '(:ignore . "#may-be-a-comment")))))
+
(describe "projectile-parse-dirconfig-file"
(it "parses dirconfig and returns directories to ignore and keep"
(spy-on 'file-exists-p :and-return-value t)