Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
add additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Dec 12, 2022
1 parent e98cd71 commit e2c7217
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 7 deletions.
5 changes: 4 additions & 1 deletion crates/rome_cli/tests/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,13 +1111,16 @@ fn does_not_format_ignored_directories() {
CONFIG_FORMATTER_IGNORED_DIRECTORIES.as_bytes(),
);

const FILES: [(&str, bool); 6] = [
const FILES: [(&str, bool); 9] = [
("test.js", true),
("test1.js", false),
("test2.js", false),
("test3/test.js", false),
("test4/test.js", true),
("test5/test.js", false),
("test6/test.js", false),
("test/test.test7.js", false),
("test.test7.js", false),
];

for (file_path, _) in FILES {
Expand Down
4 changes: 3 additions & 1 deletion crates/rome_cli/tests/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ pub const CONFIG_FORMATTER_IGNORED_DIRECTORIES: &str = r#"{
"./test2.js",
"./test3/**/*",
"/test4/**/*",
"test5/**/*"
"test5/**/*",
"**/test6/*.js",
"*.test7.js"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ expression: content
"./test2.js",
"./test3/**/*",
"/test4/**/*",
"test5/**/*"
"test5/**/*",
"**/test6/*.js",
"*.test7.js"
]
}
}
Expand All @@ -26,6 +28,18 @@ statement();

```

## `test.test7.js`

```js
statement( )
```

## `test/test.test7.js`

```js
statement( )
```

## `test1.js`

```js
Expand Down Expand Up @@ -57,6 +71,12 @@ statement();
statement( )
```

## `test6/test.js`

```js
statement( )
```

# Emitted Messages

```block
Expand Down
4 changes: 4 additions & 0 deletions crates/rome_lsp/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ use tower_lsp::lsp_types::WorkDoneProgressParams;
use tower_lsp::LspService;
use tower_lsp::{jsonrpc::Request, lsp_types::InitializeParams};

/// Statically build an [lsp::Url] instance that points to the file at `$path`
/// within the workspace. The filesystem path contained in the return URI is
/// guaranteed to be a valid path for the underlying operating system, but
/// doesn't have to refer to an existing file on the host machine.
macro_rules! url {
($path:literal) => {
if cfg!(windows) {
Expand Down
47 changes: 43 additions & 4 deletions crates/rome_service/src/matcher/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ impl Pattern {
let mut is_recursive = false;
let mut i = 0;

// A pattern is relative if it starts with "." followed by a separator
// A pattern is relative if it starts with "." followed by a separator,
// eg. "./test" or ".\test"
let is_relative = matches!(chars.get(..2), Some(['.', sep]) if path::is_separator(*sep));
if is_relative {
// If a pattern starts with a relative prefix, strip it from the pattern and replace it with "**"
// If a pattern starts with a relative prefix, strip it from the
// pattern and replace it with a "**" sequence
i += 2;
tokens.push(AnyRecursiveSequence);
} else {
// A pattern is absolute if it starts with a path separator
// A pattern is absolute if it starts with a path separator, eg. "/home" or "\\?\C:\Users"
let mut is_absolute = chars.first().map_or(false, |c| path::is_separator(*c));

// On windows a pattern may also be absolute if it starts with a drive letter, a colon and a separator
// On windows a pattern may also be absolute if it starts with a
// drive letter, a colon and a separator, eg. "c:/Users" or "G:\Users"
if cfg!(windows) && !is_absolute {
is_absolute = matches!(chars.get(..3), Some(['a'..='z' | 'A'..='Z', ':', sep]) if path::is_separator(*sep));
}
Expand Down Expand Up @@ -856,4 +859,40 @@ mod test {
let pattern = Path::new("one").join(Path::new("**/*.rs"));
assert!(Pattern::new(pattern.to_str().unwrap()).is_ok());
}

#[test]
fn test_pattern_relative() {
assert!(Pattern::new("./b").unwrap().matches_path(Path::new("a/b")));
assert!(Pattern::new("b").unwrap().matches_path(Path::new("a/b")));

if cfg!(windows) {
assert!(Pattern::new(".\\b")
.unwrap()
.matches_path(Path::new("a\\b")));
assert!(Pattern::new("b").unwrap().matches_path(Path::new("a\\b")));
}
}

#[test]
fn test_pattern_absolute() {
assert!(Pattern::new("/a/b")
.unwrap()
.matches_path(Path::new("/a/b")));

if cfg!(windows) {
assert!(Pattern::new("c:/a/b")
.unwrap()
.matches_path(Path::new("c:/a/b")));
assert!(Pattern::new("C:\\a\\b")
.unwrap()
.matches_path(Path::new("C:\\a\\b")));

assert!(Pattern::new("\\\\?\\c:\\a\\b")
.unwrap()
.matches_path(Path::new("\\\\?\\c:\\a\\b")));
assert!(Pattern::new("\\\\?\\C:/a/b")
.unwrap()
.matches_path(Path::new("\\\\?\\C:/a/b")));
}
}
}

0 comments on commit e2c7217

Please sign in to comment.