mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
#534: Move “is arg a url?” logic to a function
This function will be used in `get_new_command`.
This commit is contained in:
parent
fbea803a9b
commit
a169575b0f
@ -1,5 +1,5 @@
|
||||
import pytest
|
||||
from thefuck.rules.open import match, get_new_command
|
||||
from thefuck.rules.open import is_arg_url, match, get_new_command
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@ -10,11 +10,26 @@ def stderr(script):
|
||||
|
||||
@pytest.mark.parametrize('script', [
|
||||
'open foo.com',
|
||||
'open foo.ly',
|
||||
'open foo.org',
|
||||
'open foo.net',
|
||||
'open foo.se',
|
||||
'open foo.edu',
|
||||
'open foo.info',
|
||||
'open foo.io',
|
||||
'open foo.ly',
|
||||
'open foo.me',
|
||||
'open foo.net',
|
||||
'open foo.org',
|
||||
'open foo.se',
|
||||
'open www.foo.ru'])
|
||||
def test_is_arg_url(script):
|
||||
assert is_arg_url(Command(script))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', ['open foo', 'open bar.txt', 'open egg.doc'])
|
||||
def test_not_is_arg_url(script):
|
||||
assert not is_arg_url(Command(script))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', [
|
||||
'open foo.com',
|
||||
'xdg-open foo.com',
|
||||
'gnome-open foo.com',
|
||||
'kde-open foo.com'])
|
||||
@ -23,11 +38,6 @@ def test_match(script, stderr):
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, new_command', [
|
||||
('open foo.com', 'open http://foo.com'),
|
||||
('open foo.ly', 'open http://foo.ly'),
|
||||
('open foo.org', 'open http://foo.org'),
|
||||
('open foo.net', 'open http://foo.net'),
|
||||
('open foo.se', 'open http://foo.se'),
|
||||
('open foo.io', 'open http://foo.io'),
|
||||
('xdg-open foo.io', 'xdg-open http://foo.io'),
|
||||
('gnome-open foo.io', 'gnome-open http://foo.io'),
|
||||
|
@ -5,21 +5,26 @@
|
||||
# The file ~/github.com does not exist.
|
||||
# Perhaps you meant 'http://github.com'?
|
||||
#
|
||||
from thefuck.utils import for_app
|
||||
from thefuck.shells import shell
|
||||
from thefuck.utils import eager, for_app
|
||||
|
||||
|
||||
def is_arg_url(command):
|
||||
return ('.com' in command.script or
|
||||
'.edu' in command.script or
|
||||
'.info' in command.script or
|
||||
'.io' in command.script or
|
||||
'.ly' in command.script or
|
||||
'.me' in command.script or
|
||||
'.net' in command.script or
|
||||
'.org' in command.script or
|
||||
'.se' in command.script or
|
||||
'www.' in command.script)
|
||||
|
||||
|
||||
@for_app('open', 'xdg-open', 'gnome-open', 'kde-open')
|
||||
def match(command):
|
||||
return ('.com' in command.script
|
||||
or '.net' in command.script
|
||||
or '.org' in command.script
|
||||
or '.ly' in command.script
|
||||
or '.io' in command.script
|
||||
or '.se' in command.script
|
||||
or '.edu' in command.script
|
||||
or '.info' in command.script
|
||||
or '.me' in command.script
|
||||
or 'www.' in command.script)
|
||||
return is_arg_url(command)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
|
Loading…
x
Reference in New Issue
Block a user