annotate src/message_test.c @ 32884:27ce9b18f1d5 v9.0.1751

patch 9.0.1751: CI: labeler configuration not found Commit: https://github.com/vim/vim/commit/8b8f7d19f89069a2100b2790bc4701e2a7d03a8b Author: Philip H <47042125+pheiduck@users.noreply.github.com> Date: Sat Aug 19 15:46:11 2023 +0200 patch 9.0.1751: CI: labeler configuration not found Problem: CI: labeler configuration not found (after 9.0.1748) Solution: set configuration path closes: #12852 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Philip H <47042125+pheiduck@users.noreply.github.com>
author Christian Brabandt <cb@256bit.org>
date Sat, 19 Aug 2023 16:00:05 +0200
parents f48e27f20e6b
children 7bc10151ce81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9581
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * message_test.c: Unittests for message.c
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 */
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 #undef NDEBUG
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 #include <assert.h>
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
18931
80b40bd5ec1a patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 11309
diff changeset
17 // Must include main.c because it contains much more than just main()
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 #define NO_VIM_MAIN
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 #include "main.c"
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
18931
80b40bd5ec1a patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 11309
diff changeset
21 // This file has to be included because some of the tested functions are
80b40bd5ec1a patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 11309
diff changeset
22 // static.
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 #include "message.c"
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
25 #ifndef MIN
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
26 # define MIN(x,y) ((x) < (y) ? (x) : (y))
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
27 #endif
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
28
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
29 // These formats are not standard in C printf() function.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
30 // Use a global variable rather than a literal format to disable
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
31 // -Wformat compiler warnings:
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
32 //
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
33 // - warning: '0' flag used with ‘%p’ gnu_printf format
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
34 // - warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 4 has type ‘char *’
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
35 // - warning: unknown conversion type character ‘b’ in format
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
36 //
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
37 // These formats are in practise only used from vim script printf()
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
38 // function and never as literals in C code.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
39 char *fmt_012p = "%012p";
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
40 char *fmt_5S = "%5S";
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
41 char *fmt_06b = "%06b";
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
42 char *fmt_06pb = "%1$0.*2$b";
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
43 char *fmt_212s = "%2$s %1$s %2$s";
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
44 char *fmt_21s = "%2$s %1$s";
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
45
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 /*
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 * Test trunc_string().
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 */
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 static void
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 test_trunc_string(void)
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 {
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
52 char_u *buf; /*allocated every time to find uninit errors */
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
53 char_u *s;
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54
23946
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
55 // Should not write anything to destination if buflen is 0.
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
56 trunc_string((char_u *)"", NULL, 1, 0);
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
57
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
58 // Truncating an empty string does nothing.
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
59 buf = alloc(1);
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
60 trunc_string((char_u *)"", buf, 1, 1);
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
61 assert(buf[0] == NUL);
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
62 vim_free(buf);
0b1f5717dc4d patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents: 20105
diff changeset
63
18931
80b40bd5ec1a patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 11309
diff changeset
64 // in place
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
65 buf = alloc(40);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 STRCPY(buf, "text");
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 trunc_string(buf, buf, 20, 40);
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 assert(STRCMP(buf, "text") == 0);
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
69 vim_free(buf);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
71 buf = alloc(40);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 STRCPY(buf, "a short text");
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 trunc_string(buf, buf, 20, 40);
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 assert(STRCMP(buf, "a short text") == 0);
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
75 vim_free(buf);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
77 buf = alloc(40);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 STRCPY(buf, "a text tha just fits");
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 trunc_string(buf, buf, 20, 40);
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 assert(STRCMP(buf, "a text tha just fits") == 0);
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
81 vim_free(buf);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
83 buf = alloc(40);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 STRCPY(buf, "a text that nott fits");
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 trunc_string(buf, buf, 20, 40);
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 assert(STRCMP(buf, "a text t...nott fits") == 0);
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
87 vim_free(buf);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88
18931
80b40bd5ec1a patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents: 11309
diff changeset
89 // copy from string to buf
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
90 buf = alloc(40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
91 s = vim_strsave((char_u *)"text");
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
92 trunc_string(s, buf, 20, 40);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 assert(STRCMP(buf, "text") == 0);
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
94 vim_free(buf);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
95 vim_free(s);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
97 buf = alloc(40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
98 s = vim_strsave((char_u *)"a text that fits");
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
99 trunc_string(s, buf, 34, 40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
100 assert(STRCMP(buf, "a text that fits") == 0);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
101 vim_free(buf);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
102 vim_free(s);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
104 buf = alloc(40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
105 s = vim_strsave((char_u *)"a short text");
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
106 trunc_string(s, buf, 20, 40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
107 assert(STRCMP(buf, "a short text") == 0);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
108 vim_free(buf);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
109 vim_free(s);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
111 buf = alloc(40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
112 s = vim_strsave((char_u *)"a text tha just fits");
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
113 trunc_string(s, buf, 20, 40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
114 assert(STRCMP(buf, "a text tha just fits") == 0);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
115 vim_free(buf);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
116 vim_free(s);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
117
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
118 buf = alloc(40);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
119 s = vim_strsave((char_u *)"a text that nott fits");
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
120 trunc_string(s, buf, 20, 40);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121 assert(STRCMP(buf, "a text t...nott fits") == 0);
9581
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
122 vim_free(buf);
716382aaa0c0 commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents: 9542
diff changeset
123 vim_free(s);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 }
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
126 /*
24709
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
127 * Test trunc_string() with mbyte chars.
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
128 */
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
129 static void
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
130 test_trunc_string_mbyte(void)
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
131 {
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
132 char_u *buf; // allocated every time to find uninit errors
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
133 char_u *s;
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
134
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
135 buf = alloc(40);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
136 s = vim_strsave((char_u *)"Ä text tha just fits");
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
137 trunc_string(s, buf, 20, 40);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
138 assert(STRCMP(buf, "Ä text tha just fits") == 0);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
139 vim_free(buf);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
140 vim_free(s);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
141
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
142 buf = alloc(40);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
143 s = vim_strsave((char_u *)"a text ÄÖÜä nott fits");
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
144 trunc_string(s, buf, 20, 40);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
145 assert(STRCMP(buf, "a text Ä...nott fits") == 0);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
146 vim_free(buf);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
147 vim_free(s);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
148
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
149 buf = alloc(40);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
150 s = vim_strsave((char_u *)"a text that not fitsÄ");
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
151 trunc_string(s, buf, 20, 40);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
152 assert(STRCMP(buf, "a text t...not fitsÄ") == 0);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
153 vim_free(buf);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
154 vim_free(s);
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
155 }
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
156
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
157 /*
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
158 * Test vim_snprintf() with a focus on checking that truncation is
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
159 * correct when buffer is small, since it cannot be tested from
30986
360f286b5869 patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents: 30310
diff changeset
160 * vim script tests. Check that:
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
161 * - no buffer overflows happens (with valgrind or asan)
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
162 * - output string is always NUL terminated.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
163 *
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
164 * Not all formats of vim_snprintf() are checked here. They are
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
165 * checked more exhaustively in Test_printf*() vim script tests.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
166 */
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
167 static void
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
168 test_vim_snprintf(void)
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
169 {
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
170 int n;
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
171 size_t bsize;
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
172 int bsize_int;
20105
785e2f0095a9 patch 8.2.0608: warning from clang when building message test
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
173 void *ptr = (void *)0x87654321;
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
174
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
175 // Loop on various buffer sizes to make sure that truncation of
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
176 // vim_snprintf() is correct.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
177 for (bsize = 0; bsize < 15; ++bsize)
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
178 {
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
179 bsize_int = (int)bsize - 1;
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
180
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
181 // buf is the heap rather than in the stack
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
182 // so valgrind can detect buffer overflows if any.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
183 // Use malloc() rather than alloc() as test checks with 0-size
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
184 // buffer and its content should then never be used.
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
185 char *buf = malloc(bsize);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
186
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
187 n = vim_snprintf(buf, bsize, "%.8g", 10000000.1);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
188 assert(n == 12);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
189 assert(bsize == 0 || STRNCMP(buf, "1.00000001e7", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
190 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
191
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
192 n = vim_snprintf(buf, bsize, "%d", 1234567);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
193 assert(n == 7);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
194 assert(bsize == 0 || STRNCMP(buf, "1234567", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
195 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
196
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
197 n = vim_snprintf(buf, bsize, "%ld", 1234567L);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
198 assert(n == 7);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
199 assert(bsize == 0 || STRNCMP(buf, "1234567", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
200 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
201
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
202 n = vim_snprintf(buf, bsize, "%9ld", 1234567L);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
203 assert(n == 9);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
204 assert(bsize == 0 || STRNCMP(buf, " 1234567", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
205 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
206
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
207 n = vim_snprintf(buf, bsize, "%-9ld", 1234567L);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
208 assert(n == 9);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
209 assert(bsize == 0 || STRNCMP(buf, "1234567 ", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
210 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
211
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
212 n = vim_snprintf(buf, bsize, "%x", 0xdeadbeef);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
213 assert(n == 8);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
214 assert(bsize == 0 || STRNCMP(buf, "deadbeef", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
215 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
216
19119
7816aa44c145 patch 8.2.0119: message test fails on some platforms
Bram Moolenaar <Bram@vim.org>
parents: 19011
diff changeset
217 n = vim_snprintf(buf, bsize, fmt_06b, (uvarnumber_T)12);
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
218 assert(n == 6);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
219 assert(bsize == 0 || STRNCMP(buf, "001100", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
220 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
221
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
222 n = vim_snprintf(buf, bsize, "%s %s", "one", "two");
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
223 assert(n == 7);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
224 assert(bsize == 0 || STRNCMP(buf, "one two", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
225 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
226
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
227 #ifdef FEAT_FLOAT
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
228 n = vim_snprintf(buf, bsize, "%f", 1.234);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
229 assert(n == 8);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
230 assert(bsize == 0 || STRNCMP(buf, "1.234000", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
231 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
232
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
233 n = vim_snprintf(buf, bsize, "%e", 1.234);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
234 assert(n == 12);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
235 assert(bsize == 0 || STRNCMP(buf, "1.234000e+00", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
236 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
237
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
238 n = vim_snprintf(buf, bsize, "%f", 0.0/0.0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
239 assert(n == 3);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
240 assert(bsize == 0 || STRNCMP(buf, "nan", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
241 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
242
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
243 n = vim_snprintf(buf, bsize, "%f", 1.0/0.0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
244 assert(n == 3);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
245 assert(bsize == 0 || STRNCMP(buf, "inf", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
246 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
247
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
248 n = vim_snprintf(buf, bsize, "%f", -1.0/0.0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
249 assert(n == 4);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
250 assert(bsize == 0 || STRNCMP(buf, "-inf", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
251 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
252
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
253 n = vim_snprintf(buf, bsize, "%f", -0.0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
254 assert(n == 9);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
255 assert(bsize == 0 || STRNCMP(buf, "-0.000000", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
256 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
257 #endif
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
258
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
259 n = vim_snprintf(buf, bsize, "%s", "漢語");
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
260 assert(n == 6);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
261 assert(bsize == 0 || STRNCMP(buf, "漢語", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
262 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
263
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
264 n = vim_snprintf(buf, bsize, "%8s", "漢語");
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
265 assert(n == 8);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
266 assert(bsize == 0 || STRNCMP(buf, " 漢語", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
267 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
268
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
269 n = vim_snprintf(buf, bsize, "%-8s", "漢語");
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
270 assert(n == 8);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
271 assert(bsize == 0 || STRNCMP(buf, "漢語 ", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
272 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
273
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
274 n = vim_snprintf(buf, bsize, "%.3s", "漢語");
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
275 assert(n == 3);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
276 assert(bsize == 0 || STRNCMP(buf, "漢", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
277 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
278
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
279 n = vim_snprintf(buf, bsize, fmt_5S, "foo");
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
280 assert(n == 5);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
281 assert(bsize == 0 || STRNCMP(buf, " foo", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
282 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
283
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
284 n = vim_snprintf(buf, bsize, "%%%%%%");
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
285 assert(n == 3);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
286 assert(bsize == 0 || STRNCMP(buf, "%%%", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
287 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
288
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
289 n = vim_snprintf(buf, bsize, "%c%c", 1, 2);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
290 assert(n == 2);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
291 assert(bsize == 0 || STRNCMP(buf, "\x01\x02", bsize_int) == 0);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
292 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
293
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
294 // %p format is not tested in vim script tests Test_printf*()
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
295 // as it only makes sense in C code.
19352
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
296 // NOTE: SunOS libc doesn't use the prefix "0x" on %p.
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
297 #ifdef SUN_SYSTEM
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
298 # define PREFIX_LEN 0
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
299 # define PREFIX_STR1 ""
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
300 # define PREFIX_STR2 "00"
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
301 #else
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
302 # define PREFIX_LEN 2
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
303 # define PREFIX_STR1 "0x"
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
304 # define PREFIX_STR2 "0x"
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
305 #endif
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
306 n = vim_snprintf(buf, bsize, "%p", ptr);
19352
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
307 assert(n == 8 + PREFIX_LEN);
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
308 assert(bsize == 0
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
309 || STRNCMP(buf, PREFIX_STR1 "87654321", bsize_int) == 0);
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
310 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
311
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
312 n = vim_snprintf(buf, bsize, fmt_012p, ptr);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
313 assert(n == 12);
19352
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
314 assert(bsize == 0
c617ba6413bb patch 8.2.0234: message test fails on SunOS
Bram Moolenaar <Bram@vim.org>
parents: 19119
diff changeset
315 || STRNCMP(buf, PREFIX_STR2 "0087654321", bsize_int) == 0);
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
316 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
317
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
318 free(buf);
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
319 }
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
320 }
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
321
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
322 /*
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
323 * Test vim_snprintf() with a focus on checking that positional
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
324 * arguments are correctly applied and skipped
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
325 */
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
326 static void
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
327 test_vim_snprintf_positional(void)
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
328 {
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
329 int n;
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
330 size_t bsize;
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
331 int bsize_int;
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
332
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
333 // Loop on various buffer sizes to make sure that truncation of
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
334 // vim_snprintf() is correct.
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
335 for (bsize = 0; bsize < 25; ++bsize)
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
336 {
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
337 bsize_int = (int)bsize - 1;
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
338
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
339 // buf is the heap rather than in the stack
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
340 // so valgrind can detect buffer overflows if any.
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
341 // Use malloc() rather than alloc() as test checks with 0-size
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
342 // buffer and its content should then never be used.
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
343 char *buf = malloc(bsize);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
344
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
345 n = vim_snprintf(buf, bsize, "%1$*2$ld", 1234567L, -9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
346 assert(n == 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
347 assert(bsize == 0 || STRNCMP(buf, "1234567 ", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
348 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
349
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
350 n = vim_snprintf(buf, bsize, "%1$*2$.*3$ld", 1234567L, -9, 5);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
351 assert(n == 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
352 assert(bsize == 0 || STRNCMP(buf, "1234567 ", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
353 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
354
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
355 n = vim_snprintf(buf, bsize, "%1$*3$.*2$ld", 1234567L, 5, -9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
356 assert(n == 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
357 assert(bsize == 0 || STRNCMP(buf, "1234567 ", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
358 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
359
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
360 n = vim_snprintf(buf, bsize, "%3$*1$.*2$ld", -9, 5, 1234567L);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
361 assert(n == 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
362 assert(bsize == 0 || STRNCMP(buf, "1234567 ", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
363 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
364
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
365 n = vim_snprintf(buf, bsize, "%1$ld", 1234567L);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
366 assert(n == 7);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
367 assert(bsize == 0 || STRNCMP(buf, "1234567", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
368 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
369
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
370 n = vim_snprintf(buf, bsize, "%1$*2$ld", 1234567L, 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
371 assert(n == 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
372 assert(bsize == 0 || STRNCMP(buf, " 1234567", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
373 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
374
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
375 n = vim_snprintf(buf, bsize, "%2$ld %1$d %3$lu", 12345, 9L, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
376 assert(n == 15);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
377 assert(bsize == 0 || STRNCMP(buf, "9 12345 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
378 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
379
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
380 n = vim_snprintf(buf, bsize, "%2$d %1$ld %3$lu", 1234567L, 9, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
381 assert(n == 17);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
382 assert(bsize == 0 || STRNCMP(buf, "9 1234567 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
383 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
384
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
385 n = vim_snprintf(buf, bsize, "%2$d %1$lld %3$lu", 1234567LL, 9, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
386 assert(n == 17);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
387 assert(bsize == 0 || STRNCMP(buf, "9 1234567 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
388 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
389
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
390 n = vim_snprintf(buf, bsize, "%2$ld %1$u %3$lu", 12345U, 9L, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
391 assert(n == 15);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
392 assert(bsize == 0 || STRNCMP(buf, "9 12345 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
393 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
394
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
395 n = vim_snprintf(buf, bsize, "%2$d %1$lu %3$lu", 1234567UL, 9, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
396 assert(n == 17);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
397 assert(bsize == 0 || STRNCMP(buf, "9 1234567 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
398 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
399
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
400 n = vim_snprintf(buf, bsize, "%2$d %1$llu %3$lu", 1234567LLU, 9, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
401 assert(n == 17);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
402 assert(bsize == 0 || STRNCMP(buf, "9 1234567 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
403 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
404
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
405 n = vim_snprintf(buf, bsize, "%2$d %1$x %3$lu", 0xdeadbeef, 9, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
406 assert(n == 18);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
407 assert(bsize == 0 || STRNCMP(buf, "9 deadbeef 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
408 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
409
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
410 n = vim_snprintf(buf, bsize, "%2$ld %1$c %3$lu", 'c', 9L, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
411 assert(n == 11);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
412 assert(bsize == 0 || STRNCMP(buf, "9 c 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
413 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
414
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
415 n = vim_snprintf(buf, bsize, "%2$ld %1$s %3$lu", "hi", 9L, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
416 assert(n == 12);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
417 assert(bsize == 0 || STRNCMP(buf, "9 hi 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
418 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
419
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
420 n = vim_snprintf(buf, bsize, "%2$ld %1$e %3$lu", 0.0, 9L, 7654321UL);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
421 assert(n == 22);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
422 assert(bsize == 0 || STRNCMP(buf, "9 0.000000e+00 7654321", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
423 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
424
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
425 n = vim_snprintf(buf, bsize, fmt_212s, "one", "two", "three");
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
426 assert(n == 11);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
427 assert(bsize == 0 || STRNCMP(buf, "two one two", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
428 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
429
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
430 n = vim_snprintf(buf, bsize, "%3$s %1$s %2$s", "one", "two", "three");
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
431 assert(n == 13);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
432 assert(bsize == 0 || STRNCMP(buf, "three one two", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
433 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
434
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
435 n = vim_snprintf(buf, bsize, "%1$d", 1234567);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
436 assert(n == 7);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
437 assert(bsize == 0 || STRNCMP(buf, "1234567", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
438 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
439
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
440 n = vim_snprintf(buf, bsize, "%1$x", 0xdeadbeef);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
441 assert(n == 8);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
442 assert(bsize == 0 || STRNCMP(buf, "deadbeef", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
443 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
444
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
445 n = vim_snprintf(buf, bsize, fmt_06pb, (uvarnumber_T)12, 6);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
446 assert(n == 6);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
447 assert(bsize == 0 || STRNCMP(buf, "001100", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
448 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
449
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
450 n = vim_snprintf(buf, bsize, "%1$s %2$s", "one", "two");
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
451 assert(n == 7);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
452 assert(bsize == 0 || STRNCMP(buf, "one two", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
453 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
454
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
455 n = vim_snprintf(buf, bsize, fmt_06b, (uvarnumber_T)12);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
456 assert(n == 6);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
457 assert(bsize == 0 || STRNCMP(buf, "001100", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
458 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
459
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
460 n = vim_snprintf(buf, bsize, fmt_21s, "one", "two", "three");
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
461 assert(n == 7);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
462 assert(bsize == 0 || STRNCMP(buf, "two one", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
463 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
464
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
465 #ifdef FEAT_FLOAT
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
466 n = vim_snprintf(buf, bsize, "%1$f", 1.234);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
467 assert(n == 8);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
468 assert(bsize == 0 || STRNCMP(buf, "1.234000", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
469 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
470
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
471 n = vim_snprintf(buf, bsize, "%1$e", 1.234);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
472 assert(n == 12);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
473 assert(bsize == 0 || STRNCMP(buf, "1.234000e+00", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
474 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
475
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
476 n = vim_snprintf(buf, bsize, "%1$f", 0.0/0.0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
477 assert(n == 3);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
478 assert(bsize == 0 || STRNCMP(buf, "nan", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
479 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
480
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
481 n = vim_snprintf(buf, bsize, "%1$f", 1.0/0.0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
482 assert(n == 3);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
483 assert(bsize == 0 || STRNCMP(buf, "inf", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
484 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
485
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
486 n = vim_snprintf(buf, bsize, "%1$f", -1.0/0.0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
487 assert(n == 4);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
488 assert(bsize == 0 || STRNCMP(buf, "-inf", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
489 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
490
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
491 n = vim_snprintf(buf, bsize, "%1$f", -0.0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
492 assert(n == 9);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
493 assert(bsize == 0 || STRNCMP(buf, "-0.000000", bsize_int) == 0);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
494 assert(bsize == 0 || buf[MIN(n, bsize_int)] == '\0');
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
495 #endif
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
496
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
497 free(buf);
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
498 }
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
499 }
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
500
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 int
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502 main(int argc, char **argv)
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 {
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19352
diff changeset
504 CLEAR_FIELD(params);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 params.argc = argc;
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 params.argv = argv;
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 common_init(&params);
18999
6fb11e7fb9cd patch 8.2.0060: message test only runs with one encoding
Bram Moolenaar <Bram@vim.org>
parents: 18931
diff changeset
508
28457
4dcccb2673fe patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 24709
diff changeset
509 set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"utf-8", 0);
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
510 init_chartab();
18999
6fb11e7fb9cd patch 8.2.0060: message test only runs with one encoding
Bram Moolenaar <Bram@vim.org>
parents: 18931
diff changeset
511 test_trunc_string();
24709
9d304d363ab6 patch 8.2.2893: multi-byte text in popup title shows up wrong
Bram Moolenaar <Bram@vim.org>
parents: 23946
diff changeset
512 test_trunc_string_mbyte();
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
513 test_vim_snprintf();
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
514 test_vim_snprintf_positional();
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515
28457
4dcccb2673fe patch 8.2.4753: error from setting an option is silently ignored
Bram Moolenaar <Bram@vim.org>
parents: 24709
diff changeset
516 set_option_value_give_err((char_u *)"encoding", 0, (char_u *)"latin1", 0);
18999
6fb11e7fb9cd patch 8.2.0060: message test only runs with one encoding
Bram Moolenaar <Bram@vim.org>
parents: 18931
diff changeset
517 init_chartab();
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
518 test_trunc_string();
19011
61d94accf16f patch 8.2.0066: some corners of vim_snprintf() are not tested
Bram Moolenaar <Bram@vim.org>
parents: 18999
diff changeset
519 test_vim_snprintf();
32775
2d5e8c46508b patch 9.0.1704: Cannot use positional arguments for printf()
Christian Brabandt <cb@256bit.org>
parents: 30986
diff changeset
520 test_vim_snprintf_positional();
18999
6fb11e7fb9cd patch 8.2.0060: message test only runs with one encoding
Bram Moolenaar <Bram@vim.org>
parents: 18931
diff changeset
521
9542
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 return 0;
00ee8d8c2e0c commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 }