File tree Expand file tree Collapse file tree 4 files changed +60
-1
lines changed
Expand file tree Collapse file tree 4 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 1+ if ! exists (" g:loaded_switch" )
2+ finish
3+ endif
4+
5+ let b: switch_definitions =
6+ \ [
7+ \ g: switch_builtins .jinja_tag_type,
8+ \ ]
Original file line number Diff line number Diff line change 1+ if ! exists (" g:loaded_switch" )
2+ finish
3+ endif
4+
5+ let b: switch_definitions =
6+ \ [
7+ \ g: switch_builtins .python_dict_get,
8+ \ g: switch_builtins .python_string_style,
9+ \ ]
Original file line number Diff line number Diff line change @@ -226,7 +226,21 @@ let g:switch_builtins =
226226 \ ' markdown_task_item' : {
227227 \ ' ^\(\s*\)- \[ \] \(.*\)' : ' \1- [x] \2' ,
228228 \ ' ^\(\s*\)- \[x\] \(.*\)' : ' \1- [ ] \2' ,
229- \ }
229+ \ },
230+ \ ' jinja_tag_type' : {
231+ \ ' {{ \(.*\) }}' : ' {% \1 %}' ,
232+ \ ' {% \(.*\) %}' : ' {# \1 #}' ,
233+ \ ' {# \(.*\) #}' : ' {{ \1 }}' ,
234+ \ },
235+ \ ' python_dict_get' : {
236+ \ ' \v(%(\%@<!\k)+)\[(.{-})\]' : ' \1.get(\2)' ,
237+ \ ' \v(\k+)\.get\((.{-})\)' : ' \1[\2]' ,
238+ \ },
239+ \ ' python_string_style' : {
240+ \ ' f"\(\%([^"\\]\|\\.\)*\)"' : ' ' ' \1'' ' ,
241+ \ ' ' ' \(\%([^'' \\]\|\\.\)*\)'' ' : ' "\1"' ,
242+ \ ' f\@!"\(\%([^"\\]\|\\.\)*\)"' : ' f"\1"' ,
243+ \ },
230244 \ }
231245
232246let g: switch_definitions =
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ describe "python definitions" do
4+ let ( :filename ) { 'test.py' }
5+
6+ specify "string type" do
7+ set_file_contents 'foo = "bar?"'
8+
9+ vim . search ( 'bar' ) . switch
10+ assert_file_contents 'foo = f"bar?"'
11+
12+ vim . switch
13+ assert_file_contents "foo = 'bar?'"
14+
15+ vim . switch
16+ assert_file_contents 'foo = "bar?"'
17+ end
18+
19+ specify "fetch array access" do
20+ set_file_contents "foo['one']"
21+
22+ vim . search ( 'foo' ) . switch
23+ assert_file_contents "foo.get('one')"
24+
25+ vim . switch
26+ assert_file_contents "foo['one']"
27+ end
28+ end
You can’t perform that action at this time.
0 commit comments