From 203605638455fd1057bd808485280c1b87465479 Mon Sep 17 00:00:00 2001 From: Federico Tedin Date: Mon, 20 Nov 2023 19:06:55 +0100 Subject: [PATCH] Add tests --- CHANGELOG.md | 2 +- Makefile | 4 +-- test/verb-test.el | 71 +++++++++++++++++++++++++---------------------- verb.el | 5 ++-- 4 files changed, 44 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 792be8a..951583c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Verb Changelog ## **main** (MELPA) - Fixed LF being used instead of CRLF in multipart boundaries. -- When sending a request, include the HTTP method in the message displayed. +- When sending a request, include the HTTP method and path in the message displayed on the minibuffer. - The `verb-json-get` function now accepts negative integer arguments for accessing list elements. - Changed default binding of `verb-send-request-on-point-no-window` to C-c C-r C-. - Allow using single- or multi-line lambda expressions for `Verb-Map-Request`. diff --git a/Makefile b/Makefile index 0bb595e..b5272b8 100644 --- a/Makefile +++ b/Makefile @@ -93,8 +93,8 @@ update: run: ## Run emacs -Q with the working version of verb.el loaded. run: clean server-bg - make run-internal; \ + make run-noserver; \ make server-kill -run-internal: +run-noserver: FONT_SIZE=$(FONT_SIZE) $(EMACS) -Q -L . --load test/init.el diff --git a/test/verb-test.el b/test/verb-test.el index 1c8c764..3ed10a5 100644 --- a/test/verb-test.el +++ b/test/verb-test.el @@ -615,39 +615,44 @@ :type 'verb-empty-spec)) (ert-deftest test-response-header-line-string () - (should (string= (verb--response-header-line-string - (verb-response - :status "test" - :duration 1.123 - :headers '(("Content-Type" . "hello") - ("Content-Length" . "1")) - :body-bytes 999)) - "test | 1.123s | hello | 1 byte")) - - (should (string= (verb--response-header-line-string - (verb-response - :status "test" - :duration 1.123 - :headers '(("Content-Length" . "2024")) - :body-bytes 999)) - (if (< emacs-major-version 27) - "test | 1.123s | - | 2.0k bytes" - "test | 1.123s | - | 2k bytes"))) - - (should (string= (verb--response-header-line-string - (verb-response - :status "test" - :duration 1.123 - :headers '(("Content-Type" . "hello")) - :body-bytes 999)) - "test | 1.123s | hello | 999 bytes")) - - (should (string= (verb--response-header-line-string - (verb-response - :status nil - :duration 1.123 - :headers nil)) - "No Response | 1.123s | - | 0 bytes"))) + (let ((req (text-as-spec "get /hello"))) + (should (string= (verb--response-header-line-string + (verb-response + :status "test" + :duration 1.123 + :headers '(("Content-Type" . "hello") + ("Content-Length" . "1")) + :body-bytes 999 + :request req)) + "test | 1.123s | hello | 1 byte | /hello")) + + (should (string= (verb--response-header-line-string + (verb-response + :status "test" + :duration 1.123 + :headers '(("Content-Length" . "2024")) + :body-bytes 999 + :request req)) + (if (< emacs-major-version 27) + "test | 1.123s | - | 2.0k bytes | /hello" + "test | 1.123s | - | 2k bytes | /hello"))) + + (should (string= (verb--response-header-line-string + (verb-response + :status "test" + :duration 1.123 + :headers '(("Content-Type" . "hello")) + :body-bytes 999 + :request req)) + "test | 1.123s | hello | 999 bytes | /hello")) + + (should (string= (verb--response-header-line-string + (verb-response + :status nil + :duration 1.123 + :headers nil + :request req)) + "No Response | 1.123s | - | 0 bytes | /hello")))) (ert-deftest test-request-spec-from-text-error () (should-error (text-as-spec "foobar example.com"))) diff --git a/verb.el b/verb.el index 4e46020..e3bb05f 100644 --- a/verb.el +++ b/verb.el @@ -1617,7 +1617,7 @@ non-nil, do not add the command to the kill ring." (elapsed (oref response duration)) (headers (oref response headers)) (bytes (oref response body-bytes)) - (path (oref (oref (oref response request) url) filename))) + (path (car (url-path-and-query (oref (oref response request) url))))) (concat (or status-line "No Response") " | " @@ -1633,7 +1633,8 @@ non-nil, do not add the command to the kill ring." (format " | %s byte%s" (file-size-human-readable value) (if (= value 1) "" "s"))) - " | " path))) + (when (not (string-empty-p path)) + (format " | %s" path))))) (cl-defmethod verb-request-spec-url-to-string ((rs verb-request-spec)) "Return RS's url member as a string if it is non-nil."