You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
3.0 KiB
EmacsLisp
80 lines
3.0 KiB
EmacsLisp
#!/bin/sh
|
|
":"; exec emacs -Q -batch -l ert -l "$0" -f ert-run-tests-batch-and-exit
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;;;;;;;;;;;;;;;;;;;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(setq cwd default-directory)
|
|
|
|
(defmacro with-testing-buffer (file-name &rest body)
|
|
"Execute 'body using a buffer with the contents of file 'file-name,
|
|
killing the buffer afterwards"
|
|
(list 'let (list (list 'buffer
|
|
(list 'find-file
|
|
(list 'format "%s/test/testdata/%s" cwd file-name))))
|
|
(let ((to-execute (list 'with-current-buffer 'buffer)))
|
|
(append to-execute body (list '(kill-buffer buffer))))))
|
|
|
|
(load (format "%sstomp.el" default-directory) nil t)
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;;;;;;;;;;;;;; START UNIT TESTS ;;;;;;;;;;;;;;;;;;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(ert-deftest can-read-simple-frame ()
|
|
"Can read a simple message with headers and content"
|
|
(with-testing-buffer
|
|
"stomp_frame.txt"
|
|
(setq recieved (stomp-read-frame (current-buffer)))
|
|
|
|
(should (equal (alist-get 'command recieved) "BLA"))
|
|
(should (equal (alist-get 'headers recieved)
|
|
'(("ok" . "bye")
|
|
("some-header" . "value"))))
|
|
(should (equal (alist-get 'content recieved) "content\n"))))
|
|
|
|
(ert-deftest can-read-carriage-return-frame ()
|
|
"Can read a simple frame with headers and content, containing carriage returns"
|
|
(with-testing-buffer
|
|
"stomp_frame_cr.txt"
|
|
(setq recieved (stomp-read-frame (current-buffer)))
|
|
|
|
(should (equal (alist-get 'command recieved) "BLA"))
|
|
(should (equal (alist-get 'headers recieved)
|
|
'(("ok" . "bye")
|
|
("some-header" . "value"))))
|
|
(should (equal (alist-get 'content recieved) "content\r\n"))))
|
|
|
|
(ert-deftest can-read-fixed-length-frame ()
|
|
"Can read a frame that has a content-length header correctly"
|
|
(with-testing-buffer
|
|
"content_length_frame.txt"
|
|
(setq recieved (stomp-read-frame (current-buffer)))
|
|
|
|
(should (equal (alist-get 'command recieved) "MESSAGE"))
|
|
(should (equal (alist-get 'headers recieved)
|
|
'(("destination" . "/banana/kiwi")
|
|
("content-length" . "11"))))
|
|
(should (equal (alist-get 'content recieved) "jwe\u0000jsiwli\u0000"))))
|
|
|
|
(ert-deftest can-delete-one-frame ()
|
|
"Can delete the topmost frame in a buffer"
|
|
(with-testing-buffer
|
|
"multiple_frames.txt"
|
|
(let ((buffer (current-buffer)))
|
|
(stomp-delete-frame buffer nil)
|
|
(with-current-buffer buffer
|
|
(should (equal (buffer-string) "BLA\nsome-header:value\nok:bye\n\ncontent\n\u0000\n"))))))
|
|
|
|
(ert-deftest can-compose-frame ()
|
|
"Can compose a valid STOMP frame from a LISP datastructure"
|
|
(let ((frame '()) (headers '()))
|
|
(map-put frame 'command "SEND")
|
|
(map-put headers "header" "value")
|
|
(map-put frame 'headers headers)
|
|
(map-put frame 'content "Some content")
|
|
(should (equal (stomp-frame-to-string frame) "SEND\nheader:value\n\nSome content\u0000"))))
|