Skip to content

Commit

Permalink
Lots of async changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfreese committed Feb 17, 2017
1 parent 38eb7cd commit a1067d3
Show file tree
Hide file tree
Showing 35 changed files with 387 additions and 1,133 deletions.
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
--color
--require spec_helper
--format documentation
30 changes: 30 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Rails:
# Enabled: true

AllCops:
TargetRubyVersion: 2.3
Include:
- '**/Rakefile'
- '**/config.ru'
- '**/Gemfile'

Metrics/LineLength:
Max: 120

Style/Documentation:
Enabled: false

Style/DotPosition:
EnforcedStyle: trailing

Style/FrozenStringLiteralComment:
Enabled: false

Style/Lambda:
Enabled: false

Style/MultilineMethodCallIndentation:
EnforcedStyle: indented

Style/TrailingUnderscoreVariable:
Enabled: false
23 changes: 2 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
SRC_DIR := ./src
VENDOR_DIR := ./vendor

SRC_FILES := \
$(SRC_DIR)/setup.zsh \
Expand All @@ -22,34 +21,16 @@ HEADER_FILES := \

PLUGIN_TARGET := zsh-autosuggestions.zsh

SHUNIT2 := $(VENDOR_DIR)/shunit2/2.1.6
STUB_SH := $(VENDOR_DIR)/stub.sh/stub.sh

UNIT_TEST_PREREQS := \
$(SHUNIT2) \
$(STUB_SH)

all: $(PLUGIN_TARGET)

$(PLUGIN_TARGET): $(HEADER_FILES) $(SRC_FILES)
cat $(HEADER_FILES) | sed -e 's/^/# /g' > $@
cat $(SRC_FILES) >> $@

$(SHUNIT2):
git submodule update --init vendor/shunit2

$(STUB_SH):
git submodule update --init vendor/stub.sh

.PHONY: clean
clean:
rm $(PLUGIN_TARGET)

.PHONY: test
test: rspec unit_test

unit_test: all $(UNIT_TEST_PREREQS)
script/test_runner.zsh $(UNIT_TESTS)

rspec: all
bundle exec rspec $(RSPEC_TESTS)
test: all
bundle exec rspec $(TESTS)
54 changes: 0 additions & 54 deletions script/test_runner.zsh

This file was deleted.

11 changes: 11 additions & 0 deletions spec/integrations/client_zpty_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe 'a running zpty command' do
it 'is not affected by running zsh-autosuggestions' do
session.run_command('zmodload zsh/zpty')
session.run_command('zpty -b kitty cat')
session.run_command('zpty -w kitty cat')
sleep 1
session.run_command('zpty -r kitty')

wait_for(session.content).to end_with("\ncat")
end
end
13 changes: 13 additions & 0 deletions spec/multi_line_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
describe 'a multi-line suggestion' do
it 'should be displayed on multiple lines' do
with_history(-> {
session.send_string('echo "')
session.send_keys('enter')
session.send_string('"')
session.send_keys('enter')
}) do
session.send_keys('e')
wait_for { session.content }.to eq("echo \"\n\"")
end
end
end
15 changes: 15 additions & 0 deletions spec/options/async_zpty_name_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe 'the zpty for async suggestions' do
it 'is created with the default name' do
session.run_command('zpty -t zsh_autosuggest_pty &>/dev/null; echo $?')
wait_for { session.content }.to end_with("\n0")
end

context 'when ZSH_AUTOSUGGEST_ASYNC_PTY_NAME is set' do
let(:options) { ['ZSH_AUTOSUGGEST_ASYNC_PTY_NAME=foo_pty'] }

it 'is created with the specified name' do
session.run_command('zpty -t foo_pty &>/dev/null; echo $?')
wait_for { session.content }.to end_with("\n0")
end
end
end
30 changes: 30 additions & 0 deletions spec/options/buffer_max_size_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe 'a suggestion' do
let(:term_opts) { { width: 200 } }
let(:long_command) { "echo #{'a' * 100}" }

around do |example|
with_history(long_command) { example.run }
end

it 'is provided for any buffer length' do
session.send_string(long_command[0...-1])
wait_for { session.content }.to eq(long_command)
end

context 'when ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE is specified' do
let(:buffer_max_size) { 10 }
let(:options) { ["ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=#{buffer_max_size}"] }

it 'is provided when the buffer is shorter than the specified length' do
session.send_string(long_command[0...(buffer_max_size - 1)])
wait_for { session.content }.to eq(long_command)
end

it 'is provided when the buffer is equal to the specified length' do
session.send_string(long_command[0...(buffer_max_size)])
wait_for { session.content }.to eq(long_command)
end

