@@ -96,14 +96,13 @@ pub enum CommentKind {
9696impl CommentKind {
9797 fn comment ( & self ) -> & str {
9898 match self {
99- Self :: MultiLine ( comment) => comment,
100- Self :: SingleLine ( comment) => comment,
99+ Self :: MultiLine ( comment) | Self :: SingleLine ( comment) => comment,
101100 }
102101 }
103102}
104103
105104/// Structure for containing the [`CommentKind`] and the [`Span`] for a comment
106- #[ derive( Debug , PartialEq ) ]
105+ #[ derive( Debug , Eq , PartialEq ) ]
107106pub struct Comment {
108107 kind : CommentKind ,
109108 span : Span ,
@@ -215,7 +214,7 @@ impl CommentWithSpan {
215214}
216215
217216/// Structure for holding all comments found in the document
218- #[ derive( Debug , PartialEq ) ]
217+ #[ derive( Debug , Eq , PartialEq ) ]
219218pub struct Comments {
220219 comments : Vec < Comment > ,
221220}
@@ -438,6 +437,7 @@ fn multiline_comment_span() {
438437#[ test]
439438fn parse_comments ( ) {
440439 use std:: path:: Path ;
440+
441441 use crate :: { ast:: ParsedSqlFileSet , files:: SqlFileSet } ;
442442 let path = Path :: new ( "sql_files" ) ;
443443 let set = SqlFileSet :: new ( path, None ) . unwrap ( ) ;
@@ -459,16 +459,13 @@ fn parse_comments() {
459459 "Main body text" ,
460460 "When the post was created" ,
461461 ] ;
462- assert_eq ! ( expected. len( ) , parsed_comments. comments( ) . len( ) ) ;
462+ assert_eq ! ( expected. len( ) , parsed_comments. comments( ) . len( ) ) ;
463463 parsed_comments
464464 . comments ( )
465465 . iter ( )
466466 . enumerate ( )
467- . for_each ( |( i, c) |
468- assert_eq ! ( expected[ i] , c. kind( ) . comment( ) ) ) ;
469-
470-
471- } ,
467+ . for_each ( |( i, c) | assert_eq ! ( expected[ i] , c. kind( ) . comment( ) ) ) ;
468+ }
472469 "sql_files/with_multiline_comments.sql" => {
473470 let expected = [
474471 "Users table stores user account information \n multiline" ,
@@ -483,13 +480,13 @@ fn parse_comments() {
483480 "Main body text \n multiline" ,
484481 "When the post was created \n multiline" ,
485482 ] ;
486- assert_eq ! ( expected. len( ) , parsed_comments. comments( ) . len( ) ) ;
483+ assert_eq ! ( expected. len( ) , parsed_comments. comments( ) . len( ) ) ;
487484 parsed_comments
488485 . comments ( )
489486 . iter ( )
490487 . enumerate ( )
491- . for_each ( |( i, c) | assert_eq ! ( expected[ i] , c. kind( ) . comment( ) ) ) ;
492- } ,
488+ . for_each ( |( i, c) | assert_eq ! ( expected[ i] , c. kind( ) . comment( ) ) ) ;
489+ }
493490 "sql_files/with_mixed_comments.sql" => {
494491 let expected = [
495492 "Users table stores user account information" ,
@@ -504,26 +501,31 @@ fn parse_comments() {
504501 "Main body text" ,
505502 "When the post was created" ,
506503 ] ;
507- assert_eq ! ( expected. len( ) , parsed_comments. comments( ) . len( ) ) ;
504+ assert_eq ! ( expected. len( ) , parsed_comments. comments( ) . len( ) ) ;
508505 parsed_comments
509506 . comments ( )
510507 . iter ( )
511508 . enumerate ( )
512- . for_each ( |( i, c) | assert_eq ! ( expected[ i] , c. kind( ) . comment( ) ) ) ;
513-
514- } ,
509+ . for_each ( |( i, c) | assert_eq ! ( expected[ i] , c. kind( ) . comment( ) ) ) ;
510+ }
515511 "sql_files/without_comments.sql" => {
516512 assert_eq ! ( 0 , parsed_comments. comments. len( ) ) ;
517- } ,
518- _ => unreachable ! ( "This shouldn't be accessible if directory parsed correctly and all test files accounted for" ) ,
513+ }
514+ _ => {
515+ unreachable ! (
516+ "This shouldn't be accessible if directory parsed correctly and all test \
517+ files accounted for"
518+ )
519+ }
519520 }
520521 }
521522}
522523
523524#[ test]
524525fn single_line_comment_spans_are_correct ( ) {
525526 use std:: path:: Path ;
526- use crate :: { files:: SqlFileSet , ast:: ParsedSqlFileSet } ;
527+
528+ use crate :: { ast:: ParsedSqlFileSet , files:: SqlFileSet } ;
527529 let path = Path :: new ( "sql_files" ) ;
528530 let set = SqlFileSet :: new ( path, None ) . unwrap ( ) ;
529531 let parsed_set = ParsedSqlFileSet :: parse_all ( set) . unwrap ( ) ;
@@ -549,44 +551,32 @@ fn single_line_comment_spans_are_correct() {
549551 ) ;
550552}
551553
552-
553554#[ test]
554555fn multiline_comment_spans_are_correct ( ) {
555556 use std:: path:: Path ;
556- use crate :: { files:: SqlFileSet , ast:: ParsedSqlFileSet } ;
557+
558+ use crate :: { ast:: ParsedSqlFileSet , files:: SqlFileSet } ;
557559 let path = Path :: new ( "sql_files" ) ;
558560 let set = SqlFileSet :: new ( path, None ) . unwrap ( ) ;
559561 let parsed_set = ParsedSqlFileSet :: parse_all ( set) . unwrap ( ) ;
560562 let file = parsed_set
561563 . files ( )
562564 . iter ( )
563- . find ( |f| {
564- f. file ( )
565- . path ( )
566- . to_str ( )
567- . unwrap ( )
568- . ends_with ( "with_multiline_comments.sql" )
569- } )
565+ . find ( |f| f. file ( ) . path ( ) . to_str ( ) . unwrap ( ) . ends_with ( "with_multiline_comments.sql" ) )
570566 . expect ( "with_multiline_comments.sql should be present" ) ;
571567 let comments = Comments :: parse_all_comments_from_file ( file) . unwrap ( ) ;
572568 let comments = comments. comments ( ) ;
573569 assert_eq ! ( comments. len( ) , 11 ) ;
574570 let first = & comments[ 0 ] ;
575- assert_eq ! (
576- first. kind( ) . comment( ) ,
577- "Users table stores user account information \n multiline"
578- ) ;
571+ assert_eq ! ( first. kind( ) . comment( ) , "Users table stores user account information \n multiline" ) ;
579572 assert_eq ! ( first. span( ) . start( ) , & Location :: new( 0 , 0 ) ) ;
580573 assert_eq ! ( first. span( ) . end( ) . line( ) , 1 ) ;
581574 assert ! (
582575 first. span( ) . end( ) . column( ) > first. span( ) . start( ) . column( ) ,
583576 "end column should be after start column for first multiline comment" ,
584577 ) ;
585578 let primary_key = & comments[ 1 ] ;
586- assert_eq ! (
587- primary_key. kind( ) . comment( ) ,
588- "Primary key \n multiline"
589- ) ;
579+ assert_eq ! ( primary_key. kind( ) . comment( ) , "Primary key \n multiline" ) ;
590580 assert_eq ! ( primary_key. span( ) . start( ) , & Location :: new( 3 , 4 ) ) ;
591581 assert_eq ! ( primary_key. span( ) . end( ) . line( ) , 4 ) ;
592582 assert ! (
0 commit comments