diff options
| author | Paul Eggert | 2018-07-26 00:34:10 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-07-26 00:39:17 -0700 |
| commit | 4a56ca5bbfabbb9c581828cd91648346e6b03844 (patch) | |
| tree | 90b804ea4ec22a8b7be181f0b505b57c40a85c27 /test/src | |
| parent | 19f5f7b19b0dcdae87476a3fd51c41f840b2b80f (diff) | |
| download | emacs-4a56ca5bbfabbb9c581828cd91648346e6b03844.tar.gz emacs-4a56ca5bbfabbb9c581828cd91648346e6b03844.zip | |
%o and %x can now format signed integers
Optionally treat integers as signed numbers with %o
and %x format specifiers, instead of treating them as
a machine-dependent two’s complement representation.
This option is more machine-independent, allows formats
like "#x%x" to be useful for reading later, and is
better-insulated for future changes involving bignums.
Setting the new variable ‘binary-as-unsigned’ to nil
enables the new behavior (Bug#32252).
This is a simplified version of the change proposed in:
https://lists.gnu.org/r/emacs-devel/2018-07/msg00763.html
I simplified that proposal by omitting bitwidth modifiers, as
I could not find an any example uses in the Emacs source code
that needed them and doing them correctly would have been
quite a bit more work for apparently little benefit.
* doc/lispref/strings.texi (Formatting Strings):
Document that %x and %o format negative integers in a
platform-dependent way. Also, document how to format
numbers so that the same values can be read back in.
* etc/NEWS: Document the change.
* src/editfns.c (styled_format): Treat integers as signed
numbers even with %o and %x, if binary-as-unsigned is nil.
Support the + and space flags with %o and %x, since they’re
about signs.
(syms_of_editfns): New variable binary-as-unsigned.
* test/src/editfns-tests.el (read-large-integer):
Test that maximal integers can be read after printing
with all integer formats, if binary-as-unsigned is nil.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/editfns-tests.el | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index c828000bb4f..2951270dbf7 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el | |||
| @@ -165,10 +165,12 @@ | |||
| 165 | :type 'overflow-error) | 165 | :type 'overflow-error) |
| 166 | (should-error (read (substring (format "%d" most-negative-fixnum) 1)) | 166 | (should-error (read (substring (format "%d" most-negative-fixnum) 1)) |
| 167 | :type 'overflow-error) | 167 | :type 'overflow-error) |
| 168 | (should-error (read (format "#x%x" most-negative-fixnum)) | 168 | (let ((binary-as-unsigned nil)) |
| 169 | :type 'overflow-error) | 169 | (dolist (fmt '("%d" "%s" "#o%o" "#x%x")) |
| 170 | (should-error (read (format "#o%o" most-negative-fixnum)) | 170 | (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum) |
| 171 | :type 'overflow-error) | 171 | -1 0 1 |
| 172 | (1- most-positive-fixnum) most-positive-fixnum)) | ||
| 173 | (should (eq val (read (format fmt val))))))) | ||
| 172 | (should-error (read (format "#32rG%x" most-positive-fixnum)) | 174 | (should-error (read (format "#32rG%x" most-positive-fixnum)) |
| 173 | :type 'overflow-error)) | 175 | :type 'overflow-error)) |
| 174 | 176 | ||