Browse Source

Add test for msgfield-regexp and move it around

tags/v0.7.0
Damien Cassou 2 years ago
parent
commit
5a85d11e4a
No known key found for this signature in database GPG Key ID: A7123815F5DCE914
2 changed files with 16 additions and 8 deletions
  1. +9
    -8
      libmpdel.el
  2. +7
    -0
      test/libmpdel-test.el

+ 9
- 8
libmpdel.el View File

@@ -93,6 +93,15 @@ The logs of this connection are accessible in the *mpd* buffer.")
"\n")
"Regexp matching the responses sent by the MPD server.")

(defconst libmpdel--msgfield-regexp
(rx line-start
(group (+? (not (any ?:))))
": "
(group (* not-newline))
line-end)
"Regexp matching a line consisting of a key and a value.
The key is stored in group 1 and the value in group 2.")

(defvar libmpdel--msghandlers nil
"Current commands sent to the server.
Each element in the list is of the form (COMMAND HANDLER BUFFER).
@@ -400,14 +409,6 @@ command."
;; nothing to do
nil)

(defconst libmpdel--msgfield-regexp
(rx line-start
(group (+? (not (any ?:))))
": "
(group (* not-newline))
line-end)
"Regexp matching a line consisting of a key and a value.")

(defun libmpdel--extract-data (message)
"Return MESSAGE."
(save-match-data


+ 7
- 0
test/libmpdel-test.el View File

@@ -37,6 +37,13 @@
(should (string-match-p libmpdel--response-regexp "ACK [51@10] {} unknown command \"foobar\"\n"))
(should (string-match-p libmpdel--response-regexp "Artist: A-ha\nOK\n")))

(ert-deftest libmpdel--msgfield-regexp ()
(save-match-data
(let ((line "key: value\n"))
(should (string-match libmpdel--msgfield-regexp line))
(should (equal "key" (match-string 1 line)))
(should (equal "value" (match-string 2 line))))))

;;; Data structures



Loading…
Cancel
Save