Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Unified Diff: mojom/mojom_parser/lexer/lexer_test.go

Issue 1837353002: Mojom parser: Fix snippet algorithm. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 ('k') | mojom/mojom_parser/lexer/tokens.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/lexer/lexer_test.go
diff --git a/mojom/mojom_parser/lexer/lexer_test.go b/mojom/mojom_parser/lexer/lexer_test.go
index e87d7f48cfd0fbc5da194067a740bfdc9cdbbe8e..422f4d8ddff1dd7a3e7c31dd2260d3e9dfe60376 100644
--- a/mojom/mojom_parser/lexer/lexer_test.go
+++ b/mojom/mojom_parser/lexer/lexer_test.go
@@ -312,6 +312,26 @@ func TestTokenSnippetLongPrelude(t *testing.T) {
checkEq(t, expected, ts.PeekNext().Snippet(source, false))
}
+// TestTokenSnippetLongPreludeWithNewLine tests snippet generation in the presence of a
+// long line with many characters preceeding the token and then a newline after the token.
+func TestTokenSnippetLongPreludeWithNewLine(t *testing.T) {
+ source := strings.Repeat(" ", 70) + "hello world\n"
+ ts := Tokenize(source)
+ expected := strings.Repeat(" ", 58) + "hello world\n"
+ expected += strings.Repeat(" ", 58) + "^^^^^"
+ checkEq(t, expected, ts.PeekNext().Snippet(source, false))
+}
+
+// TestTokenSnippetLongPreludeWithSuffix tests snippet generation in the presence of a
+// long line with many characters preceeding the token and then some characters following on the same line.
+func TestTokenSnippetLongPreludeWithLongSuffix(t *testing.T) {
+ source := strings.Repeat(" ", 70) + "hello world " + strings.Repeat("x", 10)
+ ts := Tokenize(source)
+ expected := strings.Repeat(" ", 58) + "hello world xxxxxxxx\n"
+ expected += strings.Repeat(" ", 58) + "^^^^^"
+ checkEq(t, expected, ts.PeekNext().Snippet(source, false))
+}
+
func TestFilteredTokens(t *testing.T) {
source := "/* filtered1 */ hello world // filtered2"
ts := Tokenize(source)
« no previous file with comments | « mojo/public/tools/bindings/mojom_tool/bin/mac64/mojom.sha1 ('k') | mojom/mojom_parser/lexer/tokens.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698