@@ -41,7 +41,7 @@ impl Location {
4141
4242impl Default for Location {
4343 fn default ( ) -> Self {
44- Self :: new ( 0 , 0 )
44+ Self :: new ( 1 , 1 )
4545 }
4646}
4747
@@ -95,6 +95,7 @@ pub enum CommentKind {
9595
9696impl CommentKind {
9797 /// Getter for returning the comment from within the enum
98+ #[ must_use]
9899 pub fn comment ( & self ) -> & str {
99100 match self {
100101 Self :: MultiLine ( comment) | Self :: SingleLine ( comment) => comment,
@@ -269,11 +270,11 @@ impl Comments {
269270 pub fn scan_comments ( src : & str ) -> CommentResult < Self > {
270271 let mut comments = Vec :: new ( ) ;
271272
272- let mut start_line = 0u64 ;
273- let mut start_col = 0u64 ;
273+ let mut start_line = 1u64 ;
274+ let mut start_col = 1u64 ;
274275
275- let mut line = 0u64 ;
276- let mut col = 0u64 ;
276+ let mut line = 1u64 ;
277+ let mut col = 1u64 ;
277278
278279 let mut in_single = false ;
279280 let mut in_multi = false ;
@@ -339,7 +340,7 @@ impl Comments {
339340 }
340341 ( false , true , ch) | ( true , false , ch) => {
341342 buf. push ( ch) ;
342- } ,
343+ }
343344 ( false , false , _) => { }
344345 ( true , true , _) => {
345346 unreachable ! ( "should not be possible to be in multiline and single line" )
@@ -387,21 +388,6 @@ impl Comments {
387388 pub fn leading_comment ( & self , line : u64 ) -> Option < & Comment > {
388389 self . comments ( ) . iter ( ) . rev ( ) . find ( |comment| comment. span ( ) . end ( ) . line ( ) + 1 == line)
389390 }
390-
391- /// Helper method for checking and finding for a comment before a specific
392- /// line for columns (hopefully temporary)
393- ///
394- /// # Parameters
395- /// - `self` an instance of [`Comments`]
396- /// - `line` an `u64` value representing the desired line to check above.
397- #[ must_use]
398- pub fn leading_comment_column ( & self , line : u64 ) -> Option < & Comment > {
399- dbg ! ( line) ;
400- let line = line -2 ;
401- let com = self . comments ( ) . iter ( ) . rev ( ) . find ( |comment| comment. span ( ) . end ( ) . line ( ) == line) ;
402- dbg ! ( & com) ;
403- com
404- }
405391}
406392
407393#[ cfg( test) ]
@@ -414,7 +400,7 @@ fn location_new_and_default() {
414400 assert_eq ! ( Location { column: 20 , line: 43 } , location) ;
415401
416402 let location2 = Location :: default ( ) ;
417- assert_eq ! ( location2, Location { line: 0 , column: 0 } ) ;
403+ assert_eq ! ( location2, Location { line: 1 , column: 1 } ) ;
418404}
419405
420406#[ test]
@@ -444,15 +430,15 @@ fn comments_with_comment_kind() {
444430 assert_eq ! ( comment. kind, singleline) ;
445431
446432 let expected_span =
447- Span :: new ( Location { line : 0 , column : 0 } , Location { line : 0 , column : len - 1 } ) ;
433+ Span :: new ( Location { line : 1 , column : 1 } , Location { line : 1 , column : len - 1 } ) ;
448434
449435 assert_eq ! ( comment. span, expected_span) ;
450436}
451437
452438#[ test]
453439fn multiline_comment_span ( ) {
454440 let kind = CommentKind :: MultiLine ( "/* hello\n world */" . to_string ( ) ) ;
455- let span = Span :: new ( Location { line : 1 , column : 0 } , Location { line : 2 , column : 9 } ) ;
441+ let span = Span :: new ( Location { line : 1 , column : 1 } , Location { line : 2 , column : 9 } ) ;
456442
457443 let comment = Comment :: new ( kind. clone ( ) , span) ;
458444
@@ -516,8 +502,11 @@ fn parse_comments() {
516502 }
517503 "sql_files/with_mixed_comments.sql" => {
518504 let expected = [
505+ "interstitial Comment above statements (should be ignored)" ,
519506 "Users table stores user account information" ,
507+ "users interstitial comment \n (should be ignored)" ,
520508 "Primary key" ,
509+ "Id comment that is interstitial (should be ignored)" ,
521510 "Username for login" ,
522511 "Email address" ,
523512 "When the user registered" ,
@@ -566,12 +555,12 @@ fn single_line_comment_spans_are_correct() {
566555 assert_eq ! ( comments. len( ) , 11 ) ;
567556 let first = & comments[ 0 ] ;
568557 assert_eq ! ( first. kind( ) . comment( ) , "Users table stores user account information" ) ;
569- assert_eq ! ( first. span( ) . start( ) , & Location :: new( 0 , 0 ) ) ;
570- assert_eq ! ( first. span( ) . end( ) , & Location :: new( 0 , 46 ) ) ;
558+ assert_eq ! ( first. span( ) . start( ) , & Location :: new( 1 , 1 ) ) ;
559+ assert_eq ! ( first. span( ) . end( ) , & Location :: new( 1 , 47 ) ) ;
571560 let primary_key = & comments[ 1 ] ;
572561 assert_eq ! ( primary_key. kind( ) . comment( ) , "Primary key" ) ;
573- assert_eq ! ( primary_key. span( ) . start( ) , & Location :: new( 2 , 4 ) ) ;
574- assert_eq ! ( primary_key. span( ) . end( ) , & Location :: new( 2 , 18 ) ) ;
562+ assert_eq ! ( primary_key. span( ) . start( ) , & Location :: new( 3 , 4 ) ) ;
563+ assert_eq ! ( primary_key. span( ) . end( ) , & Location :: new( 3 , 18 ) ) ;
575564 assert ! (
576565 primary_key. span( ) . end( ) . column( ) > primary_key. span( ) . start( ) . column( ) ,
577566 "end column should be after start column" ,
@@ -596,16 +585,16 @@ fn multiline_comment_spans_are_correct() {
596585 assert_eq ! ( comments. len( ) , 11 ) ;
597586 let first = & comments[ 0 ] ;
598587 assert_eq ! ( first. kind( ) . comment( ) , "Users table stores user account information \n multiline" ) ;
599- assert_eq ! ( first. span( ) . start( ) , & Location :: new( 0 , 0 ) ) ;
600- assert_eq ! ( first. span( ) . end( ) . line( ) , 1 ) ;
588+ assert_eq ! ( first. span( ) . start( ) , & Location :: new( 1 , 1 ) ) ;
589+ assert_eq ! ( first. span( ) . end( ) . line( ) , 2 ) ;
601590 assert ! (
602591 first. span( ) . end( ) . column( ) > first. span( ) . start( ) . column( ) ,
603592 "end column should be after start column for first multiline comment" ,
604593 ) ;
605594 let primary_key = & comments[ 1 ] ;
606595 assert_eq ! ( primary_key. kind( ) . comment( ) , "Primary key \n multiline" ) ;
607- assert_eq ! ( primary_key. span( ) . start( ) , & Location :: new( 3 , 4 ) ) ;
608- assert_eq ! ( primary_key. span( ) . end( ) . line( ) , 4 ) ;
596+ assert_eq ! ( primary_key. span( ) . start( ) , & Location :: new( 4 , 4 ) ) ;
597+ assert_eq ! ( primary_key. span( ) . end( ) . line( ) , 5 ) ;
609598 assert ! (
610599 primary_key. span( ) . end( ) . column( ) > primary_key. span( ) . start( ) . column( ) ,
611600 "end column should be after start column for primary key multiline comment" ,
0 commit comments