File: dump.c

package info (click to toggle)
dte 1.10-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,152 kB
  • sloc: ansic: 28,421; sh: 94; awk: 56; makefile: 13; sed: 1
file content (78 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "test.h"
#include "alias.h"
#include "bind.h"
#include "command/args.h"
#include "command/parse.h"
#include "commands.h"
#include "compiler.h"
#include "config.h"
#include "filetype.h"
#include "frame.h"
#include "options.h"
#include "syntax/color.h"
#include "util/str-util.h"

static const struct {
    const char name[10];
    bool check_parse;
    bool check_name;
    String (*dump)(void);
} handlers[] = {
    {"alias", true, true, dump_aliases},
    {"bind", true, true, dump_bindings},
    {"errorfmt", true, true, dump_compilers},
    {"ft", true, true, dump_ft},
    {"hi", true, true, dump_hl_colors},
    {"include", false, false, dump_builtin_configs},
    {"option", true, false, dump_options},
    {"wsplit", false, false, dump_frames},
};

static void test_dump_handlers(void)
{
    for (size_t i = 0; i < ARRAY_COUNT(handlers); i++) {
        String str = handlers[i].dump();
        size_t pos = 0;
        while (pos < str.len) {
            const char *line = buf_next_line(str.buffer, &pos, str.len);
            ASSERT_NONNULL(line);
            char c = line[0];
            if (c == '\0' || c == '#' || !handlers[i].check_parse) {
                continue;
            }

            PointerArray arr = PTR_ARRAY_INIT;
            CommandParseError parse_err = parse_commands(&arr, line);
            EXPECT_EQ(parse_err, CMDERR_NONE);
            EXPECT_TRUE(arr.count >= 2);
            if (parse_err != CMDERR_NONE || arr.count < 2) {
                continue;
            }

            if (handlers[i].check_name) {
                EXPECT_STREQ(arr.ptrs[0], handlers[i].name);
            }

            const Command *cmd = find_normal_command(arr.ptrs[0]);
            EXPECT_NONNULL(cmd);
            if (!cmd) {
                continue;
            }

            CommandArgs a = {.args = (char**)arr.ptrs + 1};
            ArgParseError arg_err = do_parse_args(cmd, &a);
            EXPECT_EQ(arg_err, 0);
            if (arg_err != 0) {
                continue;
            }
            ptr_array_free(&arr);
        }
        string_free(&str);
    }
}

static const TestEntry tests[] = {
    TEST(test_dump_handlers),
};

const TestGroup dump_tests = TEST_GROUP(tests);