Browse Source

Define equality between entities

tags/v0.7.0
Damien Cassou 2 years ago
parent
commit
6eeb9cb17d
No known key found for this signature in database GPG Key ID: A7123815F5DCE914
2 changed files with 59 additions and 0 deletions
  1. +13
    -0
      libmpdel.el
  2. +46
    -0
      test/libmpdel-test.el

+ 13
- 0
libmpdel.el View File

@@ -240,6 +240,15 @@ message from the server.")
(cl-defmethod libmpdel-entity-parent ((_stored-playlist libmpdel-stored-playlist))
'stored-playlists)

(cl-defgeneric libmpdel-entity-id (entity)
"Return an identifier string for ENTITY."
entity)

(cl-defmethod libmpdel-entity-id ((song libmpdel-song))
;; Override of default implementation to ignore changing ids and
;; position.
(libmpdel--song-file song))

(defun libmpdel-song-file (song)
"Return the filename of SONG."
(libmpdel--song-file song))
@@ -623,6 +632,10 @@ If HANDLER is nil, ignore response."
(require 'dired-x)
(dired-jump t (expand-file-name (libmpdel-song-file song) libmpdel-music-directory)))

(defun libmpdel-equal (entity1 entity2)
"Return non-nil if ENTITY1 and ENTITY2 represent the same entity."
(equal (libmpdel-entity-id entity1) (libmpdel-entity-id entity2)))

;;; Helper queries



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

@@ -125,6 +125,52 @@
(ert-deftest libmpdel-group-data-of-nil-is-nil ()
(should (null (libmpdel-group-data nil))))

(ert-deftest libmpdel-equal ()
(let* ((artist1 (libmpdel--artist-create :name "artist1"))
(artist1-bis (libmpdel--artist-create :name "artist1"))
(artist2 (libmpdel--artist-create :name "artist2"))
(album1 (libmpdel--album-create :name "album1" :artist artist1))
(album1-bis (libmpdel--album-create :name "album1" :artist artist1))
(album2 (libmpdel--album-create :name "album2" :artist artist1))
(song1 (libmpdel--song-create
:name "name"
:file "file"
:track "3"
:album album1
:id "1"
:pos "1"))
(song1-bis (libmpdel--song-create
:name "name"
:file "file"
:track "3"
:album album1-bis
:id "2" ;; change id and pos
:pos "2"))
(song2 (libmpdel--song-create
:name "name2"
:file "file2"
:track "3"
:album album2
:id "3"
:pos "3")))
(should (libmpdel-equal artist1 artist1))
(should (libmpdel-equal artist1 artist1-bis))
(should (libmpdel-equal artist1-bis artist1))
(should (not (libmpdel-equal artist1 artist2)))
(should (not (libmpdel-equal artist2 artist1)))

(should (libmpdel-equal album1 album1))
(should (libmpdel-equal album1 album1-bis))
(should (libmpdel-equal album1-bis album1))
(should (not (libmpdel-equal album1 album2)))
(should (not (libmpdel-equal album2 album1)))

(should (libmpdel-equal song1 song1))
(should (libmpdel-equal song1 song1-bis))
(should (libmpdel-equal song1-bis song1))
(should (not (libmpdel-equal song1 song2)))
(should (not (libmpdel-equal song2 song1)))))

;;; Data structures



Loading…
Cancel
Save