NeoMutt  2020-06-26-250-g349c94
Teaching an old dog new tricks
DOXYGEN
parse_test.c File Reference

Test the config parsing code. More...

#include "config.h"
#include <stdio.h>
#include "mutt/lib.h"
#include "lib.h"
#include "init.h"
#include "mutt_commands.h"
+ Include dependency graph for parse_test.c:

Go to the source code of this file.

Functions

void test_parse_set (void)
 Test the config parsing. More...
 

Detailed Description

Test the config parsing code.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file parse_test.c.

Function Documentation

◆ test_parse_set()

void test_parse_set ( void  )

Test the config parsing.

Definition at line 39 of file parse_test.c.

40 {
41  const char *vars[] = {
42  "from", // ADDRESS
43  "beep", // BOOL
44  "ispell", // COMMAND
45  "mbox_type", // ENUM
46  "to_chars", // MBTABLE
47  "net_inc", // NUMBER
48  "signature", // PATH
49  "print", // QUAD
50  "mask", // REGEX
51  "sort", // SORT
52  "attribution", // STRING
53  "zzz", // UNKNOWN
54  "my_var", // MY_VAR
55  };
56 
57  const char *commands[] = {
58  "set",
59  "toggle",
60  "reset",
61  "unset",
62  };
63 
64  const char *tests[] = {
65  "%s %s", "%s %s=42", "%s %s?", "%s ?%s", "%s ?%s=42",
66  "%s ?%s?", "%s no%s", "%s no%s=42", "%s no%s?", "%s inv%s",
67  "%s inv%s=42", "%s inv%s?", "%s &%s", "%s &%s=42", "%s &%s?",
68  };
69 
70  struct Buffer err = mutt_buffer_make(256);
71  char line[64];
72 
73  for (size_t v = 0; v < mutt_array_size(vars); v++)
74  {
75  // printf("--------------------------------------------------------------------------------\n");
76  // printf("VARIABLE %s\n", vars[v]);
77  for (size_t c = 0; c < mutt_array_size(commands); c++)
78  {
79  // printf("----------------------------------------\n");
80  // printf("COMMAND %s\n", commands[c]);
81  for (size_t t = 0; t < mutt_array_size(tests); t++)
82  {
83  mutt_buffer_reset(&err);
84 
85  snprintf(line, sizeof(line), tests[t], commands[c], vars[v]);
86  printf("%-26s", line);
87  enum CommandResult rc = mutt_parse_rc_line(line, &err);
88  printf("%2d %s\n", rc, err.data);
89  }
90  printf("\n");
91  }
92  // printf("\n");
93  }
94 
95  mutt_buffer_dealloc(&err);
96 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
CommandResult
Error codes for command_t parse functions.
Definition: mutt_commands.h:33
static const struct TestValue tests[]
Definition: mutt_str_atoi.c:36
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
enum CommandResult mutt_parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: init.c:1041
#define mutt_array_size(x)
Definition: memory.h:33
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
char * data
Pointer to data.
Definition: buffer.h:35
int const char int line
Definition: acutest.h:617
+ Here is the call graph for this function:
+ Here is the caller graph for this function: