From 865535a24cd07efee3c2d323de6e9baae8bc817d Mon Sep 17 00:00:00 2001 From: Remington Furman Date: Fri, 16 Jul 2021 11:47:36 +0200 Subject: Make `number-at-point' work for more hex numbers * lisp/thingatpt.el (number-at-point): Rewrite to actually catch the hex numbers (bug#49588). Copyright-paperwork-exempt: yes --- test/lisp/thingatpt-tests.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'test/lisp/thingatpt-tests.el') diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el index 07eb8bb250e..fba6f21d5dc 100644 --- a/test/lisp/thingatpt-tests.el +++ b/test/lisp/thingatpt-tests.el @@ -190,4 +190,37 @@ position to retrieve THING.") (goto-char 2) (should (eq (symbol-at-point) nil)))) +(defun test--number (number pos) + (with-temp-buffer + (insert (format "%s\n" number)) + (goto-char (point-min)) + (forward-char pos) + (number-at-point))) + +(ert-deftest test-numbers-none () + (should (equal (test--number "foo" 0) nil))) + +(ert-deftest test-numbers-decimal () + (should (equal (test--number "42" 0) 42)) + (should (equal (test--number "42" 1) 42)) + (should (equal (test--number "42" 2) 42))) + +(ert-deftest test-numbers-hex-lisp () + (should (equal (test--number "#x42" 0) 66)) + (should (equal (test--number "#x42" 1) 66)) + (should (equal (test--number "#x42" 2) 66)) + (should (equal (test--number "#xf00" 0) 3840)) + (should (equal (test--number "#xf00" 1) 3840)) + (should (equal (test--number "#xf00" 2) 3840)) + (should (equal (test--number "#xf00" 3) 3840))) + +(ert-deftest test-numbers-hex-c () + (should (equal (test--number "0x42" 0) 66)) + (should (equal (test--number "0x42" 1) 66)) + (should (equal (test--number "0x42" 2) 66)) + (should (equal (test--number "0xf00" 0) 3840)) + (should (equal (test--number "0xf00" 1) 3840)) + (should (equal (test--number "0xf00" 2) 3840)) + (should (equal (test--number "0xf00" 3) 3840))) + ;;; thingatpt.el ends here -- cgit v1.2.3