mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	Create cat_dir rule for replacing cat with ls (#823)
				
					
				
			* Create `cat_dir` rule for replacing `cat` with `ls` when you try to run `cat` on a directory. * Changed to string methods in response to feedback. Added a test to make sure lines like 'cat cat' don't become 'ls ls'. Added trailing '\n's to test cases.
This commit is contained in:
		
				
					committed by
					
						 Vladimir Iakovlev
						Vladimir Iakovlev
					
				
			
			
				
	
			
			
			
						parent
						
							142ef6e66c
						
					
				
				
					commit
					fe0785bc42
				
			
							
								
								
									
										29
									
								
								tests/rules/test_cat_dir.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/rules/test_cat_dir.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| import pytest | ||||
| from thefuck.rules.cat_dir import match, get_new_command | ||||
| from thefuck.types import Command | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
|     Command('cat foo', 'cat: foo: Is a directory\n'), | ||||
|     Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'), | ||||
|     Command('cat cat/', 'cat: cat/: Is a directory\n'), | ||||
| ]) | ||||
| def test_match(command): | ||||
|     assert match(command) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command', [ | ||||
|     Command('cat foo', 'foo bar baz'), | ||||
|     Command('cat foo bar', 'foo bar baz'), | ||||
| ]) | ||||
| def test_not_match(command): | ||||
|     assert not match(command) | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('command, new_command', [ | ||||
|     (Command('cat foo', 'cat: foo: Is a directory\n'), 'ls foo'), | ||||
|     (Command('cat /foo/bar/', 'cat: /foo/bar/: Is a directory\n'), 'ls /foo/bar/'), | ||||
|     (Command('cat cat', 'cat: cat: Is a directory\n'), 'ls cat'), | ||||
| ]) | ||||
| def test_get_new_command(command, new_command): | ||||
|     assert get_new_command(command) == new_command | ||||
		Reference in New Issue
	
	Block a user