mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
Adapt the whois
rule to #342
This commit is contained in:
parent
88732a608e
commit
fc48e69921
@ -6,7 +6,7 @@ from tests.utils import Command
|
|||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
Command(script='whois https://en.wikipedia.org/wiki/Main_Page'),
|
Command(script='whois https://en.wikipedia.org/wiki/Main_Page'),
|
||||||
Command(script='whois https://en.wikipedia.org/'),
|
Command(script='whois https://en.wikipedia.org/'),
|
||||||
Command(script='whois en.wikipedia.org')])
|
Command(script='whois meta.unix.stackexchange.com')])
|
||||||
def test_match(command):
|
def test_match(command):
|
||||||
assert match(command, None)
|
assert match(command, None)
|
||||||
|
|
||||||
@ -15,9 +15,12 @@ def test_not_match():
|
|||||||
assert not match(Command(script='whois'), None)
|
assert not match(Command(script='whois'), None)
|
||||||
|
|
||||||
|
|
||||||
|
# `whois com` actually makes sense
|
||||||
@pytest.mark.parametrize('command, new_command', [
|
@pytest.mark.parametrize('command, new_command', [
|
||||||
(Command('whois https://en.wikipedia.org/wiki/Main_Page'), 'whois en.wikipedia.org'),
|
(Command('whois https://en.wikipedia.org/wiki/Main_Page'), 'whois en.wikipedia.org'),
|
||||||
(Command('whois https://en.wikipedia.org/'), 'whois en.wikipedia.org'),
|
(Command('whois https://en.wikipedia.org/'), 'whois en.wikipedia.org'),
|
||||||
(Command('whois en.wikipedia.org'), 'whois wikipedia.org')])
|
(Command('whois meta.unix.stackexchange.com'), ['whois unix.stackexchange.com',
|
||||||
|
'whois stackexchange.com',
|
||||||
|
'whois com'])])
|
||||||
def test_get_new_command(command, new_command):
|
def test_get_new_command(command, new_command):
|
||||||
assert get_new_command(command, None) == new_command
|
assert get_new_command(command, None) == new_command
|
||||||
|
@ -19,7 +19,7 @@ def match(command, settings):
|
|||||||
- www.google.fr → subdomain: www, domain: 'google.fr';
|
- www.google.fr → subdomain: www, domain: 'google.fr';
|
||||||
- google.co.uk → subdomain: None, domain; 'google.co.uk'.
|
- google.co.uk → subdomain: None, domain; 'google.co.uk'.
|
||||||
"""
|
"""
|
||||||
return 'whois' in command.script and len(command.script.split()) > 1
|
return 'whois ' in command.script.strip()
|
||||||
|
|
||||||
|
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
@ -28,4 +28,5 @@ def get_new_command(command, settings):
|
|||||||
if '/' in command.script:
|
if '/' in command.script:
|
||||||
return 'whois ' + urlparse(url).netloc
|
return 'whois ' + urlparse(url).netloc
|
||||||
elif '.' in command.script:
|
elif '.' in command.script:
|
||||||
return 'whois ' + '.'.join(urlparse(url).path.split('.')[1:])
|
path = urlparse(url).path.split('.')
|
||||||
|
return ['whois ' + '.'.join(path[n:]) for n in range(1, len(path))]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user