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.
69 lines
2.5 KiB
EmacsLisp
69 lines
2.5 KiB
EmacsLisp
#!/bin/sh
|
|
":"; exec emacs -Q -batch -l ert -l "$0" -f ert-run-tests-batch-and-exit
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;;;;;;;;;;;;;;;;;;;;; SETUP ;;;;;;;;;;;;;;;;;;;;;;;
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
(setq cwd default-directory)
|
|
|
|
(defun stomp-frame-buffer (test-file)
|
|
"Create a buffer with a stomp frame in it for testing purposes"
|
|
(find-file (format "%s/test/testdata/%s" cwd test-file)))
|
|
|
|
(defun simple-frame-buffer ()
|
|
"Simple buffer to be used for testing"
|
|
(stomp-frame-buffer "stomp_frame.txt"))
|
|
|
|
(defun carriage-return-frame-buffer ()
|
|
"Simple buffer with carriage returns"
|
|
(stomp-frame-buffer "stomp_frame_cr.txt"))
|
|
|
|
(defun multiple-frame-buffer ()
|
|
"Buffer with multiple frames"
|
|
(stomp-frame-buffer "multiple_frames.txt"))
|
|
|
|
(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"
|
|
(setq recieved (stomp-read-frame (simple-frame-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"
|
|
(setq recieved (stomp-read-frame (carriage-return-frame-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-delete-one-frame ()
|
|
"Can delete the topmost frame in a buffer"
|
|
(let ((buffer (multiple-frame-buffer)))
|
|
(stomp-delete-frame buffer)
|
|
(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"))))
|