fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
c97b1a992
master
1#!/usr/bin/env python3 2from pexpect_helper import SpawnedProc 3 4sp = SpawnedProc () 5send ,sendline ,sleep ,expect_prompt ,expect_re ,expect_str = ( 6sp .send , 7sp .sendline , 8sp .sleep , 9sp .expect_prompt , 10sp .expect_re , 11sp .expect_str , 12) 13 14expect_prompt () 15 16# Exclam to clear the commandline. 17sendline (r"bind ! 'commandline \'\''" ) 18expect_prompt () 19 20# A do-nothing function to ensure we don't inherit weird completions. 21sendline (r"function foo; end" ) 22expect_prompt () 23 24sendline (r"cd (mktemp -d)" ) 25expect_prompt () 26 27 28# Helper function that sets the commandline to a glob, 29# optionally moves the cursor back, tab completes, and then clears the commandline. 30def tab_expand_glob (input ,expected ,move_cursor_back = 0 ): 31send (input ) 32if move_cursor_back > 0 : 33send ("\x1b[D" * move_cursor_back ) 34expect_str (input ) 35sleep (0.1 ) 36send ("\t" ) 37expect_str (expected ) 38send (r"!" )# clears the commandline 39 40 41# Don't report tab_expand_glob as the callsite since it is a helper. 42tab_expand_glob .callsite_skip = True 43 44sendline (r"touch aaa1 aaa2 aaa3" ) 45expect_prompt () 46 47tab_expand_glob (r"cat *" ,r"cat aaa1 aaa2 aaa3" ) 48tab_expand_glob (r"cat *2" ,r"cat aaa2" ) 49 50# Globs that fail to expand are left alone. 51tab_expand_glob (r"cat qqq*" ,r"cat qqq*" ) 52 53# Special characters in expanded globs are properly escaped. 54sendline (r"touch bb\*bbQ cc\;ccQ" ) 55expect_prompt () 56tab_expand_glob (r"cat *Q" ,r"cat bb\*bbQ cc\;ccQ" ) 57 58# Cases from #8593. 59sendline (r"rm -Rf *; touch README.rst" ) 60expect_prompt () 61tab_expand_glob (r"cat R*" ,r"cat README.rst" ) 62 63# Glob fails, so offer completion. 64tab_expand_glob (r"cat *.r" ,r"cat *.rst" ) 65tab_expand_glob (r"cat *.rst" ,r"cat README.rst" ) 66 67sendline (r"mkdir benchmarks && mkdir benchmarks/somedir && touch benchmarks/somefile" ) 68expect_prompt () 69 70tab_expand_glob (r"echo benchmarks/*" ,r"echo benchmarks/somedir benchmarks/somefile" ) 71 72# Trailing slash suppresses files. 73# Note we move the cursor backwards one, to right after the glob. 74tab_expand_glob (r"echo benchmarks/*/" ,r"echo benchmarks/somedir/" ,1 ) 75 76# Glob fails so it tries completions which also fails. 77# This happens whether the cursor is at the end, or just after the glob. 78tab_expand_glob (r"echo ben*/nomatch" ,r"echo ben*/nomatch" ) 79tab_expand_glob (r"echo ben*/nomatch" ,r"echo ben*/nomatch" ,len ("/nomatch" )) 80 81# Glob fails so it tries completions which succeeds. 82tab_expand_glob (r"echo ben*/somed" ,r"echo ben*/somedir" ) 83tab_expand_glob (r"echo ben*/somed" ,r"echo ben*/somedir" ,len ("/somed" )) 84 85# No glob in "current path component," offer completions. 86tab_expand_glob (r"echo {benchmarks/*/,benchm}a" ,r"echo {benchmarks/*/,benchm}arks/" ) 87 88# Test undo and redo. 89# "<" and ">" to undo and redo respectively. 90sendline (r"bind \< undo; bind \> redo" ) 91expect_prompt () 92 93send (r"echo benchmarks/*" ) 94sleep (0.1 ) 95send ("\t" ) 96expect_str (r"echo benchmarks/somedir benchmarks/somefile" ) 97 98# Undo un-expands the command. 99send (r"<" ) 100expect_str (r"echo benchmarks/*" ) 101 102# Redo re-expands it. 103send (r">" ) 104expect_str (r"echo benchmarks/somedir benchmarks/somefile" )