28 Commits

Author SHA1 Message Date
ringabout
2df633180a enable experimental:strictDefs (#24225) 2024-11-23 22:01:39 +01:00
Jacek Sieka
a1e41930f8 strformat: detect format string errors at compile-time (#23356)
This also prevents unwanted `raises: [ValueError]` effects from bubbling
up from correct format strings which makes `fmt` broadly unusable with
`raises`.

The old runtime-based `formatValue` overloads are kept for
backwards-compatibility, should anyone be using runtime format strings.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-03-03 15:40:53 +01:00
metagn
e5d0907a42 line info for strformat + fix issue with typed templates (#21761)
* line info in strformat

* also fix #20381
2023-05-02 11:28:52 +02:00
ringabout
4fa86422c0 stdlib tests now check refc too (#21664)
* stdlib tests now check refc too

* typo

* fixes line numbers

* disable cpp

* do not touch
2023-04-21 15:37:58 +02:00
ringabout
fc068ee06d fixes #18134; registers formatBiggestFloat in VM (#21299)
fixes #18134; registers formatBiggestFloat in vmops

strformat supports float format in VM
2023-01-26 23:03:59 +01:00
ringabout
3d2f0e2c7c make more standard libraries work with nimPreviewSlimSystem (#20343)
* make more standard libraries work with `nimPreviewSlimSystem`

* typo

* part two

* Delete specutils.nim

* fixes more tests

* more fixes

* fixes tests

* fixes three more tests

* add formatfloat import

* fix

* last
2022-09-27 20:06:23 +02:00
metagn
b8dc58d884 test removing dollar for objects out of system (#20242)
* test removing dollar for objects out of system

* test & fixes

* fix bootstrap

* use nimPreviewSlimSystem, test stdlib category

* fix test
2022-08-24 09:44:16 +02:00
shirleyquirk
0bc943ad54 followup strformat PR. backslash escapes, tests, docs (#17700)
* Allow use of colons inside fmt
allowing colons inside fmt by replacing the format specifier delimiter lets arbitrary nim code be run within fmt expressions.

Co-authored-by: flywind <xzsflywind@gmail.com>

* formatting,documentation,backslash escapes

Adding support for evaluating expressions by special-casing parentheses causes this regression: `&"""{ "(hello)" }"""` no longer parses.
In addition, code such as &"""{(if open: '(' else: ')')}""" wouldn't work.
To enable that, as well as the use of, e.g. Table constructors inside curlies, I've added backslash escapes.
This also means that if/for/etc statements, unparenthesized, will work, if the colons are escaped, but i've left that under-documented.

It's not exactly elegant having two types of escape, but I believe it's the least bad option.

* changelog
* added json strformat test
* pulled my thumb out and wrote a parser

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Co-authored-by: flywind <xzsflywind@gmail.com>
2021-04-12 07:32:37 +02:00
konsumlamm
bd199a8d31 Improve the strformat module (#17106)
* Improve the strformat module

Improve documentation
Use runnableExamples

* Fix overflow error for low(int64)

Add test

* Use assert in runnableExamples

* Improve tstrformat

Put tests in proc & test VM
Put tests in blocks
Add c, js targets

* Use doAssert in tests

* Disable JS & VM tests
2021-02-20 18:06:29 +01:00
flywind
6d442a40a6 use doAssert in tests (#16486) 2020-12-28 14:13:21 +01:00
flywind
cbc793b30b move tests to testament (#16101)
* move tests to testament

* minor

* fix random

* disable test random
2020-11-24 19:06:41 +01:00
flywind
3db6d9ea0c add docs and more tests for debug format strings (#14861)
* add debug format string

* remove try except

* add changelog

* add docs and more tests

* Update lib/pure/strformat.nim

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>

* minor

Co-authored-by: Juan Carlos <juancarlospaco@gmail.com>
2020-07-08 22:21:30 +02:00
flywind
8be54b8fa7 add debug fmt string like python's (#14808)
* add debug format string

* remove try except

* add changelog
2020-06-30 15:21:37 +02:00
Timothee Cour
7df27b5035 [cleanups] doassert => doAssert; mark deadcode (#14711) 2020-06-17 20:25:25 -07:00
Andreas Rumpf
cc60caedb3 fixes #14054 [backport:1.2] (#14061)
* fixes #14054

* make tests green again

* more tests are green

* maybe now
2020-04-30 06:48:57 +02:00
Andreas Rumpf
56a00da34a fixes #12612 [backport] (#12681) 2019-11-19 12:09:36 +01:00
Tomohiro
a9d7796e1c [feature]strformat: add 2 'fmt' macros that use specified characters instead of '{}' (#11748)
* [feature]strformat: add 2 'fmt' macros that use specified chars instead of '{}'

* strformat: revert documentation comments of `&` and 'fmt'

* strformat: removed single open/close char variant of fmt
2019-10-28 12:33:44 +01:00
Araq
76f9ddb6ab fixes #11723 2019-07-15 17:22:01 +02:00
jcosborn
433ce7bea2 move test for #7632 above import strformat (#11270) 2019-05-20 10:17:56 +02:00
Araq
a517a9985b fixes another regression; the behaviour of 'array' formatting was changed 2019-04-15 08:20:28 +02:00
Araq
59ccaa43c7 fixes #11012 2019-04-15 08:20:28 +02:00
Arne Döring
3a5a0f6d46 Strformat symbol binding (#10927) 2019-04-05 15:27:04 +02:00
skilchen
230692a22f Fix strformat neg zero (#7954)
* fix strformat handling of neg zero with sign

* better tests for neg zero with sign

* use inplace insertion of the sign as suggested by Varriount
2018-06-05 00:09:07 -04:00
skilchen
fd102f39bb Fix strformat precision handling for strings (#7941)
* fix strformat precision handling for strings

* add some limited unicode awareness to the precision handling for strings

* improvement suggested by Varriount: use setLen and runeOffset instead of runeSubstr
2018-06-04 18:26:16 -04:00
skilchen
07ff9940f4 fix strformat zeropadding for floats (#7934) 2018-06-01 22:23:50 -04:00
Araq
9a60eae631 fixes #7078 2018-01-14 23:49:53 +01:00
Araq
fb8def869c rename strformat.fmt to % as it works better with backslash escape sequences; refs #6958 2018-01-11 18:05:14 +01:00
Oscar Nihlgård
624bd847fb Add test case 2018-01-09 00:33:39 +01:00