Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

irb lexer: recognize the SIMPLE prompt #1943

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/rouge/lexers/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ def lang_lexer
end

def prompt_regex
/^.*?(irb|pry).*?[>"*]/
%r(
^.*?
(
(irb|pry).*?[>"*] |
[>"*]>
)
)x
end

def allow_comments?
Expand Down
30 changes: 30 additions & 0 deletions spec/lexers/irb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*- #
# frozen_string_literal: true

describe Rouge::Lexers::IRBLexer do
let(:subject) { Rouge::Lexers::IRBLexer.new }
let(:klass) { Rouge::Lexers::IRBLexer }

include Support::Lexing

it "parses IRB's :DEFAULT prompt" do
assert_tokens_equal 'irb(main):001:0> self',
['Generic.Prompt', 'irb(main):001:0>'],
['Text.Whitespace', ' '],
['Name.Builtin', 'self']
end

it "parses IRB's :SIMPLE prompt" do
assert_tokens_equal '>> self',
['Generic.Prompt', '>>'],
['Text.Whitespace', ' '],
['Name.Builtin', 'self']
end

it "parses Pry's default prompt" do
assert_tokens_equal 'pry(main)> self',
['Generic.Prompt', 'pry(main)>'],
['Text.Whitespace', ' '],
['Name.Builtin', 'self']
end
end