aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorBasil L. Contovounesios2020-06-11 13:48:37 +0100
committerBasil L. Contovounesios2020-06-18 12:58:28 +0100
commit23a148c9506f2a5bce71bd5c8822bb7cde6697e8 (patch)
tree560e8278331540cfdbd6b30073f7de8f40f631da /test
parent0185d76e7426eb1b58a9b60b0d18e763ddf57dea (diff)
downloademacs-23a148c9506f2a5bce71bd5c8822bb7cde6697e8.tar.gz
emacs-23a148c9506f2a5bce71bd5c8822bb7cde6697e8.zip
Various battery.el improvements (bug#41808)
* lisp/battery.el: Mention BSD support in Commentary. Don't load preloaded lisp/emacs-lisp/timer.el. (battery--files): New function. (battery--find-linux-sysfs-batteries): Use it and make fewer syscalls. (battery-status-function): Perform GNU/Linux checks in increasing order of obsolescence: sysfs, ACPI, and then APM. Simplify Darwin check. Add :version tag now that battery-upower is the default. (battery-echo-area-format, battery-mode-line-format): Mention %s. (battery-load-low, battery-load-critical): New faces. (battery-update): Display battery-mode-line-format even if percentage is N/A. Apply faces battery-load-low or battery-load-critical according to the percentage, but append them so they don't override user customizations. Update all mode lines since we are in global-mode-string. (battery-linux-proc-apm-regexp): Mark as obsolete, replacing with... (battery--linux-proc-apm): ...this new rx definition. (battery-linux-proc-apm): Use it. Fix indentation. Simplify. (battery--acpi-rate, battery--acpi-capacity): New rx definitions. (battery-linux-proc-acpi): Use them. Fix pathological whitespace regexps. Simplify. (battery-linux-sysfs): Fix docstring and indentation. Reduce number of file searches. Simplify. (battery-bsd-apm): Fix docstring. Simplify. (battery-pmset): Fix docstring. Simplify ID regexp. * lisp/emacs-lisp/rx.el (rx-define): Indent as a defun. * test/lisp/battery-tests.el (battery-linux-proc-apm-regexp): Test new battery--linux-proc-apm rx definition. (battery-acpi-rate-regexp, battery-acpi-capacity-regexp): New tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/battery-tests.el39
1 files changed, 36 insertions, 3 deletions
diff --git a/test/lisp/battery-tests.el b/test/lisp/battery-tests.el
index 4cb7470d884..92ab013f040 100644
--- a/test/lisp/battery-tests.el
+++ b/test/lisp/battery-tests.el
@@ -22,9 +22,9 @@
22(require 'battery) 22(require 'battery)
23 23
24(ert-deftest battery-linux-proc-apm-regexp () 24(ert-deftest battery-linux-proc-apm-regexp ()
25 "Test `battery-linux-proc-apm-regexp'." 25 "Test `rx' definition `battery--linux-proc-apm'."
26 (let ((str "1.16 1.2 0x07 0x01 0xff 0x80 -1% -1 ?")) 26 (let ((str "1.16 1.2 0x07 0x01 0xff 0x80 -1% -1 ?"))
27 (should (string-match battery-linux-proc-apm-regexp str)) 27 (should (string-match (rx battery--linux-proc-apm) str))
28 (should (equal (match-string 0 str) str)) 28 (should (equal (match-string 0 str) str))
29 (should (equal (match-string 1 str) "1.16")) 29 (should (equal (match-string 1 str) "1.16"))
30 (should (equal (match-string 2 str) "1.2")) 30 (should (equal (match-string 2 str) "1.2"))
@@ -36,7 +36,7 @@
36 (should (equal (match-string 8 str) "-1")) 36 (should (equal (match-string 8 str) "-1"))
37 (should (equal (match-string 9 str) "?"))) 37 (should (equal (match-string 9 str) "?")))
38 (let ((str "1.16 1.2 0x03 0x00 0x00 0x01 99% 1792 min")) 38 (let ((str "1.16 1.2 0x03 0x00 0x00 0x01 99% 1792 min"))
39 (should (string-match battery-linux-proc-apm-regexp str)) 39 (should (string-match (rx battery--linux-proc-apm) str))
40 (should (equal (match-string 0 str) str)) 40 (should (equal (match-string 0 str) str))
41 (should (equal (match-string 1 str) "1.16")) 41 (should (equal (match-string 1 str) "1.16"))
42 (should (equal (match-string 2 str) "1.2")) 42 (should (equal (match-string 2 str) "1.2"))
@@ -48,6 +48,39 @@
48 (should (equal (match-string 8 str) "1792")) 48 (should (equal (match-string 8 str) "1792"))
49 (should (equal (match-string 9 str) "min")))) 49 (should (equal (match-string 9 str) "min"))))
50 50
51(ert-deftest battery-acpi-rate-regexp ()
52 "Test `rx' definition `battery--acpi-rate'."
53 (let ((str "01 mA"))
54 (should (string-match (rx (battery--acpi-rate)) str))
55 (should (equal (match-string 0 str) str))
56 (should (equal (match-string 1 str) "01"))
57 (should (equal (match-string 2 str) "mA")))
58 (let ((str "23 mW"))
59 (should (string-match (rx (battery--acpi-rate)) str))
60 (should (equal (match-string 0 str) str))
61 (should (equal (match-string 1 str) "23"))
62 (should (equal (match-string 2 str) "mW")))
63 (let ((str "23 mWh"))
64 (should (string-match (rx (battery--acpi-rate)) str))
65 (should (equal (match-string 0 str) "23 mW"))
66 (should (equal (match-string 1 str) "23"))
67 (should (equal (match-string 2 str) "mW")))
68 (should-not (string-match (rx (battery--acpi-rate) eos) "45 mWh")))
69
70(ert-deftest battery-acpi-capacity-regexp ()
71 "Test `rx' definition `battery--acpi-capacity'."
72 (let ((str "01 mAh"))
73 (should (string-match (rx battery--acpi-capacity) str))
74 (should (equal (match-string 0 str) str))
75 (should (equal (match-string 1 str) "01"))
76 (should (equal (match-string 2 str) "mAh")))
77 (let ((str "23 mWh"))
78 (should (string-match (rx battery--acpi-capacity) str))
79 (should (equal (match-string 0 str) str))
80 (should (equal (match-string 1 str) "23"))
81 (should (equal (match-string 2 str) "mWh")))
82 (should-not (string-match (rx battery--acpi-capacity eos) "45 mW")))
83
51(ert-deftest battery-format () 84(ert-deftest battery-format ()
52 "Test `battery-format'." 85 "Test `battery-format'."
53 (should (equal (battery-format "" ()) "")) 86 (should (equal (battery-format "" ()) ""))