Debian Codegraph @

tests/unit/test_clean_safe.template

raw
1 /**
2 * This file is part of the Detox package.
3 *
4 * Copyright (c) Doug Harple <[email protected]>
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 */
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13
14 #include "builtin_table.h"
15 #include "clean_string.h"
16 #include "detox_struct.h"
17 #include "table.h"
18
19 #include "unit_struct.h"
20
21 #define DATA_COUNT 46
22 static struct test_filename data[DATA_COUNT] = {
23
24 // legacy tests
25
26 { .filename = "lower", .expected_a = "lower" },
27 { .filename = "^acute", .expected_a = "^acute" },
28 { .filename = "&ampersand", .expected_a = "_and_ampersand" },
29 { .filename = "<angle bracket left", .expected_a = "_angle_bracket_left" },
30 { .filename = ">angle bracket right", .expected_a = "_angle_bracket_right" },
31 { .filename = "\\back slash", .expected_a = "_back_slash" },
32 { .filename = "`back tick", .expected_a = "_back_tick" },
33 { .filename = "|bar", .expected_a = "_bar" },
34 { .filename = "{brace left", .expected_a = "-brace_left" },
35 { .filename = "}brace right", .expected_a = "-brace_right" },
36 { .filename = ":colon", .expected_a = "_colon" },
37 { .filename = ",comma", .expected_a = ",comma" },
38 { .filename = "@commercial at", .expected_a = "_commercial_at" },
39 { .filename = "dash-", .expected_a = "dash-" },
40 { .filename = "#dash_octothorpe-", .expected_a = "#dash_octothorpe-" },
41 { .filename = "_dash_underscore-", .expected_a = "_dash_underscore-" },
42 { .filename = "$dollar sign", .expected_a = "_dollar_sign" },
43 { .filename = "\"double quote", .expected_a = "_double_quote" },
44 { .filename = "ends with octothorpe#", .expected_a = "ends_with_octothorpe#" },
45 { .filename = "!exclamation point", .expected_a = "_exclamation_point" },
46 { .filename = "#octothorpe", .expected_a = "#octothorpe" },
47 { .filename = "#-octothorpe_dash", .expected_a = "#-octothorpe_dash" },
48 { .filename = "(parenthesis left", .expected_a = "-parenthesis_left" },
49 { .filename = ")parenthesis right", .expected_a = "-parenthesis_right" },
50 { .filename = "%percent", .expected_a = "%percent" },
51 { .filename = "+plus", .expected_a = "+plus" },
52 { .filename = "?question mark", .expected_a = "_question_mark" },
53 { .filename = ";semi colon", .expected_a = "_semi_colon" },
54 { .filename = "'single quote", .expected_a = "_single_quote" },
55 { .filename = " space", .expected_a = "_space" },
56 { .filename = "[square bracket left", .expected_a = "-square_bracket_left" },
57 { .filename = "]square bracket right", .expected_a = "-square_bracket_right" },
58 { .filename = "_-underscore_dash", .expected_a = "_-underscore_dash" },
59 { .filename = "_underscore", .expected_a = "_underscore" },
60 { .filename = "~tilde", .expected_a = "~tilde" },
61
62 // other
63
64 { .filename = "\u00C6 capital AE", .expected_a = "\u00C6_capital_AE" },
65 { .filename = "\xC6 capital AE", .expected_a = "\xC6_capital_AE" },
66 { .filename = "\u00DE capital thorn", .expected_a = "\u00DE_capital_thorn" },
67 { .filename = "\xDE capital thorn", .expected_a = "\xDE_capital_thorn" },
68 { .filename = "\u0172 capital U Ogonek", .expected_a = "\u0172_capital_U_Ogonek" },
69 { .filename = "\x7E tilde", .expected_a = "~_tilde" },
70 { .filename = "\x7F delete", .expected_a = "__delete" },
71
72 // github issue 9
73
74 {
75 .filename = "hi\tthere",
76 .expected_a = "hi_there",
77 .expected_b = "hi_tab_there",
78 },
79
80 // github issue 17
81
82 {
83 .filename = "new\nline",
84 .expected_a = "new_line",
85 .expected_b = "new_nl_line",
86 },
87
88 // other, with a/b rules
89
90 {
91 .filename = "\x07 bell",
92 .expected_a = "__bell",
93 .expected_b = "_beep__bell",
94 },
95 {
96 .filename = "\x09 tab \x0A new line",
97 .expected_a = "__tab___new_line",
98 .expected_b = "_tab__tab__nl__new_line",
99 },
100 };
101
102 #test test_clean_safe
103 table_t *table;
104 char *output;
105 int i;
106
107 table = load_builtin_safe_table();
108
109 for (i = 0; i < DATA_COUNT; i++) {
110 output = clean_safe(data[i].filename, table);
111 ck_assert_str_eq(output, data[i].expected_a);
112 }
113
114 #test test_clean_safe_null
115 char *output;
116
117 // confirm NULL works
118 output = clean_safe(NULL, NULL);
119 ck_assert(output == NULL);
120
121 #test-exit(1) test_clean_safe_missing_table
122 clean_safe("what", NULL);
123
124 #test test_clean_safe_custom
125 table_t *table;
126 char *output;
127 int i;
128
129 table = load_builtin_safe_table();
130
131 table_put(table, 0x07, "_beep_");
132 table_put(table, 0x09, "_tab_");
133 table_put(table, 0x0a, "_nl_");
134
135 // legacy tests
136 for (i = 0; i < DATA_COUNT; i++) {
137 output = clean_safe(data[i].filename, table);
138 ck_assert_str_eq(output, (data[i].expected_b != NULL) ? data[i].expected_b : data[i].expected_a);
139 }