spanner/spansql: fix InlineComment

It never worked unless the Start/End offsets were zeroed out, which was
true for tests but never true for real situations.

Also fix the End.Offset of comments, which were inadvertently set
relative to the Start.Offset rather than the start of the file.

Change-Id: Ib47daba822d1df8a6c76ca58ad638b83d61fa561
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/52032
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Knut Olav Løite <koloite@gmail.com>
diff --git a/spanner/spansql/parser.go b/spanner/spansql/parser.go
index 01f222c..c38fd70 100644
--- a/spanner/spansql/parser.go
+++ b/spanner/spansql/parser.go
@@ -719,14 +719,14 @@
 		}
 		c.end = Position{
 			Line:   p.line + strings.Count(c.text, "\n"),
-			Offset: i + ti,
+			Offset: c.start.Offset + ti,
 		}
 		p.comments = append(p.comments, c)
 		p.line = c.end.Line
 		if term == "\n" {
 			p.line++
 		}
-		i = c.end.Offset + len(term)
+		i += ti + len(term)
 	}
 	p.s = p.s[i:]
 	p.offset += i
diff --git a/spanner/spansql/parser_test.go b/spanner/spansql/parser_test.go
index 7dc772c..f0f2682 100644
--- a/spanner/spansql/parser_test.go
+++ b/spanner/spansql/parser_test.go
@@ -369,7 +369,11 @@
 	}
 
 	// Check the comment discovey helpers on the first DDL.
-	ddl := tests[0].want
+	// Reparse it first so we get full position information.
+	ddl, err := ParseDDL("filename", tests[0].in)
+	if err != nil {
+		t.Fatal(err)
+	}
 	// The CreateTable for NonScalars has a leading comment.
 	found := false
 	for _, stmt := range ddl.List {
diff --git a/spanner/spansql/types.go b/spanner/spansql/types.go
index 264c4e1..eaa1d3c 100644
--- a/spanner/spansql/types.go
+++ b/spanner/spansql/types.go
@@ -543,7 +543,7 @@
 	if c.Start.Line != pos.Line {
 		return nil
 	}
-	if c.Start != c.End || len(c.Text) != 1 {
+	if c.Start.Line != c.End.Line || len(c.Text) != 1 {
 		// Multi-line comment; don't return it.
 		return nil
 	}