From 0eeacf0684591ba62266b26e6c1390fdff88cf60 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Tue, 31 May 2022 21:14:44 +0200 Subject: [PATCH] omf.packages.name: Fix regex by escaping a dot Fix #901 --- .../functions/packages/omf.packages.name.fish | 2 +- pkg/omf/spec/omf_packages_spec.fish | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 pkg/omf/spec/omf_packages_spec.fish diff --git a/pkg/omf/functions/packages/omf.packages.name.fish b/pkg/omf/functions/packages/omf.packages.name.fish index 4141200..d9741ba 100644 --- a/pkg/omf/functions/packages/omf.packages.name.fish +++ b/pkg/omf/functions/packages/omf.packages.name.fish @@ -1,3 +1,3 @@ function omf.packages.name -a name_or_url - command basename $name_or_url | sed -E 's/^(omf-)?((plugin|pkg|theme)-)?//;s/.git$//' + command basename $name_or_url | sed -E 's/^(omf-)?((plugin|pkg|theme)-)?//;s/\\.git$//' end diff --git a/pkg/omf/spec/omf_packages_spec.fish b/pkg/omf/spec/omf_packages_spec.fish new file mode 100644 index 0000000..8011518 --- /dev/null +++ b/pkg/omf/spec/omf_packages_spec.fish @@ -0,0 +1,77 @@ +function describe_omf_packages_tests + function before_all + set -gx CI WORKAROUND + end + + function it_can_extract_name_from_name + set -l output (omf.packages.name foo) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_of_a_plugin_package + set -l output (omf.packages.name plugin-foo) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_of_a_theme_package + set -l output (omf.packages.name theme-foo) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_from_name_ended_in_dot_git + set -l output (omf.packages.name foo.git) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_from_name_with_dot + set -l output (omf.packages.name foo.bar) + assert 0 = $status + assert "foo.bar" = "$output" + end + + function it_can_extract_name_from_name_ended_in_git + set -l output (omf.packages.name foobargit) + assert 0 = $status + assert "foobargit" = "$output" + end + + function it_can_extract_name_from_url + set -l output (omf.packages.name http://github.com/user/foo) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_from_url_of_a_plugin_package + set -l output (omf.packages.name http://github.com/user/plugin-foo) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_from_url_of_a_theme_package + set -l output (omf.packages.name http://github.com/user/theme-foo) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_from_url_ended_in_dot_git + set -l output (omf.packages.name http://github.com/user/foo.git) + assert 0 = $status + assert "foo" = "$output" + end + + function it_can_extract_name_from_url_with_dot + set -l output (omf.packages.name http://github.com/user/foo.bar) + assert 0 = $status + assert "foo.bar" = "$output" + end + + function it_can_extract_name_from_url_ended_in_git + set -l output (omf.packages.name http://github.com/user/foobargit) + assert 0 = $status + assert "foobargit" = "$output" + end +end