allow multiple extensions (#10593)

<!--
if this PR closes one or more issues, you can automatically link the PR
with
them by using one of the [*linking
keywords*](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword),
e.g.
- this PR should close #xxxx
- fixes #xxxx

you can also mention related issues, PRs or discussions!
-->

# Description
<!--
Thank you for improving Nushell. Please, check our [contributing
guide](../CONTRIBUTING.md) and talk to the core team before making major
changes.

Description of your pull request goes here. **Provide examples and/or
screenshots** if your changes affect the user experience.
-->

This PR allows `open` to handle files with multiple extensions; i.e it
will try to call `from tar.gz`, `from gz` when calling
```nu
open file.tar.gz
```

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->
No breaking changes.
This commit is contained in:
Gaëtan
2023-10-13 20:45:36 +02:00
committed by GitHub
parent 6cff54ed0d
commit 1751ac12f4
2 changed files with 109 additions and 30 deletions

View File

@ -34,6 +34,69 @@ fn parses_file_with_uppercase_extension() {
})
}
#[test]
fn parses_file_with_multiple_extensions() {
Playground::setup("open_test_multiple_extensions", |dirs, sandbox| {
sandbox.with_files(vec![
FileWithContent("file.tar.gz", "this is a tar.gz file"),
FileWithContent("file.tar.xz", "this is a tar.xz file"),
]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
hide "from tar.gz" ;
hide "from gz" ;
def "from tar.gz" [] { 'opened tar.gz' } ;
def "from gz" [] { 'opened gz' } ;
open file.tar.gz
"#
));
assert_eq!(actual.out, "opened tar.gz");
let actual2 = nu!(
cwd: dirs.test(), pipeline(
r#"
hide "from tar.xz" ;
hide "from xz" ;
hide "from tar" ;
def "from tar" [] { 'opened tar' } ;
def "from xz" [] { 'opened xz' } ;
open file.tar.xz
"#
));
assert_eq!(actual2.out, "opened xz");
})
}
#[test]
fn parses_dotfile() {
Playground::setup("open_test_dotfile", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
".gitignore",
r#"
/target/
"#,
)]);
let actual = nu!(
cwd: dirs.test(), pipeline(
r#"
hide "from gitignore" ;
def "from gitignore" [] { 'opened gitignore' } ;
open .gitignore
"#
));
assert_eq!(actual.out, "opened gitignore");
})
}
#[test]
fn parses_csv() {
Playground::setup("open_test_1", |dirs, sandbox| {