NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
parse_test.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdio.h>
31 #include "mutt/lib.h"
32 #include "lib.h"
33 #include "init.h"
34 #include "mutt_commands.h"
35 
39 void test_parse_set(void)
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:34
Config/command parsing.
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:1039
void test_parse_set(void)
Test the config parsing.
Definition: parse_test.c:39
#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
Definitions of NeoMutt commands.
Convenience wrapper for the debug headers.
Convenience wrapper for the library headers.