Skip to content

Commit

Permalink
Merge branch 'trishume:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
godzie44 committed May 7, 2024
2 parents 5b19c28 + b2a8ebe commit f419e83
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/parsing/syntax_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ impl SyntaxSet {
/// This uses regexes that come with some sublime syntax grammars for matching things like
/// shebangs and mode lines like `-*- Mode: C -*-`
pub fn find_syntax_by_first_line<'a>(&'a self, s: &str) -> Option<&'a SyntaxReference> {
let s = s.strip_prefix("\u{feff}").unwrap_or(s); // Strip UTF-8 BOM
let cache = self.first_line_cache();
for &(ref reg, i) in cache.regexes.iter().rev() {
if reg.search(s, 0, s.len(), None) {
Expand Down Expand Up @@ -1401,6 +1402,16 @@ mod tests {
assert_prototype_only_on(&["main"], &rebuilt, &rebuilt.syntaxes()[0]);
}

#[test]
fn find_syntax_set_from_line_with_bom() {
// Regression test for #529
let syntax_set = SyntaxSet::load_defaults_newlines();
let syntax_ref = syntax_set
.find_syntax_by_first_line("\u{feff}<?xml version=\"1.0\"?>")
.unwrap();
assert_eq!(syntax_ref.name, "XML");
}

fn assert_ops_contain(ops: &[(usize, ScopeStackOp)], expected: &(usize, ScopeStackOp)) {
assert!(
ops.contains(expected),
Expand Down
12 changes: 10 additions & 2 deletions tests/public_api.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#[test]
fn public_api() {
// NOTE: consider switching back to using `public_api::MINIMUM_NIGHTLY_RUST_VERSION` after the
// version is newer than the one set here
let nightly_version = "nightly-2023-09-18";
assert_eq!(
public_api::MINIMUM_NIGHTLY_RUST_VERSION,
"nightly-2023-08-25"
);

// Install a compatible nightly toolchain if it is missing
rustup_toolchain::install(public_api::MINIMUM_NIGHTLY_RUST_VERSION).unwrap();
rustup_toolchain::install(nightly_version).unwrap();

// Build rustdoc JSON
let rustdoc_json = rustdoc_json::Builder::default()
.toolchain(public_api::MINIMUM_NIGHTLY_RUST_VERSION)
.toolchain(nightly_version)
.build()
.unwrap();

Expand Down

0 comments on commit f419e83

Please sign in to comment.