mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	
							
								
								
									
										25
									
								
								tests/rules/test_open.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								tests/rules/test_open.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| import pytest | ||||
| from thefuck.rules.open import match, get_new_command | ||||
| from tests.utils import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
| 	Command(script='open foo.com'),  | ||||
| 	Command(script='open foo.ly'),  | ||||
| 	Command(script='open foo.org'),  | ||||
| 	Command(script='open foo.net'),  | ||||
| 	Command(script='open foo.se'),  | ||||
| 	Command(script='open foo.io')]) | ||||
| def test_match(command): | ||||
| 	assert match(command, None) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command, new_command', [ | ||||
| 	(Command('open foo.com'), 'open http://foo.com'), | ||||
| 	(Command('open foo.ly'), 'open http://foo.ly'), | ||||
| 	(Command('open foo.org'), 'open http://foo.org'), | ||||
| 	(Command('open foo.net'), 'open http://foo.net'), | ||||
| 	(Command('open foo.se'), 'open http://foo.se'), | ||||
| 	(Command('open foo.io'), 'open http://foo.io')]) | ||||
| def test_get_new_command(command, new_command): | ||||
| 	assert get_new_command(command, None) == new_command | ||||
							
								
								
									
										24
									
								
								thefuck/rules/open.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								thefuck/rules/open.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| # Opens URL's in the default web browser | ||||
| #  | ||||
| # Example: | ||||
| # > open github.com | ||||
| # The file ~/github.com does not exist. | ||||
| # Perhaps you meant 'http://github.com'? | ||||
| # | ||||
| #  | ||||
|  | ||||
| def match(command, settings): | ||||
| 	return (command.script.startswith ('open') | ||||
| 			and ( | ||||
| 			# Wanted to use this: | ||||
| 			# 'http' in command.stderr | ||||
| 			'.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)) | ||||
|  | ||||
| def get_new_command(command, settings): | ||||
| 	return 'open http://' + command.script[5:] | ||||
		Reference in New Issue
	
	Block a user