Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Nov 20, 2023
1 parent 9a6c316 commit 2036056
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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 <kbd>C-c C-r C-<return></kbd>.
- Allow using single- or multi-line lambda expressions for `Verb-Map-Request`.
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
71 changes: 38 additions & 33 deletions test/verb-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
5 changes: 3 additions & 2 deletions verb.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
" | "
Expand All @@ -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."
Expand Down

0 comments on commit 2036056

Please sign in to comment.