From 1d2d907c60a43ef31a147648d0a6cdc744f50b47 Mon Sep 17 00:00:00 2001 From: Cami Diez Date: Tue, 2 Jun 2015 12:05:47 +0800 Subject: [PATCH] Added go_run rule --- tests/rules/test_go_run.py | 17 +++++++++++++++++ thefuck/rules/go_run.py | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/rules/test_go_run.py create mode 100644 thefuck/rules/go_run.py diff --git a/tests/rules/test_go_run.py b/tests/rules/test_go_run.py new file mode 100644 index 00000000..05745054 --- /dev/null +++ b/tests/rules/test_go_run.py @@ -0,0 +1,17 @@ +import pytest +from thefuck.rules.go_run import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='go run foo'), + Command(script='go run bar')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('go run foo'), 'go run foo.go'), + (Command('go run bar'), 'go run bar.go')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/go_run.py b/thefuck/rules/go_run.py new file mode 100644 index 00000000..79eedc50 --- /dev/null +++ b/thefuck/rules/go_run.py @@ -0,0 +1,14 @@ +# Appends .go when compiling go files +# +# Example: +# > go run foo +# error: go run: no go files listed +# +# + +def match(command, settings): + return (command.script.startswith ('go run ') + and not command.script.endswith('.go')) + +def get_new_command(command, settings): + return command.script + '.go'