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 display_special;
73 bool lock_files;
74 bool optimize_true_color;
75 bool select_cursor_char;
76 bool set_window_title;
77 bool show_line_numbers;
78 bool tab_bar;
79 bool utf8_bom; // Default value for new files
80 uint8_t scroll_margin;
81 uint8_t crlf_newlines; // Default value for new files
82 uint8_t case_sensitive_search; // SearchCaseSensitivity
83 uint8_t window_separator; // WindowSeparatorType
84 uint8_t msg_compile; // Default EditorState::messages[] index for `compile`
85 uint8_t msg_tag; // Default EditorState::messages[] index for `tag`
86 unsigned int esc_timeout; // See term_read_input()
87 uint_least64_t filesize_limit; // Size limit imposed by load_buffer()
88 uint_least64_t syntax_line_limit; // Line length at which LocalOptions::syntax is disabled
89 uint_least64_t syntax_size_limit; // File size at which LocalOptions::syntax is disabled
90 const char *statusline_left;
91 const char *statusline_right;
92 } GlobalOptions;
93
94 #undef COMMON_OPTIONS
95
96 114 static inline bool use_spaces_for_indent(const LocalOptions *opt)
97 {
98
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;
99 }
100
101 struct EditorState;
102
103 bool set_option(struct EditorState *e, const char *name, const char *value, bool local, bool global, bool quiet);
104 bool set_bool_option(struct EditorState *e, const char *name, bool local, bool global, bool quiet);
105 bool toggle_option(struct EditorState *e, const char *name, bool global, bool verbose);
106 bool toggle_option_values(struct EditorState *e, const char *name, bool global, bool verbose, char **values, size_t count);
107 bool validate_local_options(ErrorBuffer *ebuf, char **strs);
108 void collect_options(PointerArray *a, StringView prefix, bool local, bool global);
109 void collect_auto_options(PointerArray *a, StringView prefix);
110 void collect_toggleable_options(PointerArray *a, StringView prefix, bool global);
111 void collect_option_values(struct EditorState *e, PointerArray *a, const char *option, StringView prefix);
112 String dump_options(GlobalOptions *gopts, LocalOptions *lopts);
113 const char *get_option_value_string(struct EditorState *e, const char *name);
114
115 #if DEBUG_ASSERTIONS_ENABLED
116 void sanity_check_global_options(const GlobalOptions *opts);
117 void sanity_check_local_options(const LocalOptions *lopts);
118 #else
119 static inline void sanity_check_global_options(const GlobalOptions* UNUSED_ARG(gopts)) {}
120 static inline void sanity_check_local_options(const LocalOptions* UNUSED_ARG(lopts)) {}
121 #endif
122
123 #endif
124