Skip to content

Commit f852db8

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

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
@@ -374,6 +374,55 @@ info: None
374374
frontmatter: None
375375
content: "#![feature(frontmatter)]\n\n---\n//~^ ERROR: expected item, found `-`\n// FIXME(frontmatter): make this diagnostic better\n---\n\n// frontmatters must be at the start of a file. This test ensures that.\n\nfn main() {}\n"
376376
377+
"##]],
378+
);
379+
}
380+
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: None
399+
content: "#![feature(frontmatter)]\n\n---\n//~^ ERROR: expected item, found `-`\n// FIXME(frontmatter): make this diagnostic better\n---\n\n// frontmatters must be at the start of a file. This test ensures that.\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: None
424+
content: "#![feature(frontmatter)]\n\n---\n//~^ ERROR: expected item, found `-`\n// FIXME(frontmatter): make this diagnostic better\n---\n\n// frontmatters must be at the start of a file. This test ensures that.\n\nfn main() {}\n"
425+
377426
"##]],
378427
);
379428
}
@@ -494,6 +543,80 @@ info: "cargo"
494543
frontmatter: ""
495544
content: "\n//@ check-pass\n// A frontmatter infostring can have leading whitespace.\n\nfn main() {}\n"
496545
546+
"#]],
547+
);
548+
}
549+
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: "Cargo-toml"
617+
frontmatter: ""
618+
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"
619+
497620
"#]],
498621
);
499622
}

0 commit comments

Comments
 (0)