diff --git a/autoload/easy_align.vim b/autoload/easy_align.vim index 8c69812..dacc1e3 100644 --- a/autoload/easy_align.vim +++ b/autoload/easy_align.vim @@ -551,9 +551,7 @@ function! s:input(str, default, vis) " EasyAlign command can be called without visual selection redraw endif - call inputsave() let got = input(a:str, a:default) - call inputrestore() return got endfunction diff --git a/test/READMD.md b/test/READMD.md new file mode 100644 index 0000000..dc95d58 --- /dev/null +++ b/test/READMD.md @@ -0,0 +1,13 @@ +Test cases for vim-easy-align +============================= + +### Prerequisite + +- [Vader.vim](https://github.com/junegunn/vader.vim) + +### Run + +```vim +:Vader * +``` + diff --git a/test/easy-align.vader b/test/easy-align.vader new file mode 100644 index 0000000..4e29b36 --- /dev/null +++ b/test/easy-align.vader @@ -0,0 +1,369 @@ +Execute: + silent! unlet g:easy_align_delimiters + silent! unlet g:easy_align_ignore_groups + silent! unlet g:easy_align_ignore_unmatched + silent! unlet g:easy_align_indentation + silent! unlet g:easy_align_delimiter_align + vnoremap :EasyAlign + +Given (the beatles): + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (around first space): + vip + \ + \ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (around second space): + vip + \ + 2\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (around all spaces): + vip + \ + *\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (right-align around all spaces): + vip + \\ + *\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (center-align around all spaces): + vip + \\\ + *\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (center-align around the last space): + vip + \\\ + -\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (right-align around second space): + vip + \\ + 2\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (left-right alternating alignment): + vip + \ + **\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (right-left alternating alignment): + vip + \\ + **\ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (with numeric left/right margin): + vip + \ + * + \2\ + \ + \5\ + * + \ + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +Do (with string left/right margin): + vip + \ + \lft\ + \rgt\ + *\ + +Expect: + Paul lft rgtMcCartneylft rgt1942 + Georgelft rgtHarrison lft rgt1943mmdd + Ringo lft rgtStarr lft rgt1940mm + Pete lft rgtBest lft rgt1941 + +Execute (with regular expression): + 1,4EasyAlign*/../ + +Expect: + Pa ul Mc Ca rt ne y 19 42 + Ge or ge Ha rr is on 19 43 mm dd + Ri ng o St ar r 19 40 mm + Pe te Be st 19 41 + +Expect: + Paul McCartney 1942 + George Harrison 1943mmdd + Ringo Starr 1940mm + Pete Best 1941 + +########################################################### + +Given ruby (delimiters in comments and strings): + xyz="abc=def" + a=b#=c + +Do (align around all =): + vip + \*= + +Expect ruby (are not aligned): + xyz = "abc=def" + a = b#=c + +########################################################### + +Given javascript (json): + var jdbc = { + // JDBC driver for MySQL database: + driver: "com.mysql.jdbc.Driver", + /* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */ + url: 'jdbc:mysql://localhost/test', + database: "test", + "user:pass":"r00t:pa55" + }; + +Do (around first colon): + vip\*: + +Expect javascript: + var jdbc = { + // JDBC driver for MySQL database: + driver: "com.mysql.jdbc.Driver", + /* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */ + url: 'jdbc:mysql://localhost/test', + database: "test", + "user:pass": "r00t:pa55" + }; + +Do (around first colon, do not ignore comments and strings): + vip\\*: + +Expect javascript: + var jdbc = { + // JDBC driver for MySQL database: + driver: "com.mysql.jdbc.Driver", + /* JDBC URL for the connection (jdbc: mysql: //HOSTNAME/DATABASE) */ + url: 'jdbc: mysql: //localhost/test', + database: "test", + "user: pass": "r00t: pa55" + }; + +Do (do not ignore comments and strings, do not ignore unmatched): + vip\\\*: + +Expect javascript: + var jdbc = { + // JDBC driver for MySQL database: + driver: "com.mysql.jdbc.Driver", + /* JDBC URL for the connection (jdbc: mysql: //HOSTNAME/DATABASE) */ + url: 'jdbc: mysql: //localhost/test', + database: "test", + "user: pass": "r00t: pa55" + }; + +Expect javascript: + var jdbc = { + // JDBC driver for MySQL database: + driver: "com.mysql.jdbc.Driver", + /* JDBC URL for the connection (jdbc:mysql://HOSTNAME/DATABASE) */ + url: 'jdbc:mysql://localhost/test', + database: "test", + "user:pass":"r00t:pa55" + }; + +########################################################### + +Given (table): + | Option| Type | Default | Description | + |--|--|--|--| + | threads | Fixnum | 1 | number of threads in the thread pool | + |queues |Fixnum | 1 | number of concurrent queues | + |queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + |batch | Boolean | false | enables batch processing mode | + |batch_size | Fixnum | nil | number of maximum items to be assigned at once | + |logger | Logger | nil | logger instance for debug logs | + +Do (around all |): + vip\*| + +Expect: + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + +Do (around all |, and right-align 3rd and center-align the last): + vip\*| + gv\\3| + gv\\\-| + +Expect: + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + +Do (Left-right alternating alignment): + vip\**| + +Expect: + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + +Do (Right-left alternating alignment): + vip\\**| + +Expect: + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + +Do (Right-left alternating alignment, indent: deep): + vip\\**\\| + +Expect: + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + +# Doesn't work. Why? +# Do (Repeat the last command): +# :%\=g:easy_align_last_command\\ + +Execute (Repeat the last command): + execute '%'.g:easy_align_last_command + +Expect: + | Option | Type | Default | Description | + | -- | -- | -- | -- | + | threads | Fixnum | 1 | number of threads in the thread pool | + | queues | Fixnum | 1 | number of concurrent queues | + | queue_size | Fixnum | 1000 | size of each queue | + | interval | Numeric | 0 | dispatcher interval for batch processing | + | batch | Boolean | false | enables batch processing mode | + | batch_size | Fixnum | nil | number of maximum items to be assigned at once | + | logger | Logger | nil | logger instance for debug logs | + +Do (around all | with no margin, right-align 2nd to last): + vip\\0\\0\*| + vip\\\0\\0\-2| + +Expect: + |Option |Type |Default|Description | + |-- |-- | --|-- | + |threads |Fixnum | 1|number of threads in the thread pool | + |queues |Fixnum | 1|number of concurrent queues | + |queue_size|Fixnum | 1000|size of each queue | + |interval |Numeric| 0|dispatcher interval for batch processing | + |batch |Boolean| false|enables batch processing mode | + |batch_size|Fixnum | nil|number of maximum items to be assigned at once| + |logger |Logger | nil|logger instance for debug logs | + +########################################################### + +Given (comma-separated items): + aaa, bb,c + d,eeeeeee + fffff, gggggggggg, + h, , ii + j,,k + +Do (around all commas): + vip\*, + +Expect: + aaa, bb, c + d, eeeeeee + fffff, gggggggggg, + h, , ii + j, , k +