maint: specify translations explicitly when pulling hints from transifex
[midnight-commander.git] / tests / lib / search / hex_translate_to_regex.c
blob86ed23a5323f208a240e79f397223c7e9625ae29
1 /*
2 libmc - checks for hex pattern parsing
4 Copyright (C) 2017-2022
5 Free Software Foundation, Inc.
7 This file is part of the Midnight Commander.
9 The Midnight Commander is free software: you can redistribute it
10 and/or modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation, either version 3 of the License,
12 or (at your option) any later version.
14 The Midnight Commander is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define TEST_SUITE_NAME "lib/search/hex"
25 #include "tests/mctest.h"
27 #include "hex.c" /* for testing static functions */
29 /* --------------------------------------------------------------------------------------------- */
31 /* @DataSource("test_hex_translate_to_regex_ds") */
32 /* *INDENT-OFF* */
33 static const struct test_hex_translate_to_regex_ds
35 const char *input_value;
36 const char *expected_result;
37 mc_search_hex_parse_error_t expected_error;
38 } test_hex_translate_to_regex_ds[] =
41 /* Simplest case */
42 "12 34",
43 "\\x12\\x34",
44 MC_SEARCH_HEX_E_OK
47 /* Prefixes (0x, 0X) */
48 "0x12 0X34",
49 "\\x12\\x34",
50 MC_SEARCH_HEX_E_OK
53 /* Prefix "0" doesn't signify octal! Numbers are always interpreted in hex. */
54 "012",
55 "\\x12",
56 MC_SEARCH_HEX_E_OK
59 /* Extra whitespace */
60 " 12 34 ",
61 "\\x12\\x34",
62 MC_SEARCH_HEX_E_OK
65 /* Min/max values */
66 "0 ff",
67 "\\x00\\xFF",
68 MC_SEARCH_HEX_E_OK
71 /* Error: Number out of range */
72 "100",
73 NULL,
74 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE
77 /* Error: Number out of range (negative) */
78 "-1",
79 NULL,
80 MC_SEARCH_HEX_E_NUM_OUT_OF_RANGE
83 /* Error: Invalid characters */
84 "1 z 2",
85 NULL,
86 MC_SEARCH_HEX_E_INVALID_CHARACTER
89 * Quotes.
92 " \"abc\" ",
93 "abc",
94 MC_SEARCH_HEX_E_OK
97 /* Preserve upper/lower case */
98 "\"aBc\"",
99 "aBc",
100 MC_SEARCH_HEX_E_OK
103 " 12\"abc\"34 ",
104 "\\x12abc\\x34",
105 MC_SEARCH_HEX_E_OK
108 "\"a\"\"b\"",
109 "ab",
110 MC_SEARCH_HEX_E_OK
112 /* Empty quotes */
114 "\"\"",
116 MC_SEARCH_HEX_E_OK
119 "12 \"\"",
120 "\\x12",
121 MC_SEARCH_HEX_E_OK
123 /* Error: Unmatched quotes */
125 "\"a",
126 NULL,
127 MC_SEARCH_HEX_E_UNMATCHED_QUOTES
130 "\"",
131 NULL,
132 MC_SEARCH_HEX_E_UNMATCHED_QUOTES
134 /* Escaped quotes */
136 "\"a\\\"b\"",
137 "a\"b",
138 MC_SEARCH_HEX_E_OK
141 "\"a\\\\b\"",
142 "a\\b",
143 MC_SEARCH_HEX_E_OK
146 /* *INDENT-ON* */
148 /* @Test(dataSource = "test_hex_translate_to_regex_ds") */
149 /* *INDENT-OFF* */
150 START_PARAMETRIZED_TEST (test_hex_translate_to_regex, test_hex_translate_to_regex_ds)
151 /* *INDENT-ON* */
153 GString *tmp, *dest_str;
154 mc_search_hex_parse_error_t error = MC_SEARCH_HEX_E_OK;
156 /* given */
157 tmp = g_string_new (data->input_value);
159 /* when */
160 dest_str = mc_search__hex_translate_to_regex (tmp, &error, NULL);
162 g_string_free (tmp, TRUE);
164 /* then */
165 if (dest_str != NULL)
167 mctest_assert_str_eq (dest_str->str, data->expected_result);
168 g_string_free (dest_str, TRUE);
170 else
171 ck_assert_int_eq (error, data->expected_error);
173 /* *INDENT-OFF* */
174 END_PARAMETRIZED_TEST
175 /* *INDENT-ON* */
177 /* --------------------------------------------------------------------------------------------- */
180 main (void)
182 TCase *tc_core;
184 tc_core = tcase_create ("Core");
186 /* Add new tests here: *************** */
187 mctest_add_parameterized_test (tc_core, test_hex_translate_to_regex,
188 test_hex_translate_to_regex_ds);
189 /* *********************************** */
191 return mctest_run_all (tc_core);
194 /* --------------------------------------------------------------------------------------------- */