| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package lexer | 5 package lexer |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "strings" | 8 "strings" |
| 9 "testing" | 9 "testing" |
| 10 ) | 10 ) |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // TestTokenSnippetLongPrelude tests snippet generation in the presence of a | 305 // TestTokenSnippetLongPrelude tests snippet generation in the presence of a |
| 306 // long line with many characters preceeding the token. | 306 // long line with many characters preceeding the token. |
| 307 func TestTokenSnippetLongPrelude(t *testing.T) { | 307 func TestTokenSnippetLongPrelude(t *testing.T) { |
| 308 source := strings.Repeat(" ", 70) + "hello world" | 308 source := strings.Repeat(" ", 70) + "hello world" |
| 309 ts := Tokenize(source) | 309 ts := Tokenize(source) |
| 310 expected := strings.Repeat(" ", 58) + "hello world\n" | 310 expected := strings.Repeat(" ", 58) + "hello world\n" |
| 311 expected += strings.Repeat(" ", 58) + "^^^^^" | 311 expected += strings.Repeat(" ", 58) + "^^^^^" |
| 312 checkEq(t, expected, ts.PeekNext().Snippet(source, false)) | 312 checkEq(t, expected, ts.PeekNext().Snippet(source, false)) |
| 313 } | 313 } |
| 314 | 314 |
| 315 // TestTokenSnippetLongPreludeWithNewLine tests snippet generation in the presen
ce of a |
| 316 // long line with many characters preceeding the token and then a newline after
the token. |
| 317 func TestTokenSnippetLongPreludeWithNewLine(t *testing.T) { |
| 318 source := strings.Repeat(" ", 70) + "hello world\n" |
| 319 ts := Tokenize(source) |
| 320 expected := strings.Repeat(" ", 58) + "hello world\n" |
| 321 expected += strings.Repeat(" ", 58) + "^^^^^" |
| 322 checkEq(t, expected, ts.PeekNext().Snippet(source, false)) |
| 323 } |
| 324 |
| 325 // TestTokenSnippetLongPreludeWithSuffix tests snippet generation in the presenc
e of a |
| 326 // long line with many characters preceeding the token and then some characters
following on the same line. |
| 327 func TestTokenSnippetLongPreludeWithLongSuffix(t *testing.T) { |
| 328 source := strings.Repeat(" ", 70) + "hello world " + strings.Repeat("x",
10) |
| 329 ts := Tokenize(source) |
| 330 expected := strings.Repeat(" ", 58) + "hello world xxxxxxxx\n" |
| 331 expected += strings.Repeat(" ", 58) + "^^^^^" |
| 332 checkEq(t, expected, ts.PeekNext().Snippet(source, false)) |
| 333 } |
| 334 |
| 315 func TestFilteredTokens(t *testing.T) { | 335 func TestFilteredTokens(t *testing.T) { |
| 316 source := "/* filtered1 */ hello world // filtered2" | 336 source := "/* filtered1 */ hello world // filtered2" |
| 317 ts := Tokenize(source) | 337 ts := Tokenize(source) |
| 318 ts.ConsumeNext() | 338 ts.ConsumeNext() |
| 319 ts.ConsumeNext() | 339 ts.ConsumeNext() |
| 320 filtered := ts.(*FilteredTokenStream).FilteredTokens() | 340 filtered := ts.(*FilteredTokenStream).FilteredTokens() |
| 321 checkEq(t, MultiLineComment, filtered[0].Kind) | 341 checkEq(t, MultiLineComment, filtered[0].Kind) |
| 322 checkEq(t, SingleLineComment, filtered[1].Kind) | 342 checkEq(t, SingleLineComment, filtered[1].Kind) |
| 323 } | 343 } |
| 324 | 344 |
| 325 func TestEmptyLine(t *testing.T) { | 345 func TestEmptyLine(t *testing.T) { |
| 326 ts := tokenizeUnfiltered("\n") | 346 ts := tokenizeUnfiltered("\n") |
| 327 checkEq(t, EmptyLine, ts.PeekNext().Kind) | 347 checkEq(t, EmptyLine, ts.PeekNext().Kind) |
| 328 ts.ConsumeNext() | 348 ts.ConsumeNext() |
| 329 checkEq(t, EOF, ts.PeekNext().Kind) | 349 checkEq(t, EOF, ts.PeekNext().Kind) |
| 330 } | 350 } |
| OLD | NEW |