aboutsummaryrefslogtreecommitdiff
path: root/test/test-util.el
blob: 49df274fc4488d9546355b550274455518c799bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(ert-deftest test-tree-filter ()
  "Test `sx-core-filter-data'"
  ;; flat
  (should
   (equal
    '((1 . t) (2 . [1 2]) (3))
    (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2])
                       ("5" . bop) (3) (p . 4))
                     '(1 2 3))))
  ;; complex
  (should
   (equal
    '((1 . [a b c])
      (2 . [((a . 1) (c . 3))
            ((a . 4) (c . 6))])
      (3 . peach))
    (sx--filter-data '((1 . [a b c])
                       (2 . [((a . 1) (b . 2) (c . 3))
                             ((a . 4) (b . 5) (c . 6))])
                       (3 . peach)
                       (4 . banana))
                     '(1 (2 a c) 3))))

  ;; vector
  (should
   (equal
    [((1 . 2) (2 . 3) (3 . 4))
     ((1 . a) (2 . b) (3 . c))
     nil ((1 . alpha) (2 . beta))]
    (sx--filter-data [((1 . 2) (2 . 3) (3 . 4))
                      ((1 . a) (2 . b) (3 . c) (5 . seven))
                      ((should-not-go))
                      ((1 . alpha) (2 . beta))]
                     '(1 2 3)))))

(ert-deftest thing-as-string ()
  "Test `sx--thing-as-string'"
  (should
   (string= (sx--thing-as-string
             '(hello world (this is a test))
             '(";" "+"))
            "hello;world;this+is+a+test"))
  (should
   (string= (sx--thing-as-string
             '(this is a test) '(";" "+"))
            "this;is;a;test"))
  (should
   (string= (sx--thing-as-string
             '(this is a test) "+")
            "this+is+a+test"))
  (should
   (string= (sx--thing-as-string
             '(this is a test))
            "this;is;a;test"))
  (should
   (string= (sx--thing-as-string
             'test)
            "test"))
  (should
   (string= (sx--thing-as-string
             'test&)
            "test&"))
  (should
   (string= (sx--thing-as-string
             'test& nil t)
            "test%26")))