mirror of
				https://github.com/astral-sh/ruff.git
				synced 2025-10-31 12:05:52 +00:00 
			
		
		
		
	 e80260a3c5
			
		
	
	
		e80260a3c5
		
			
		
	
	
	
	
		
			
			## Summary I always found it odd that we had to pass this in, since it's really higher-level context for the error. The awkwardness is further evidenced by the fact that we pass in fake values everywhere (even outside of tests). The source path isn't actually used to display the error; it's only accessed elsewhere to _re-display_ the error in certain cases. This PR modifies to instead pass the path directly in those cases.
		
			
				
	
	
		
			24 lines
		
	
	
	
		
			557 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
	
		
			557 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| use ruff_python_parser::{parse_suite, ParseError};
 | |
| use ruff_text_size::{TextRange, TextSize};
 | |
| 
 | |
| use ruff_python_ast::identifier;
 | |
| 
 | |
| #[test]
 | |
| fn extract_else_range() -> Result<(), ParseError> {
 | |
|     let contents = r"
 | |
| for x in y:
 | |
|     pass
 | |
| else:
 | |
|     pass
 | |
| "
 | |
|     .trim();
 | |
|     let stmts = parse_suite(contents)?;
 | |
|     let stmt = stmts.first().unwrap();
 | |
|     let range = identifier::else_(stmt, contents).unwrap();
 | |
|     assert_eq!(&contents[range], "else");
 | |
|     assert_eq!(
 | |
|         range,
 | |
|         TextRange::new(TextSize::from(21), TextSize::from(25))
 | |
|     );
 | |
|     Ok(())
 | |
| }
 |