Skip to content

Commit 61cebf5

Browse files
committed
test(frontmatter): Match test updates in rustc
See rust-lang/rust#145751, rust-lang/rust#142032
1 parent 12fa1da commit 61cebf5

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

src/cargo/util/toml/embedded.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,55 @@ content: "#![feature(frontmatter)]\n\n---\n//~^ ERROR: expected item, found `-`\
378378
);
379379
}
380380

381+
#[test]
382+
fn rustc_frontmatter_inner_hyphens_1() {
383+
assert_source(
384+
r#"---
385+
x ---🚧️
386+
---
387+
388+
// Regression test for #141483
389+
//@check-pass
390+
391+
#![feature(frontmatter)]
392+
393+
fn main() {}
394+
"#,
395+
str![[r#"
396+
shebang: None
397+
info: None
398+
frontmatter: "x ---🚧\u{fe0f}\n"
399+
content: "\n// Regression test for #141483\n//@check-pass\n\n#![feature(frontmatter)]\n\nfn main() {}\n"
400+
401+
"#]],
402+
);
403+
}
404+
405+
#[test]
406+
fn rustc_frontmatter_inner_hyphens_2() {
407+
assert_source(
408+
r#"---
409+
x ---y
410+
---
411+
412+
// Test that hypens are allowed inside frontmatters if there is some
413+
// non-whitespace character preceding them.
414+
//@check-pass
415+
416+
#![feature(frontmatter)]
417+
418+
fn main() {}
419+
"#,
420+
str![[r#"
421+
shebang: None
422+
info: None
423+
frontmatter: "x ---y\n"
424+
content: "\n// Test that hypens are allowed inside frontmatters if there is some\n// non-whitespace character preceding them.\n//@check-pass\n\n#![feature(frontmatter)]\n\nfn main() {}\n"
425+
426+
"#]],
427+
);
428+
}
429+
381430
#[test]
382431
fn rustc_frontmatter_non_lexible_tokens() {
383432
assert_source(
@@ -498,6 +547,80 @@ content: "\n//@ check-pass\n// A frontmatter infostring can have leading whitesp
498547
);
499548
}
500549

550+
#[test]
551+
fn rustc_hyphen_in_infostring_leading() {
552+
// We don't validate infostrings besides `info == "cargo"`
553+
assert_source(
554+
r#"--- -toml
555+
//~^ ERROR: invalid infostring for frontmatter
556+
---
557+
558+
// infostrings cannot have leading hyphens
559+
560+
#![feature(frontmatter)]
561+
562+
fn main() {}
563+
"#,
564+
str![[r#"
565+
shebang: None
566+
info: "-toml"
567+
frontmatter: "//~^ ERROR: invalid infostring for frontmatter\n"
568+
content: "\n// infostrings cannot have leading hyphens\n\n#![feature(frontmatter)]\n\nfn main() {}\n"
569+
570+
"#]],
571+
);
572+
}
573+
574+
#[test]
575+
fn rustc_hyphen_in_infostring_non_leading() {
576+
assert_source(
577+
r#"--- Cargo-toml
578+
---
579+
580+
// infostrings can contain hyphens as long as a hyphen isn't the first character.
581+
//@ check-pass
582+
583+
#![feature(frontmatter)]
584+
585+
fn main() {}
586+
"#,
587+
str![[r#"
588+
shebang: None
589+
info: "Cargo-toml"
590+
frontmatter: ""
591+
content: "\n// infostrings can contain hyphens as long as a hyphen isn't the first character.\n//@ check-pass\n\n#![feature(frontmatter)]\n\nfn main() {}\n"
592+
593+
"#]],
594+
);
595+
}
596+
597+
#[test]
598+
fn rustc_included_frontmatter() {
599+
// Deferred to rustc since this requires knowledge of Rust grammar
600+
assert_source(
601+
r#"#![feature(frontmatter)]
602+
603+
//@ check-pass
604+
605+
include!("auxiliary/lib.rs");
606+
607+
// auxiliary/lib.rs contains a frontmatter. Ensure that we can use them in an
608+
// `include!` macro.
609+
610+
fn main() {
611+
foo(1);
612+
}
613+
"#,
614+
str![[r##"
615+
shebang: None
616+
info: None
617+
frontmatter: None
618+
content: "#![feature(frontmatter)]\n\n//@ check-pass\n\ninclude!(\"auxiliary/lib.rs\");\n\n// auxiliary/lib.rs contains a frontmatter. Ensure that we can use them in an\n// `include!` macro.\n\nfn main() {\n foo(1);\n}\n"
619+
620+
"##]],
621+
);
622+
}
623+
501624
#[test]
502625
fn rustc_infostring_fail() {
503626
// We don't validate infostrings besides `info == "cargo"`

0 commit comments

Comments
 (0)