aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPhilipp Stephani2019-04-24 13:41:05 +0200
committerPhilipp Stephani2019-04-24 13:41:05 +0200
commitc4bacb1215bfdf058b374312256c27eaea1304a4 (patch)
tree2811b773f41d6ccf6984821e89b360a48a4589b3 /test/src
parent534c33cf375182c97291d2dd242f936df5953321 (diff)
downloademacs-c4bacb1215bfdf058b374312256c27eaea1304a4.tar.gz
emacs-c4bacb1215bfdf058b374312256c27eaea1304a4.zip
Clarify rounding mode when converting to struct timespec.
* doc/lispref/internals.texi (Module Values): Clarify that the truncation is towards negative infinity. * test/data/emacs-module/mod-test.c (Fmod_test_nanoseconds): Add test function. (emacs_module_init): Define it. * test/src/emacs-module-tests.el (mod-test-nanoseconds): New unit test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/emacs-module-tests.el19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el
index 9eb38cd4548..173b63670fc 100644
--- a/test/src/emacs-module-tests.el
+++ b/test/src/emacs-module-tests.el
@@ -342,6 +342,25 @@ Interactively, you can try hitting \\[keyboard-quit] to quit."
342 (ert-info ((format "input: %s" input)) 342 (ert-info ((format "input: %s" input))
343 (should-error (mod-test-add-nanosecond input))))) 343 (should-error (mod-test-add-nanosecond input)))))
344 344
345(ert-deftest mod-test-nanoseconds ()
346 "Test truncation when converting to `struct timespec'."
347 (dolist (test-case '((0 . 0)
348 (-1 . -1000000000)
349 ((1 . 1000000000) . 1)
350 ((-1 . 1000000000) . -1)
351 ((1 . 1000000000000) . 0)
352 ((-1 . 1000000000000) . -1)
353 ((999 . 1000000000000) . 0)
354 ((-999 . 1000000000000) . -1)
355 ((1000 . 1000000000000) . 1)
356 ((-1000 . 1000000000000) . -1)
357 ((0 0 0 1) . 0)
358 ((0 0 0 -1) . -1)))
359 (let ((input (car test-case))
360 (expected (cdr test-case)))
361 (ert-info ((format "input: %S, expected result: %d" input expected))
362 (should (eq (mod-test-nanoseconds input) expected))))))
363
345(ert-deftest mod-test-double () 364(ert-deftest mod-test-double ()
346 (dolist (input (list 0 1 2 -1 42 12345678901234567890 365 (dolist (input (list 0 1 2 -1 42 12345678901234567890
347 most-positive-fixnum (1+ most-positive-fixnum) 366 most-positive-fixnum (1+ most-positive-fixnum)