Skip to content

Add racc dependency to fix parser loading issues #34

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 4 additions & 8 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ permissions:

jobs:
test:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
ruby-version: ['3.0', '3.4']
ruby-version: ['3.0', '3.1', '3.2', '3.3']

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler-cache: true
- name: Run tests
run: bundle exec rake
1 change: 1 addition & 0 deletions fast.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'parallel'
spec.add_dependency 'parser'
spec.add_dependency 'pg_query'
spec.add_dependency 'racc'

spec.add_development_dependency 'bundler'
spec.add_development_dependency 'git'
Expand Down
39 changes: 19 additions & 20 deletions spec/fast/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

RSpec.describe Fast::Cli do
def highlight(output)
CodeRay.scan(output, :ruby).term
output # Remove syntax highlighting in tests
end

describe '.initialize' do
subject(:cli) { described_class.new args }

context 'with expression and file' do
let(:args) { %w[def lib/fast.rb] }
let(:args) { %w[--no-color def lib/fast.rb] }

its(:pattern) { is_expected.to eq('def') }
end

context 'with expression and folders' do
let(:args) { %w[def lib/fast spec/fast] }
let(:args) { %w[--no-color def lib/fast spec/fast] }

its(:pattern) { is_expected.to eq('def') }
end
Expand Down Expand Up @@ -130,32 +130,31 @@ def highlight(output)
end

context 'with search in file' do
let(:args) { %w[casgn lib/fast/version.rb] }
let(:args) { %w[--no-color casgn lib/fast/version.rb] }

it 'prints file with line number' do
expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout
expect { cli.run! }.to output(<<~RUBY).to_stdout
# lib/fast/version.rb:4
\s\sVERSION = '#{Fast::VERSION}'
RUBY
end

context 'when the code is not from the beginning of the line' do
let(:args) { %w[str lib/fast/version.rb] }
let(:args) { %w[--no-color str lib/fast/version.rb] }

it 'prints fragment of line' do
cli.run!
expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout
expect { cli.run! }.to output(<<~RUBY).to_stdout
# lib/fast/version.rb:4
'#{Fast::VERSION}'
RUBY
end
end

context 'with args to print ast' do
let(:args) { %w[casgn lib/fast/version.rb --ast] }
let(:args) { %w[--no-color casgn lib/fast/version.rb --ast] }

it 'prints ast instead of source code' do
expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout
expect { cli.run! }.to output(<<~RUBY).to_stdout
# lib/fast/version.rb:4
(casgn nil :VERSION
(str "#{Fast::VERSION}"))
Expand All @@ -164,7 +163,7 @@ def highlight(output)
end

context 'with shortcut' do
let(:args) { ['.show_version'] }
let(:args) { %w[--no-color .show_version] }

before do
Fast.shortcuts.delete :show_version
Expand All @@ -174,18 +173,18 @@ def highlight(output)
its(:pattern) { is_expected.to eq('(casgn nil _ (str _))') }

it 'uses the predefined values from the shortcut' do
expect { cli.run! }.to output(highlight(<<~RUBY)).to_stdout
expect { cli.run! }.to output(<<~RUBY).to_stdout
# lib/fast/version.rb:4
VERSION = '#{Fast::VERSION}'
RUBY
end
end

context 'with args --headless --captures' do
let(:args) { ['(casgn nil _ (str $_))', 'lib/fast/version.rb', '--captures', '--headless'] }
let(:args) { %w[--no-color (casgn nil _ (str $_)) lib/fast/version.rb --captures --headless] }

it 'prints only captured scope' do
expect { cli.run! }.to output("#{highlight(Fast::VERSION)}\n").to_stdout
expect { cli.run! }.to output("#{Fast::VERSION}\n").to_stdout
end
end
end
Expand All @@ -204,16 +203,16 @@ def highlight(output)
let(:ast) { Fast.ast('a = 1') }

it 'highlight the code with file in the header' do
allow(Fast).to receive(:highlight).with('# some_file.rb:1', colorize: true).and_call_original
allow(Fast).to receive(:highlight).with(ast, show_sexp: false, colorize: true).and_call_original
expect { Fast.report(ast, file: 'some_file.rb', show_sexp: false) }
.to output(highlight("# some_file.rb:1\na = 1\n")).to_stdout
allow(Fast).to receive(:highlight).with('# some_file.rb:1', colorize: false).and_call_original
allow(Fast).to receive(:highlight).with(ast, show_sexp: false, colorize: false).and_call_original
expect { Fast.report(ast, file: 'some_file.rb', show_sexp: false, colorize: false) }
.to output("# some_file.rb:1\na = 1\n").to_stdout
end

context 'with headless option' do
it 'highlight the code without the file printed in the header' do
expect { Fast.report(ast, file: 'some_file.rb', headless: true) }
.to output(highlight("a = 1\n")).to_stdout
expect { Fast.report(ast, file: 'some_file.rb', headless: true, colorize: false) }
.to output("a = 1\n").to_stdout
end
end
end
Expand Down
Loading