From 3f4a0d5370ae6c34afe180df96add3b8522f4af1 Mon Sep 17 00:00:00 2001 From: mattkae Date: Wed, 11 May 2022 09:23:58 -0400 Subject: initial commit --- .../server/test/elisp/irony-cdb-json.el | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el (limited to 'elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el') diff --git a/elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el b/elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el new file mode 100644 index 0000000..a810dae --- /dev/null +++ b/elpa/irony-20220110.849/server/test/elisp/irony-cdb-json.el @@ -0,0 +1,87 @@ +;; -*-no-byte-compile: t; -*- +(load + (concat (file-name-directory (or load-file-name buffer-file-name)) + "test-config")) + +(require 'irony-cdb-json) +(require 'cl-lib) + +(defconst irony-cdb/compile-command + '((file . "../src/file.cc") + (directory . "/home/user/project/build") + (command . "/usr/bin/clang++ -DSOMEDEF=1 -c -o file.o /home/user/project/src/file.cc"))) + +(ert-deftest cdb/parse/simple/path-is-absolute () + (should + (equal "/home/user/project/src/file.cc" + (nth 0 (irony-cdb-json--transform-compile-command + irony-cdb/compile-command))))) + +(ert-deftest cdb/parse/simple/compile-options () + (should + (equal '("-DSOMEDEF=1") + (nth 1 (irony-cdb-json--transform-compile-command + irony-cdb/compile-command))))) + +(ert-deftest cdb/parse/simple/invocation-directory () + (should + (equal "/home/user/project/build" + (nth 2 (irony-cdb-json--transform-compile-command + irony-cdb/compile-command))))) + +(ert-deftest cdb/choose-closest-path/chooses-closest () + (should + (equal "/tmp/a/cdb" + (irony-cdb--choose-closest-path "/tmp/a/1" + '("/tmp/a/cdb" "/tmp/cdb"))))) + +(ert-deftest cdb/choose-closest-path/chooses-closest2 () + (should + (equal "/tmp/a/cdb" + (irony-cdb--choose-closest-path "/tmp/a/1" + '("/tmp/cdb" "/tmp/a/cdb"))))) + +(ert-deftest cdb/choose-closest-path/prefers-deeper () + (should + (equal "/tmp/a/build/cdb" + (irony-cdb--choose-closest-path "/tmp/a/1" + '("/tmp/a/build/cdb" "/tmp/cdb"))))) + +(ert-deftest cdb/choose-closest-path/prefers-deeper2 () + (should + (equal "/tmp/a/build/cdb" + (irony-cdb--choose-closest-path "/tmp/a/1" + '("/tmp/cdb" "/tmp/a/build/cdb"))))) + +(ert-deftest cdb/choose-closest-path/will-survive-garbage () + (should + (equal nil + (irony-cdb--choose-closest-path "/tmp/a/1" + 'ordures)))) + +; http://endlessparentheses.com/understanding-letf-and-how-it-replaces-flet.html +(ert-deftest cdb/locate-db/choose-among-candidates () + (should + (equal "/foo/build/cdb" + (cl-letf (((symbol-function 'locate-dominating-file) + (lambda (file name) + (cond + ((string= name "./cdb") "/") ; found /cdb + ((string= name "build/cdb") "/foo/") ; found /foo/build/cdb + )))) + (irony-cdb--locate-dominating-file-with-dirs "/foo/bar/qux.cpp" + "cdb" + '("." "build" "out/x86_64")))))) + +(ert-deftest cdb/locate-dominating-file-with-dirs/children-first () + (should + (equal "/tmp/foo/bar/out/x86_64/cdb" + (cl-letf (((symbol-function 'locate-dominating-file) + (lambda (file name) + (cond + ((string= name "./cdb") "/tmp/foo/") ; found /tmp/foo/cdb + ((string= name "out/x86_64/cdb") "/tmp/foo/bar/") ;found /tmp/foo/bar/out/x86_64/cdb + )))) + (irony-cdb--locate-dominating-file-with-dirs "/tmp/foo/bar/qux.cpp" + "cdb" + '("." "out/x86_64" )))))) -- cgit v1.2.1