it 'is not provided when the buffer is longer than the specified length'
end
end
7 changes: 7 additions & 0 deletions spec/options/highlight_style_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe 'a displayed suggestion' do
it 'is shown in the default style'

describe 'when ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE is set to a zle_highlight string' do
it 'is shown in the specified style'
end
end
7 changes: 7 additions & 0 deletions spec/options/original_widget_prefix_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe 'an original zle widget' do
context 'is accessible with the default prefix'

context 'when ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX is set' do
it 'is accessible with the specified prefix'
end
end
20 changes: 20 additions & 0 deletions spec/options/strategy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe 'a suggestion for a given prefix' do
let(:options) { ['_zsh_autosuggest_strategy_default() { suggestion="echo foo" }'] }

it 'is determined by calling the default strategy function' do
session.send_string('e')
wait_for { session.content }.to eq('echo foo')
end

context 'when ZSH_AUTOSUGGEST_STRATEGY is set' do
let(:options) { [
'_zsh_autosuggest_strategy_custom() { suggestion="echo foo" }',
'ZSH_AUTOSUGGEST_STRATEGY=custom'
] }

it 'is determined by calling the specified strategy function' do
session.send_string('e')
wait_for { session.content }.to eq('echo foo')
end
end
end
7 changes: 7 additions & 0 deletions spec/options/use_async_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
describe 'suggestion fetching' do
it 'is performed asynchronously'

context 'when ZSH_AUTOSUGGEST_USE_ASYNC is unset' do
it 'is performed synchronously'
end
end
72 changes: 72 additions & 0 deletions spec/options/widget_lists_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
describe 'a zle widget' do
let(:before_sourcing) { -> { session.run_command('my-widget() {}; zle -N my-widget; bindkey ^B my-widget') } }

context 'when added to ZSH_AUTOSUGGEST_ACCEPT_WIDGETS' do
let(:options) { ['ZSH_AUTOSUGGEST_ACCEPT_WIDGETS=(my-widget)'] }

it 'accepts the suggestion when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to eq('echo hello')
end
end
end

context 'when added to ZSH_AUTOSUGGEST_CLEAR_WIDGETS' do
let(:options) { ['ZSH_AUTOSUGGEST_CLEAR_WIDGETS=(my-widget)'] }

it 'clears the suggestion when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content }.to eq('e')
end
end
end

context 'when added to ZSH_AUTOSUGGEST_EXECUTE_WIDGETS' do
let(:options) { ['ZSH_AUTOSUGGEST_EXECUTE_WIDGETS=(my-widget)'] }

it 'executes the suggestion when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-b')
wait_for { session.content }.to end_with("\nhello")
end
end
end
end

describe 'a zle widget that moves the cursor forward' do
let(:before_sourcing) { -> { session.run_command('my-widget() { zle forward-char }; zle -N my-widget; bindkey ^B my-widget') } }

context 'when added to ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS' do
let(:options) { ['ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS=(my-widget)'] }

it 'accepts the suggestion as far as the cursor is moved when invoked' do
with_history('echo hello') do
session.send_string('e')
wait_for { session.content }.to start_with('echo hello')
session.send_keys('C-b')
wait_for { session.content(esc_seqs: true) }.to match(/\Aec\e\[[0-9]+mho hello/)
end
end
end
end

describe 'a builtin zle widget' do
let(:widget) { 'beep' }

context 'when added to ZSH_AUTOSUGGEST_IGNORE_WIDGETS' do
let(:options) { ["ZSH_AUTOSUGGEST_IGNORE_WIDGETS=(#{widget})"] }

it 'should not be wrapped with an autosuggest widget' do
session.run_command("echo $widgets[#{widget}]")
wait_for { session.content }.to end_with("\nbuiltin")
end
end
end
35 changes: 35 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@
require 'rspec/wait'
require 'terminal_session'

RSpec.shared_context 'terminal session' do
let(:term_opts) { {} }
let(:session) { TerminalSession.new(term_opts) }
let(:before_sourcing) { -> {} }
let(:options) { [] }

around do |example|
before_sourcing.call

session.run_command((['source zsh-autosuggestions.zsh'] + options).join('; '))
session.clear_screen

example.run

session.destroy
end

def with_history(*commands, &block)
session.run_command('fc -p')

commands.each do |c|
c.respond_to?(:call) ? c.call : session.run_command(c)
end

session.clear_screen

yield block

session.send_keys('C-c')
session.run_command('fc -P')
end
end

RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
Expand All @@ -12,4 +45,6 @@
end

config.wait_timeout = 2

config.include_context 'terminal session'
end
Loading

0 comments on commit a1067d3

Please sign in to comment.