Skip to content

Commit 22200b7

Browse files
committed
feat(embedded): Allow experimenting with triple dash/hash fences
1 parent e46f916 commit 22200b7

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,29 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
217217
source.content = content;
218218
}
219219

220+
// Experiment: let us try which char works better
221+
let tick_char = source
222+
.content
223+
.chars()
224+
.filter(|c| ['`', '#', '-'].contains(c))
225+
.next()
226+
.unwrap_or('`');
227+
220228
let tick_end = source
221229
.content
222230
.char_indices()
223-
.find_map(|(i, c)| (c != '`').then_some(i))
231+
.find_map(|(i, c)| (c != tick_char).then_some(i))
224232
.unwrap_or(source.content.len());
225233
let (fence_pattern, rest) = match tick_end {
226234
0 => {
227235
return Ok(source);
228236
}
229237
1 | 2 => {
230-
anyhow::bail!("found {tick_end} backticks in rust frontmatter, expected at least 3")
238+
if tick_char == '#' {
239+
// Attribute
240+
return Ok(source);
241+
}
242+
anyhow::bail!("found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3")
231243
}
232244
_ => source.content.split_at(tick_end),
233245
};
@@ -358,6 +370,72 @@ strip = true
358370
time="0.1.25"
359371
```
360372
fn main() {}
373+
"#),
374+
);
375+
}
376+
377+
#[test]
378+
fn test_dash() {
379+
snapbox::assert_matches(
380+
r#"[[bin]]
381+
name = "test-"
382+
path = [..]
383+
384+
[dependencies]
385+
time = "0.1.25"
386+
387+
[package]
388+
autobenches = false
389+
autobins = false
390+
autoexamples = false
391+
autotests = false
392+
build = false
393+
edition = "2021"
394+
name = "test-"
395+
396+
[profile.release]
397+
strip = true
398+
399+
[workspace]
400+
"#,
401+
si!(r#"---
402+
[dependencies]
403+
time="0.1.25"
404+
---
405+
fn main() {}
406+
"#),
407+
);
408+
}
409+
410+
#[test]
411+
fn test_hash() {
412+
snapbox::assert_matches(
413+
r#"[[bin]]
414+
name = "test-"
415+
path = [..]
416+
417+
[dependencies]
418+
time = "0.1.25"
419+
420+
[package]
421+
autobenches = false
422+
autobins = false
423+
autoexamples = false
424+
autotests = false
425+
build = false
426+
edition = "2021"
427+
name = "test-"
428+
429+
[profile.release]
430+
strip = true
431+
432+
[workspace]
433+
"#,
434+
si!(r#"###
435+
[dependencies]
436+
time="0.1.25"
437+
###
438+
fn main() {}
361439
"#),
362440
);
363441
}

0 commit comments

Comments
 (0)