summaryrefslogtreecommitdiff
path: root/test/lisp/battery-tests.el
blob: 052ae49a8001aa00795d2fb71e86a2ee9bfba895 (plain)
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
;;; 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-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