mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
commit
eff0894a13
3 changed files with 34 additions and 23 deletions
|
@ -1,11 +1,6 @@
|
||||||
describe 'a multi-line suggestion' do
|
describe 'a multi-line suggestion' do
|
||||||
it 'should be displayed on multiple lines' do
|
it 'should be displayed on multiple lines' do
|
||||||
with_history(-> {
|
with_history("echo \"\n\"") do
|
||||||
session.send_string('echo "')
|
|
||||||
session.send_keys('enter')
|
|
||||||
session.send_string('"')
|
|
||||||
session.send_keys('enter')
|
|
||||||
}) do
|
|
||||||
session.send_keys('e')
|
session.send_keys('e')
|
||||||
wait_for { session.content }.to eq("echo \"\n\"")
|
wait_for { session.content }.to eq("echo \"\n\"")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'pry'
|
require 'pry'
|
||||||
require 'rspec/wait'
|
require 'rspec/wait'
|
||||||
require 'terminal_session'
|
require 'terminal_session'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
RSpec.shared_context 'terminal session' do
|
RSpec.shared_context 'terminal session' do
|
||||||
let(:term_opts) { {} }
|
let(:term_opts) { {} }
|
||||||
|
@ -21,11 +22,12 @@ RSpec.shared_context 'terminal session' do
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_history(*commands, &block)
|
def with_history(*commands, &block)
|
||||||
session.run_command('fc -p')
|
Tempfile.create do |f|
|
||||||
|
f.write(commands.map{|c| c.gsub("\n", "\\\n")}.join("\n"))
|
||||||
|
f.flush
|
||||||
|
|
||||||
commands.each do |c|
|
session.run_command('fc -p')
|
||||||
c.respond_to?(:call) ? c.call : session.run_command(c)
|
session.run_command("fc -R #{f.path}")
|
||||||
end
|
|
||||||
|
|
||||||
session.clear_screen
|
session.clear_screen
|
||||||
|
|
||||||
|
@ -34,6 +36,7 @@ RSpec.shared_context 'terminal session' do
|
||||||
session.send_keys('C-c')
|
session.send_keys('C-c')
|
||||||
session.run_command('fc -P')
|
session.run_command('fc -P')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
|
|
|
@ -1,58 +1,71 @@
|
||||||
shared_examples 'special characters' do
|
shared_examples 'special characters' do
|
||||||
describe 'a special character in the buffer' do
|
describe 'a special character in the buffer should be treated like any other character' do
|
||||||
it 'should be treated like any other character' do
|
it 'asterisk' do
|
||||||
with_history('echo "hello*"', 'echo "hello."') do
|
with_history('echo "hello*"', 'echo "hello."') do
|
||||||
session.send_string('echo "hello*')
|
session.send_string('echo "hello*')
|
||||||
wait_for { session.content }.to eq('echo "hello*"')
|
wait_for { session.content }.to eq('echo "hello*"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'question mark' do
|
||||||
with_history('echo "hello?"', 'echo "hello."') do
|
with_history('echo "hello?"', 'echo "hello."') do
|
||||||
session.send_string('echo "hello?')
|
session.send_string('echo "hello?')
|
||||||
wait_for { session.content }.to eq('echo "hello?"')
|
wait_for { session.content }.to eq('echo "hello?"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'backslash' do
|
||||||
with_history('echo "hello\nworld"') do
|
with_history('echo "hello\nworld"') do
|
||||||
session.send_string('echo "hello\\')
|
session.send_string('echo "hello\\')
|
||||||
wait_for { session.content }.to eq('echo "hello\nworld"')
|
wait_for { session.content }.to eq('echo "hello\nworld"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'double backslash' do
|
||||||
with_history('echo "\\\\"') do
|
with_history('echo "\\\\"') do
|
||||||
session.send_string('echo "\\\\')
|
session.send_string('echo "\\\\')
|
||||||
wait_for { session.content }.to eq('echo "\\\\"')
|
wait_for { session.content }.to eq('echo "\\\\"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'tilde' do
|
||||||
with_history('echo ~/foo') do
|
with_history('echo ~/foo') do
|
||||||
session.send_string('echo ~')
|
session.send_string('echo ~')
|
||||||
wait_for { session.content }.to eq('echo ~/foo')
|
wait_for { session.content }.to eq('echo ~/foo')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'parentheses' do
|
||||||
with_history('echo "$(ls foo)"') do
|
with_history('echo "$(ls foo)"') do
|
||||||
session.send_string('echo "$(')
|
session.send_string('echo "$(')
|
||||||
wait_for { session.content }.to eq('echo "$(ls foo)"')
|
wait_for { session.content }.to eq('echo "$(ls foo)"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'square bracket' do
|
||||||
with_history('echo "$history[123]"') do
|
with_history('echo "$history[123]"') do
|
||||||
session.send_string('echo "$history[')
|
session.send_string('echo "$history[')
|
||||||
wait_for { session.content }.to eq('echo "$history[123]"')
|
wait_for { session.content }.to eq('echo "$history[123]"')
|
||||||
session.send_string('123]')
|
session.send_string('123]')
|
||||||
wait_for { session.content }.to eq('echo "$history[123]"')
|
wait_for { session.content }.to eq('echo "$history[123]"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'octothorpe' do
|
||||||
with_history('echo "#yolo"') do
|
with_history('echo "#yolo"') do
|
||||||
session.send_string('echo "#')
|
session.send_string('echo "#')
|
||||||
wait_for { session.content }.to eq('echo "#yolo"')
|
wait_for { session.content }.to eq('echo "#yolo"')
|
||||||
end
|
end
|
||||||
|
|
||||||
with_history('echo "#foo"', 'echo $#abc') do
|
|
||||||
session.send_string('echo "#')
|
|
||||||
wait_for { session.content }.to eq('echo "#foo"')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'caret' do
|
||||||
with_history('echo "^A"', 'echo "^B"') do
|
with_history('echo "^A"', 'echo "^B"') do
|
||||||
session.send_string('echo "^A')
|
session.send_string('echo "^A')
|
||||||
wait_for { session.content }.to eq('echo "^A"')
|
wait_for { session.content }.to eq('echo "^A"')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'dash' do
|
||||||
with_history('-foo() {}') do
|
with_history('-foo() {}') do
|
||||||
session.send_string('-')
|
session.send_string('-')
|
||||||
wait_for { session.content }.to eq('-foo() {}')
|
wait_for { session.content }.to eq('-foo() {}')
|
||||||
|
|
Loading…
Reference in a new issue