Merge remote-tracking branch 'origin/master' into sheet
[pspp] / tests / ui / syntax-gen-test.c
1 /* 
2 PSPP - a program for statistical analysis.
3 Copyright (C) 2017 Free Software Foundation, Inc.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <config.h>
20
21 #include "ui/syntax-gen.h"
22
23 #include <stdio.h>
24
25 static void
26 test_runner (const char *format, ...)
27 {
28   struct string syntax;
29   va_list args;
30   va_start (args, format);
31
32   ds_init_empty (&syntax);
33
34   syntax_gen_pspp_valist (&syntax, format, args);
35
36   va_end (args);
37
38   puts (ds_cstr (&syntax));
39
40   ds_destroy (&syntax);
41 }
42
43 int
44 main (void)
45 {
46   test_runner ("A simple string: %ssEND", "Hello world");
47   test_runner ("A syntax string: %sqEND", "Hello world");
48   test_runner ("A syntax string containing \": %sqEND", "here\"is the quote");
49   test_runner ("A syntax string containing non-printables: %sqEND", "A CtrlL\fchar");
50   test_runner ("An integer: %dEND", 98765);
51   test_runner ("A floating point number: %gEND", 3.142);
52   test_runner ("A floating point number with default precision: %fEND", 1.234);
53   test_runner ("A floating point number with given precision: %.20fEND", 1.234);
54   test_runner ("A literal %%");
55
56   test_runner ("and %ss a %sq of %d different %f examples %g of 100%% conversions.",
57                "finally", "concatination", 6, 20.309, 23.09);
58
59   return 0;
60 }