unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 88060470690aea86efbc3d4745fe0ad679d906ee 5599 bytes (raw)
name: test/lisp/battery-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
117
118
119
120
121
 
;;; battery-tests.el --- tests for battery.el -*- lexical-binding: t -*-

;; Copyright (C) 2020 Free Software Foundation, Inc.

;; This file is part of GNU Emacs.

;; GNU Emacs 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.

;; GNU Emacs 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 GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

(require 'battery)

(ert-deftest battery-linux-proc-apm-regexp ()
  "Test `battery-linux-proc-apm-regexp'."
  (let ((str "1.16 1.2 0x07 0x01 0xff 0x80 -1% -1 ?"))
    (should (string-match battery-linux-proc-apm-regexp str))
    (should (equal (match-string 0 str) str))
    (should (equal (match-string 1 str) "1.16"))
    (should (equal (match-string 2 str) "1.2"))
    (should (equal (match-string 3 str) "07"))
    (should (equal (match-string 4 str) "01"))
    (should (equal (match-string 5 str) "ff"))
    (should (equal (match-string 6 str) "80"))
    (should (equal (match-string 7 str) "-1"))
    (should (equal (match-string 8 str) "-1"))
    (should (equal (match-string 9 str) "?")))
  (let ((str "1.16 1.2 0x03 0x00 0x00 0x01 99% 1792 min"))
    (should (string-match battery-linux-proc-apm-regexp str))
    (should (equal (match-string 0 str) str))
    (should (equal (match-string 1 str) "1.16"))
    (should (equal (match-string 2 str) "1.2"))
    (should (equal (match-string 3 str) "03"))
    (should (equal (match-string 4 str) "00"))
    (should (equal (match-string 5 str) "00"))
    (should (equal (match-string 6 str) "01"))
    (should (equal (match-string 7 str) "99"))
    (should (equal (match-string 8 str) "1792"))
    (should (equal (match-string 9 str) "min"))))

(ert-deftest battery-upower-state ()
  "Test `battery--upower-state'."
  ;; Charging.
  (dolist (total '(nil charging discharging empty fully-charged
                       pending-charge pending-discharge))
    (should (eq (battery--upower-state '(("State" . 1)) total) 'charging)))
  (dolist (state '(nil 0 1 2 3 4 5 6))
    (should (eq (battery--upower-state `(("State" . ,state)) 'charging)
                'charging)))
  ;; Discharging.
  (dolist (total '(nil discharging empty fully-charged
                       pending-charge pending-discharge))
    (should (eq (battery--upower-state '(("State" . 2)) total) 'discharging)))
  (dolist (state '(nil 0 2 3 4 5 6))
    (should (eq (battery--upower-state `(("State" . ,state)) 'discharging)
                'discharging)))
  ;; Pending charge.
  (dolist (total '(nil empty fully-charged pending-charge pending-discharge))
    (should (eq (battery--upower-state '(("State" . 5)) total)
                'pending-charge)))
  (dolist (state '(nil 0 3 4 5 6))
    (should (eq (battery--upower-state `(("State" . ,state)) 'pending-charge)
                'pending-charge)))
  ;; Pending discharge.
  (dolist (total '(nil empty fully-charged pending-discharge))
    (should (eq (battery--upower-state '(("State" . 6)) total)
                'pending-discharge)))
  (dolist (state '(nil 0 3 4 6))
    (should (eq (battery--upower-state `(("State" . ,state)) 'pending-discharge)
                'pending-discharge)))
  ;; Empty.
  (dolist (total '(nil empty))
    (should (eq (battery--upower-state '(("State" . 3)) total) 'empty)))
  (dolist (state '(nil 0 3))
    (should (eq (battery--upower-state `(("State" . ,state)) 'empty) 'empty)))
  ;; Fully charged.
  (dolist (total '(nil fully-charged))
    (should (eq (battery--upower-state '(("State" . 4)) total) 'fully-charged)))
  (dolist (state '(nil 0 4))
    (should (eq (battery--upower-state `(("State" . ,state)) 'fully-charged)
                'fully-charged))))

(ert-deftest battery-upower-state-unknown ()
  "Test `battery--upower-state' with unknown states."
  ;; Unknown running total retains new state.
  (should-not (battery--upower-state () nil))
  (should-not (battery--upower-state '(("State" . state)) nil))
  (should-not (battery--upower-state '(("State" . 0)) nil))
  (should (eq (battery--upower-state '(("State" . 1)) nil) 'charging))
  (should (eq (battery--upower-state '(("State" . 2)) nil) 'discharging))
  (should (eq (battery--upower-state '(("State" . 3)) nil) 'empty))
  (should (eq (battery--upower-state '(("State" . 4)) nil) 'fully-charged))
  (should (eq (battery--upower-state '(("State" . 5)) nil) 'pending-charge))
  (should (eq (battery--upower-state '(("State" . 6)) nil) 'pending-discharge))
  ;; Unknown new state retains running total.
  (dolist (props '(() (("State" . state)) (("State" . 0))))
    (dolist (total '(nil charging discharging empty fully-charged
                         pending-charge pending-discharge))
      (should (eq (battery--upower-state props total) total))))
  ;; Conflicting empty and fully-charged.
  (should-not (battery--upower-state '(("State" . 3)) 'fully-charged))
  (should-not (battery--upower-state '(("State" . 4)) 'empty)))

(ert-deftest battery-format ()
  "Test `battery-format'."
  (should (equal (battery-format "" ()) ""))
  (should (equal (battery-format "" '((?b . "-"))) ""))
  (should (equal (battery-format "%a%b%p%%" '((?b . "-") (?p . "99")))
                 "-99%")))

;;; battery-tests.el ends here

debug log:

solving 8806047069 ...
found 8806047069 in https://yhetil.org/emacs-bugs/87ftb1zja1.fsf@tcd.ie/
found 052ae49a80 in https://git.savannah.gnu.org/cgit/emacs.git
preparing index
index prepared:
100644 052ae49a8001aa00795d2fb71e86a2ee9bfba895	test/lisp/battery-tests.el

applying [1/1] https://yhetil.org/emacs-bugs/87ftb1zja1.fsf@tcd.ie/
diff --git a/test/lisp/battery-tests.el b/test/lisp/battery-tests.el
index 052ae49a80..8806047069 100644

Checking patch test/lisp/battery-tests.el...
Applied patch test/lisp/battery-tests.el cleanly.

index at:
100644 88060470690aea86efbc3d4745fe0ad679d906ee	test/lisp/battery-tests.el

(*) 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.savannah.gnu.org/cgit/emacs.git

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).