dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 2 / 0 / 2
Functions: 100.0% 1 / 0 / 1
Branches: 75.0% 3 / 0 / 4

src/options.h
Line Branch Exec Source
1 #ifndef OPTIONS_H
2 #define OPTIONS_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include "command/error.h"
8 #include "regexp.h"
9 #include "util/debug.h"
10 #include "util/macros.h"
11 #include "util/ptr-array.h"
12 #include "util/string-view.h"
13 #include "util/string.h"
14
15 enum {
16 INDENT_WIDTH_MAX = 8,
17 TAB_WIDTH_MAX = 8,
18 TEXT_WIDTH_MAX = 1000,
19 };
20
21 // Note: this must be kept in sync with ws_error_values[]
22 typedef enum {
23 WSE_SPACE_INDENT = 1 << 0, // Spaces in indent (except WSE_SPACE_ALIGN)
24 WSE_SPACE_ALIGN = 1 << 1, // Less than tab-width spaces at end of indent
25 WSE_TAB_INDENT = 1 << 2, // Tab in indent
26 WSE_TAB_AFTER_INDENT = 1 << 3, // Tab anywhere but indent
27 WSE_SPECIAL = 1 << 4, // Special whitespace characters
28 WSE_AUTO_INDENT = 1 << 5, // expand-tab ? WSE_TAB_AFTER_INDENT | WSE_TAB_INDENT : WSE_SPACE_INDENT
29 WSE_TRAILING = 1 << 6, // Trailing whitespace
30 WSE_ALL_TRAILING = 1 << 7, // Like WSE_TRAILING, but including around cursor
31 } WhitespaceErrorFlags;
32
33 // Note: this must be kept in sync with save_unmodified_enum[]
34 typedef enum {
35 SAVE_NONE,
36 SAVE_TOUCH,
37 SAVE_FULL,
38 } SaveUnmodifiedType;
39
40 #define COMMON_OPTIONS \
41 unsigned int detect_indent; \
42 unsigned int ws_error; \
43 unsigned int text_width; \
44 uint8_t indent_width; \
45 uint8_t tab_width; \
46 uint8_t save_unmodified; \
47 bool auto_indent; \
48 bool editorconfig; \
49 bool emulate_tab; \
50 bool expand_tab; \
51 bool file_history; \
52 bool fsync; \
53 bool overwrite; \
54 bool syntax
55
56 typedef struct {
57 COMMON_OPTIONS;
58 } CommonOptions;
59
60 // Note: all members should be initialized in buffer_new()
61 typedef struct {
62 COMMON_OPTIONS;
63 // Only local
64 bool brace_indent;
65 const char *filetype;
66 const InternedRegexp *indent_regex;
67 } LocalOptions;
68
69 typedef struct {
70 COMMON_OPTIONS;
71 // Only global
72 bool center_at_eof;
73 bool display_special;
74 bool lock_files;
75 bool optimize_true_color;
76 bool select_cursor_char;
77 bool set_window_title;
78 bool show_line_numbers;
79 bool tab_bar;
80 bool utf8_bom; // Default value for new files
81 uint8_t scroll_margin;
82 uint8_t crlf_newlines; // Default value for new files
83 uint8_t case_sensitive_search; // SearchCaseSensitivity
84 uint8_t window_separator; // WindowSeparatorType
85 uint8_t msg_compile; // Default EditorState::messages[] index for `compile`
86 uint8_t msg_tag; // Default EditorState::messages[] index for `tag`
87 unsigned int esc_timeout; // See term_read_input()
88 uint_least64_t filesize_limit; // Size limit imposed by load_buffer()
89 uint_least64_t syntax_line_limit; // Line length at which LocalOptions::syntax is disabled
90 uint_least64_t syntax_size_limit; // File size at which LocalOptions::syntax is disabled
91 const char *statusline_left;
92 const char *statusline_right;
93 } GlobalOptions;
94
95 #undef COMMON_OPTIONS
96
97 114 static inline bool use_spaces_for_indent(const LocalOptions *opt)
98 {
99
3/4
✓ Branch 2 → 3 taken 16 times.
✓ Branch 2 → 5 taken 98 times.
✓ Branch 3 → 4 taken 16 times.
✗ Branch 3 → 5 not taken.
114 return opt->expand_tab || opt->indent_width != opt->tab_width;
100 }
101
102 struct EditorState;
103
104 bool is_option(const char *name) PURE;
105 bool set_option(struct EditorState *e, const char *name, const char *value, bool local, bool global, bool quiet);
106 bool set_bool_option(struct EditorState *e, const char *name, bool local, bool global, bool quiet);
107 bool toggle_option(struct EditorState *e, const char *name, bool global, bool verbose);
108 bool toggle_option_values(struct EditorState *e, const char *name, bool global, bool verbose, char **values, size_t count);
109 bool validate_local_options(ErrorBuffer *ebuf, char **strs);
110 void collect_options(PointerArray *a, StringView prefix, bool local, bool global);
111 void collect_auto_options(PointerArray *a, StringView prefix);
112 void collect_toggleable_options(PointerArray *a, StringView prefix, bool global);
113 void collect_option_values(struct EditorState *e, PointerArray *a, const char *option, StringView prefix);
114 String dump_options(GlobalOptions *gopts, LocalOptions *lopts);
115 const char *get_option_value_string(struct EditorState *e, const char *name);
116
117 #if DEBUG_ASSERTIONS_ENABLED
118 void sanity_check_global_options(const GlobalOptions *opts);
119 void sanity_check_local_options(const LocalOptions *lopts);
120 #else
121 static inline void sanity_check_global_options(const GlobalOptions* UNUSED_ARG(gopts)) {}
122 static inline void sanity_check_local_options(const LocalOptions* UNUSED_ARG(lopts)) {}
123 #endif
124
125 #endif
126