| 562 | |
| 563 | impl<'a> CommentsTestCase<'a> { |
| 564 | fn from_code(source: &'a str) -> Self { |
| 565 | let source_code = SourceCode::new(source); |
| 566 | let source_type = PySourceType::Python; |
| 567 | let parsed = parse(source, ParseOptions::from(source_type)) |
| 568 | .expect("Expect source to be valid Python"); |
| 569 | let trivia = TriviaRanges::from(parsed.tokens()); |
| 570 | |
| 571 | CommentsTestCase { |
| 572 | parsed, |
| 573 | trivia, |
| 574 | source_code, |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | fn to_comments(&self) -> Comments<'_> { |
| 579 | Comments::from_ast(self.parsed.syntax(), self.source_code, &self.trivia) |