Skip to content

Commit f997b91

Browse files
committed
Progress: more methods supported
1 parent ff4061b commit f997b91

File tree

1 file changed

+98
-6
lines changed

1 file changed

+98
-6
lines changed

src/main.rs

+98-6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct TestInput {
100100
#[serde(default)]
101101
callback: String,
102102
#[serde(default)]
103+
#[serde(rename(deserialize = "option"))]
103104
options: Vec<String>,
104105
#[serde(default)]
105106
#[serde(rename(deserialize = "input"))]
@@ -109,7 +110,7 @@ struct TestInput {
109110
#[derive(Serialize)]
110111
struct TestOutput {
111112
success: bool,
112-
message: String,
113+
message: Option<String>,
113114
html: String,
114115
}
115116

@@ -131,6 +132,10 @@ async fn test_handler(Form(test_input): Form<TestInput>) -> Response<Body> {
131132
html.push_str("\t\t</tr>\n");
132133
}
133134

135+
// capture_names
136+
// captures_len
137+
// static_captures_len
138+
134139
html.push_str("\t</tbody>\n");
135140
html.push_str("</table>");
136141

@@ -163,18 +168,105 @@ async fn test_handler(Form(test_input): Form<TestInput>) -> Response<Body> {
163168
html.push_str("<table class=\"table table-bordered table-striped\" style=\"width: auto;\">\n");
164169
html.push_str("\t<thead>\n");
165170
html.push_str("\t\t<tr>\n");
171+
html.push_str("\t\t\t<th>Test</th>\n");
166172
html.push_str("\t\t\t<th>Input</th>\n");
167173
html.push_str("\t\t\t<th>is_match</th>\n");
174+
html.push_str("\t\t\t<th>find</th>\n");
175+
html.push_str("\t\t\t<th>find_iter</th>\n");
176+
html.push_str("\t\t\t<th>captures</th>\n");
177+
html.push_str("\t\t\t<th>captures_iter</th>\n");
178+
html.push_str("\t\t\t<th>split</th>\n");
179+
// replace
180+
// replace_all
181+
// replacen
182+
// shortest_match
168183
html.push_str("\t\t</tr>\n");
169184
html.push_str("\t</thead>\n");
170185
html.push_str("\t<tbody>\n");
171-
172-
for input in test_input.inputs {
173-
//let output = the_regex.as_ref().unwrap().replace_all(&input, &test_input.replacement);
186+
for (index, input) in test_input.inputs.iter().enumerate() {
187+
if input == "" {
188+
continue;
189+
}
174190
html.push_str("\t\t<tr>\n");
191+
html.push_str(&format!("\t\t\t<td class=\"text-center\">{}</td>\n", index+1));
175192
html.push_str(&format!("\t\t\t<td>{}</td>\n", encode_text(&input)));
176193
let is_match = if the_regex.is_match(&input) { "true" } else { "false" };
177194
html.push_str(&format!("\t\t\t<td>{}</td>\n", is_match));
195+
196+
let find = the_regex.find(&input);
197+
if find.is_none() {
198+
html.push_str("\t\t\t<td><i>(none)</i></td>\n");
199+
} else {
200+
html.push_str(&format!("\t\t\t<td>{}..{}</td>\n", find.unwrap().start(), find.unwrap().end()));
201+
}
202+
203+
let finds: Vec<_> = the_regex.find_iter(&input).map(|m| m.range()).collect();
204+
if finds.len() == 0 {
205+
html.push_str("\t\t\t<td><i>(none)</i></td>\n");
206+
} else {
207+
html.push_str("\t\t\t<td>\n");
208+
for (index, found) in finds.iter().enumerate() {
209+
html.push_str(&format!("\t\t\t\t[{}]: {}..{}", index, found.start, found.end));
210+
if index < finds.len() - 1 {
211+
html.push_str("<br>\n");
212+
}
213+
}
214+
html.push_str("\t\t\t</td>\n");
215+
}
216+
217+
let caps = the_regex.captures(&input);
218+
if caps.is_none() {
219+
html.push_str("\t\t\t<td><i>(none)</i></td>\n");
220+
} else {
221+
let caps = caps.unwrap();
222+
html.push_str("\t\t\t<td>\n");
223+
for (index, cap) in caps.iter().enumerate() {
224+
if cap.is_none() {
225+
continue;
226+
}
227+
let cap = cap.unwrap();
228+
html.push_str(&format!("\t\t\t\t[{}]: {} ({}..{})", index, encode_text(cap.as_str()), cap.start(), cap.end()));
229+
if index < caps.len() - 1 {
230+
html.push_str("<br>\n");
231+
}
232+
}
233+
html.push_str("\t\t\t</td>\n");
234+
}
235+
236+
let icaps: Vec<_> = the_regex.captures_iter(&input).map(|caps| caps.iter().map(|cap| cap.map(|c| c.as_str()).unwrap_or("")).collect::<Vec<_>>()).collect();
237+
if icaps.len() == 0 {
238+
html.push_str("\t\t\t<td><i>(none)</i></td>\n");
239+
} else {
240+
html.push_str("\t\t\t<td>\n");
241+
for (index, caps) in icaps.iter().enumerate() {
242+
html.push_str(&format!("\t\t\t\t[{}]: ", index));
243+
for (index, cap) in caps.iter().enumerate() {
244+
html.push_str(&format!("{}: {}", index, cap));
245+
if index < caps.len() - 1 {
246+
html.push_str(", ");
247+
}
248+
}
249+
if index < icaps.len() - 1 {
250+
html.push_str("<br>\n");
251+
}
252+
}
253+
html.push_str("\t\t\t</td>\n");
254+
}
255+
256+
let splits: Vec<_> = the_regex.split(&input).collect();
257+
if splits.len() == 0 {
258+
html.push_str("\t\t\t<td><i>(none)</i></td>\n");
259+
} else {
260+
html.push_str("\t\t\t<td>\n");
261+
for (index, split) in splits.iter().enumerate() {
262+
html.push_str(&format!("\t\t\t\t[{}]: {}", index, encode_text(split)));
263+
if index < splits.len() - 1 {
264+
html.push_str("<br>\n");
265+
}
266+
}
267+
html.push_str("\t\t\t</td>\n");
268+
}
269+
178270
html.push_str("\t\t</tr>\n");
179271
}
180272

@@ -189,8 +281,8 @@ fn handle_jsonp(callback: &str, html: String) -> Response<Body> {
189281

190282
let test_output = TestOutput {
191283
success: true,
192-
message: "OK".to_string(),
193-
html: html,
284+
message: None,
285+
html,
194286
};
195287

196288
let json_output = serde_json::to_string(&test_output).unwrap();

0 commit comments

Comments
 (0)