Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 6ea2bae0e0
Fetching contributors…

Cannot retrieve contributors at this time

155 lines (140 sloc) 3.675 kb
(require 'kv)
(require 'ert)
(ert-deftest kvhash->alist ()
"Test making alists from hashes."
(should
(equal
(sort
(kvhash->alist
(kvalist->hash '((name1 . value1)
(name2 . value2))))
(lambda (a b)
(string-lessp (symbol-name (car a))
(symbol-name (car b)))))
'((name1 . value1)
(name2 . value2))))
(should
(equal
(sort '((a . 1)
(c . 3)) 'kvcmp)
(sort (kvhash->alist
(kvalist->hash '((a . 1)(b . 2)(c . 3)))
(lambda (k v) (and (memq k '(a c)) v))) 'kvcmp))))
(ert-deftest kvalist-sort ()
(should
(equal
(kvalist-sort
(list '("z" . 20)
'("a" . 20)
'("b" . 17))
'string-lessp)
'(("a" . 20)
("b" . 17)
("z" . 20)))))
(ert-deftest kvalist-sort-by-value ()
(should
(equal
(kvalist-sort-by-value
(list '("z" . 20)
'("a" . 20)
'("b" . 17))
'<)
'(("b" . 17)
("z" . 20)
("a" . 20)))))
(ert-deftest kvcmp ()
"Test the general cmp function."
(should
(equal
'((a . 10)(b . 20)(c . 5))
(sort '((a . 10)(b . 20)(c . 5)) 'kvcmp)))
(should
(equal
'((a . 10)(b . 20)(c . 5))
(sort '((b . 20)(c . 5)(a . 10)) 'kvcmp))))
(ert-deftest kvalist-keys->symbols ()
"Test the key transformation."
(should
(equal
'((a . 10)(\10 . 20)(\(a\ b\ c\) . 30))
(kvalist-keys->symbols
'(("a" . 10)(10 . 20)((a b c) . 30))))))
(ert-deftest kvassoc= ()
(should
(equal
'("testkey" . "testvalue")
(kvassoc= "testkey" "testvalue" '(("testkey" . "testvalue"))))))
(ert-deftest kvassoq= ()
(should
(equal
'(testkey . "testvalue")
(kvassoq= 'testkey "testvalue" '((testkey . "testvalue")))))
(should
(equal
'("testkey" . "testvalue")
(kvassoq= "testkey" "testvalue" '(("testkey" . "testvalue")))))
;; Not sure about this - should we really find strings with symbols?
(should
(equal
'("testkey" . "testvalue")
(kvassoq= 'testkey "testvalue" '(("testkey" . "testvalue"))))))
(ert-deftest kvalist2-filter ()
(should
(equal
'(((a . 1)(b . 2)))
(kvalist2-filter
'(((a . 1)(b . 2))((c . 1)(d . 2)))
(lambda (alist)
(or
(memq 'a (kvalist->keys alist))
(memq 'b (kvalist->keys alist))))))))
(ert-deftest kvquery->func ()
"Test the query language."
(should
(equal
'((("a" . 1)("b" . 2))(("c" . 1)("d" . 2)))
(kvalist2-filter
'((("a" . 1)("b" . 2))(("c" . 1)("d" . 2)))
(kvquery->func '(|(= "a" 1)(= "d" 2))))))
(should
(equal
'((("a" . 1)("b" . 2)))
(kvalist2-filter
'((("a" . 1)("b" . 2))(("c" . 1)("d" . 2)))
(kvquery->func '(= "a" 1)))))
(should
(equal
'()
(kvalist2-filter
'((("a" . 1)("b" . 2))(("c" . 1)("d" . 2)))
(kvquery->func '(&(= "a" 1)(= "c" 1))))))
(should
(equal
'((("a" . 1)("b" . 2)))
(kvalist2-filter
'((("a" . 1)("b" . 2))(("c" . 1)("d" . 2)))
(kvquery->func '(&(= "a" 1)(= "b" 2)))))))
(ert-deftest kvdotassoc ()
(should
(equal
(dotassoc "a.b.c" '(("a" . (("b" . (("c" . 10)))))))
10)))
(ert-deftest kvdotassq ()
(should
(equal
(dotassq 'a.b.c '((a . ((b . ((c . 10)))))))
10)))
(ert-deftest kvalist->plist ()
"Make alists into plists."
(should
(equal
'(:a1 value1 :a2 value2)
(kvalist->plist '((a1 . value1)(a2 . value2))))))
(ert-deftest kvplist->filter-keys ()
(should
(equal
(list :key1 "value1" :key4 10)
(kvplist->filter-keys
(list :key1 "value1" :key2 t :key3 '(big list of symbols) :key4 10)
'key1 'key4))))
;;; kv-tests.el ends here
Jump to Line
Something went wrong with that request. Please try again.