Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix comment parsing in Console lexer (#1379)
The Console lexer would not correctly parse comments if only the `comments` option was enabled. This was because of a bug in the way the prompt's regular expression pattern worked. This commit fixes that bug and adds a series of tests to confirm the behaviour of the lexer is as intended.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- # | ||
# frozen_string_literal: true | ||
|
||
describe Rouge::Lexers::ConsoleLexer do | ||
let(:subject) { Rouge::Lexers::ConsoleLexer.new } | ||
let(:klass) { Rouge::Lexers::ConsoleLexer } | ||
|
||
include Support::Lexing | ||
|
||
it 'parses a basic prompt' do | ||
assert_tokens_equal '$ foo', | ||
['Generic.Prompt', '$'], | ||
['Text.Whitespace', ' '], | ||
['Text', 'foo'] | ||
end | ||
|
||
it 'parses a custom prompt' do | ||
subject_with_options = klass.new({ prompt: '%' }) | ||
assert_tokens_equal '% foo', subject_with_options, | ||
['Generic.Prompt', '%'], | ||
['Text.Whitespace', ' '], | ||
['Text', 'foo'] | ||
end | ||
|
||
it 'parses single-line comments' do | ||
subject_with_options = klass.new({ comments: true }) | ||
assert_tokens_equal '# this is a comment', subject_with_options, | ||
['Comment', '# this is a comment'] | ||
end | ||
|
||
it 'ignores single-line comments' do | ||
assert_tokens_equal '# this is not a comment', | ||
['Generic.Prompt', '#'], | ||
['Text.Whitespace', ' '], | ||
['Text', 'this is not a comment'] | ||
end | ||
|
||
describe 'guessing' do | ||
include Support::Guessing | ||
|
||
it 'guesses by filename' do | ||
assert_guess :filename => 'foo.cap' | ||
end | ||
end | ||
end |