discussion and development of piem
 help / color / mirror / code / Atom feed
blob 71dc1099123b56f3aece0b75beda6a9c9e888ed4 4619 bytes (raw)
name: tests/piem-lei-tests.el 	 # note: path name is non-authoritative(*)

  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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
;;; piem-lei-tests.el --- tests for piem-lei  -*- lexical-binding: t; -*-

;; Copyright (C) 2021  all contributors <piem@inbox.kyleam.com>

;; Author: Kyle Meyer <kyle@kyleam.com>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'ert)
(require 'piem-lei)

(ert-deftest piem-lei-query--add-child ()
  (should-error
   (piem-lei-query--add-child
    (make-piem-lei-msg :mid "m1")
    (make-piem-lei-msg :mid "m1")))
  (let ((m1 (make-piem-lei-msg :mid "m1"))
        (m2 (make-piem-lei-msg :mid "m2")))
    (piem-lei-query--add-child m1 m2)
    (should (equal (piem-lei-msg-parent m2) m1))
    (should (equal (piem-lei-msg-children m1) (list m2))))
  (let ((m1 (make-piem-lei-msg :mid "m1"))
        (m2 (make-piem-lei-msg :mid "m2"))
        (m3 (make-piem-lei-msg :mid "m3"))
        (m4 (make-piem-lei-msg :mid "m4")))
    (piem-lei-query--add-child m1 m2)
    (piem-lei-query--add-child m1 m4)
    (piem-lei-query--add-child m3 m2)
    (should (equal (piem-lei-msg-parent m2) m3))
    (should (equal (piem-lei-msg-children m1) (list m4)))
    (should (equal (piem-lei-msg-children m3) (list m2)))))

(ert-deftest piem-lei-query--has-descendant ()
  (let ((m1 (make-piem-lei-msg :mid "m1"))
        (m2 (make-piem-lei-msg :mid "m2")))
    (should-not
     (piem-lei-query--has-descendant m1 m2))
    (should-not
     (piem-lei-query--has-descendant m2 m1)))
  (let ((m1 (make-piem-lei-msg :mid "m1")))
    (should (piem-lei-query--has-descendant m1 m1)))
  (let ((m1 (make-piem-lei-msg :mid "m1"))
        (m2 (make-piem-lei-msg :mid "m2")))
    (piem-lei-query--add-child m1 m2)
    (should (piem-lei-query--has-descendant m1 m2))
    (should-not
     (piem-lei-query--has-descendant m2 m1)))
  (let ((m1 (make-piem-lei-msg :mid "m1"))
        (m2 (make-piem-lei-msg :mid "m2"))
        (m3 (make-piem-lei-msg :mid "m3")))
    (piem-lei-query--add-child m1 m2)
    (piem-lei-query--add-child m2 m3)
    (should (piem-lei-query--has-descendant m1 m2))
    (should (piem-lei-query--has-descendant m1 m3))
    (should (piem-lei-query--has-descendant m2 m3))
    (should-not (piem-lei-query--has-descendant m2 m1))
    (should-not (piem-lei-query--has-descendant m3 m2))
    (should-not (piem-lei-query--has-descendant m3 m1))))

(ert-deftest piem-lei-query--elide-subject:keep-original ()
  (should (equal "ghi jlk"
                 (piem-lei-query--elide-subject
                  nil
                  "ghi jlk")))
  (should (equal "ghi jlk"
                 (piem-lei-query--elide-subject
                  "abc def"
                  "ghi jlk")))
  (should (equal "abc def"
                 (piem-lei-query--elide-subject
                  "[PATCH] abc def"
                  "abc def")))
  (should (equal "abc def"
                 (piem-lei-query--elide-subject
                  "[bug#00000] [PATCH] abc def"
                  "abc def")))
  (should (equal "abc def"
                 (piem-lei-query--elide-subject
                  "[PATCH] abc def"
                  "abc def")))
  (should (equal "[bug#00000] [PATCH v2] abc"
                 (piem-lei-query--elide-subject
                  "[bug#00000] [PATCH] abc"
                  "[bug#00000] [PATCH v2] abc")))
  (should (equal "[bug#00000] [PATCH v2] ghi jlk mno"
                 (piem-lei-query--elide-subject
                  "[bug#00000] [PATCH] abc def"
                  "[bug#00000] [PATCH v2] ghi jlk mno"))))

(defvar piem-lei-tests-elide-string (if (char-displayable-p ?…) "…" "..."))

(ert-deftest piem-lei-query--elide-subject:elide ()
  (should (equal (concat "[PATCH v2] " piem-lei-tests-elide-string)
                 (piem-lei-query--elide-subject
                  "[PATCH] abc def"
                  "[PATCH v2] abc def")))
  (should (equal (concat "[bug#00000] [PATCH v2] " piem-lei-tests-elide-string)
                 (piem-lei-query--elide-subject
                  "[bug#00000] [PATCH] abc def"
                  "[bug#00000] [PATCH v2] abc def"))))

(provide 'piem-lei-tests)
;;; piem-lei-tests.el ends here

debug log:

solving 71dc1099 ...
found 71dc1099 in https://git.kyleam.com/piem/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).