mirror of
https://github.com/nix-community/nixvim.git
synced 2025-08-29 22:30:13 +02:00
lib: fix escaping bugs in wrapVimscriptForLua and wrapLuaForVimscript
These functions had very similar bugs: they didn't check if their chosen "close token" was already present in the string they're escaping. I went ahead and did the work implied by the TODOs: search for a "close token" that is *not* in the original string. Pretty simple concept, but it turned into an annoying amount of code. I couldn't find anything in upstream nixpkgs lib, or some clever insight about lua/vimscript that makes this work unecessary, but I'll be thrilled (and a little bummed about a wasted afternoon) to learn about something.
This commit is contained in:
parent
2df1bdd14d
commit
400d1d927d
2 changed files with 120 additions and 14 deletions
|
@ -374,6 +374,41 @@ let
|
|||
];
|
||||
};
|
||||
};
|
||||
|
||||
testEscapeStringForLua = {
|
||||
expr = lib.mapAttrs (_: helpers.utils.toLuaLongLiteral) {
|
||||
simple = "simple";
|
||||
depth-one = " ]] ";
|
||||
depth-two = " ]] ]=] ";
|
||||
};
|
||||
expected = {
|
||||
simple = "[[simple]]";
|
||||
depth-one = "[=[ ]] ]=]";
|
||||
depth-two = "[==[ ]] ]=] ]==]";
|
||||
};
|
||||
};
|
||||
|
||||
testEscapeStringForVimscript = {
|
||||
expr = lib.mapAttrs (_: helpers.utils.toVimscriptHeredoc) {
|
||||
simple = "simple";
|
||||
depth-one = "EOF";
|
||||
depth-two = "EOF EOFF";
|
||||
};
|
||||
expected = {
|
||||
simple = ''
|
||||
<< EOF
|
||||
simple
|
||||
EOF'';
|
||||
depth-one = ''
|
||||
<< EOFF
|
||||
EOF
|
||||
EOFF'';
|
||||
depth-two = ''
|
||||
<< EOFFF
|
||||
EOF EOFF
|
||||
EOFFF'';
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
if results == [ ] then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue