File src/menus/menus.c changed (mode: 100644) (index 9260aba5e..71c04713d) |
51 |
51 |
#include "../utils/path.h" |
#include "../utils/path.h" |
52 |
52 |
#include "../utils/str.h" |
#include "../utils/str.h" |
53 |
53 |
#include "../utils/string_array.h" |
#include "../utils/string_array.h" |
|
54 |
|
#include "../utils/test_helpers.h" |
54 |
55 |
#include "../utils/utf8.h" |
#include "../utils/utf8.h" |
55 |
56 |
#include "../utils/utils.h" |
#include "../utils/utils.h" |
56 |
57 |
#include "../background.h" |
#include "../background.h" |
|
... |
... |
static int prompt_error_msg_internalv(const char title[], const char format[], |
66 |
67 |
int prompt_skip, va_list pa); |
int prompt_skip, va_list pa); |
67 |
68 |
static int prompt_error_msg_internal(const char title[], const char message[], |
static int prompt_error_msg_internal(const char title[], const char message[], |
68 |
69 |
int prompt_skip); |
int prompt_skip); |
69 |
|
static char * parse_spec(const char spec[], int *line_num); |
|
|
70 |
|
TSTATIC char * parse_spec(const char spec[], int *line_num); |
70 |
71 |
static void open_selected_file(const char path[], int line_num); |
static void open_selected_file(const char path[], int line_num); |
71 |
72 |
static void navigate_to_selected_file(FileView *view, const char path[]); |
static void navigate_to_selected_file(FileView *view, const char path[]); |
72 |
73 |
static void normalize_top(menu_info *m); |
static void normalize_top(menu_info *m); |
|
... |
... |
goto_selected_file(FileView *view, const char spec[], int try_open) |
484 |
485 |
free(path_buf); |
free(path_buf); |
485 |
486 |
} |
} |
486 |
487 |
|
|
487 |
|
/* Extracts path and line number from the spec. Returns path and sets *line_num |
|
488 |
|
* to line number, otherwise NULL is returned. */ |
|
489 |
|
static char * |
|
|
488 |
|
/* Extracts path and line number from the spec (1 when absent from the spec). |
|
489 |
|
* Returns path and sets *line_num to line number, otherwise NULL is |
|
490 |
|
* returned. */ |
|
491 |
|
TSTATIC char * |
490 |
492 |
parse_spec(const char spec[], int *line_num) |
parse_spec(const char spec[], int *line_num) |
491 |
493 |
{ |
{ |
492 |
494 |
char *path_buf; |
char *path_buf; |
File src/menus/menus.h changed (mode: 100644) (index 3e7d61884..44694452d) |
23 |
23 |
#include <stdio.h> /* FILE */ |
#include <stdio.h> /* FILE */ |
24 |
24 |
#include <wchar.h> /* wchar_t */ |
#include <wchar.h> /* wchar_t */ |
25 |
25 |
|
|
|
26 |
|
#include "../utils/test_helpers.h" |
26 |
27 |
#include "../ui.h" |
#include "../ui.h" |
27 |
28 |
|
|
28 |
29 |
enum |
enum |
|
... |
... |
int display_menu(menu_info *m, FileView *view); |
156 |
157 |
* next. */ |
* next. */ |
157 |
158 |
KHandlerResponse filelist_khandler(menu_info *m, const wchar_t keys[]); |
KHandlerResponse filelist_khandler(menu_info *m, const wchar_t keys[]); |
158 |
159 |
|
|
|
160 |
|
TSTATIC_DEFS( |
|
161 |
|
char * parse_spec(const char spec[], int *line_num); |
|
162 |
|
) |
|
163 |
|
|
159 |
164 |
#endif /* VIFM__MENUS__MENUS_H__ */ |
#endif /* VIFM__MENUS__MENUS_H__ */ |
160 |
165 |
|
|
161 |
166 |
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ |
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ |
File tests/misc/parse_spec.c added (mode: 100644) (index 000000000..a05ef5163) |
|
1 |
|
#include "seatest.h" |
|
2 |
|
|
|
3 |
|
#include <stdlib.h> /* free() */ |
|
4 |
|
|
|
5 |
|
#include "../../src/menus/menus.h" |
|
6 |
|
|
|
7 |
|
#define DEFAULT_LINENUM 1 |
|
8 |
|
|
|
9 |
|
static void |
|
10 |
|
test_empty_path_without_linenum(void) |
|
11 |
|
{ |
|
12 |
|
int line_num; |
|
13 |
|
char *const path = parse_spec("", &line_num); |
|
14 |
|
|
|
15 |
|
assert_string_equal("./", path); |
|
16 |
|
assert_int_equal(DEFAULT_LINENUM, line_num); |
|
17 |
|
|
|
18 |
|
free(path); |
|
19 |
|
} |
|
20 |
|
|
|
21 |
|
static void |
|
22 |
|
test_empty_path_with_linenum(void) |
|
23 |
|
{ |
|
24 |
|
int line_num; |
|
25 |
|
char *const path = parse_spec(":78", &line_num); |
|
26 |
|
|
|
27 |
|
assert_string_equal("./", path); |
|
28 |
|
assert_int_equal(78, line_num); |
|
29 |
|
|
|
30 |
|
free(path); |
|
31 |
|
} |
|
32 |
|
|
|
33 |
|
static void |
|
34 |
|
test_absolute_path_without_linenum(void) |
|
35 |
|
{ |
|
36 |
|
int line_num; |
|
37 |
|
char *const path = parse_spec("/home/user", &line_num); |
|
38 |
|
|
|
39 |
|
assert_string_equal("/home/user", path); |
|
40 |
|
assert_int_equal(DEFAULT_LINENUM, line_num); |
|
41 |
|
|
|
42 |
|
free(path); |
|
43 |
|
} |
|
44 |
|
|
|
45 |
|
static void |
|
46 |
|
test_absolute_path_with_linenum(void) |
|
47 |
|
{ |
|
48 |
|
int line_num; |
|
49 |
|
char *const path = parse_spec("/home/user:1234", &line_num); |
|
50 |
|
|
|
51 |
|
assert_string_equal("/home/user", path); |
|
52 |
|
assert_int_equal(1234, line_num); |
|
53 |
|
|
|
54 |
|
free(path); |
|
55 |
|
} |
|
56 |
|
|
|
57 |
|
static void |
|
58 |
|
test_relative_path_without_linenum(void) |
|
59 |
|
{ |
|
60 |
|
int line_num; |
|
61 |
|
char *const path = parse_spec("repos/repo", &line_num); |
|
62 |
|
|
|
63 |
|
assert_string_equal("./repos/repo", path); |
|
64 |
|
assert_int_equal(DEFAULT_LINENUM, line_num); |
|
65 |
|
|
|
66 |
|
free(path); |
|
67 |
|
} |
|
68 |
|
|
|
69 |
|
static void |
|
70 |
|
test_relative_path_with_linenum(void) |
|
71 |
|
{ |
|
72 |
|
int line_num; |
|
73 |
|
char *const path = parse_spec("repos/repo:9876", &line_num); |
|
74 |
|
|
|
75 |
|
assert_string_equal("./repos/repo", path); |
|
76 |
|
assert_int_equal(9876, line_num); |
|
77 |
|
|
|
78 |
|
free(path); |
|
79 |
|
} |
|
80 |
|
|
|
81 |
|
#ifdef _WIN32 |
|
82 |
|
|
|
83 |
|
static void |
|
84 |
|
test_win_relative_path_without_linenum(void) |
|
85 |
|
{ |
|
86 |
|
int line_num; |
|
87 |
|
char *const path = parse_spec("repos\\repo", &line_num); |
|
88 |
|
|
|
89 |
|
assert_string_equal("./repos/repo", path); |
|
90 |
|
assert_int_equal(DEFAULT_LINENUM, line_num); |
|
91 |
|
|
|
92 |
|
free(path); |
|
93 |
|
} |
|
94 |
|
|
|
95 |
|
static void |
|
96 |
|
test_win_relative_path_with_linenum(void) |
|
97 |
|
{ |
|
98 |
|
int line_num; |
|
99 |
|
char *const path = parse_spec("repos\\repo:9876", &line_num); |
|
100 |
|
|
|
101 |
|
assert_string_equal("./repos/repo", path); |
|
102 |
|
assert_int_equal(9876, line_num); |
|
103 |
|
|
|
104 |
|
free(path); |
|
105 |
|
} |
|
106 |
|
|
|
107 |
|
#endif |
|
108 |
|
|
|
109 |
|
void |
|
110 |
|
parse_spec_tests(void) |
|
111 |
|
{ |
|
112 |
|
test_fixture_start(); |
|
113 |
|
|
|
114 |
|
run_test(test_empty_path_without_linenum); |
|
115 |
|
run_test(test_empty_path_with_linenum); |
|
116 |
|
run_test(test_absolute_path_without_linenum); |
|
117 |
|
run_test(test_absolute_path_with_linenum); |
|
118 |
|
run_test(test_relative_path_without_linenum); |
|
119 |
|
run_test(test_relative_path_with_linenum); |
|
120 |
|
#ifdef _WIN32 |
|
121 |
|
run_test(test_win_relative_path_without_linenum); |
|
122 |
|
run_test(test_win_relative_path_with_linenum); |
|
123 |
|
#endif |
|
124 |
|
|
|
125 |
|
test_fixture_end(); |
|
126 |
|
} |
|
127 |
|
|
|
128 |
|
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ |
|
129 |
|
/* vim: set cinoptions+=t0 : */ |