mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib/lua: add isKeyword
and isIdentifier
Allow testing whether a string is a valid lua identifier or a reserved keyword.
This commit is contained in:
parent
b64ee08d6b
commit
01cf43dbaa
3 changed files with 118 additions and 3 deletions
|
@ -6,6 +6,45 @@
|
|||
helpers,
|
||||
}:
|
||||
let
|
||||
luaNames = {
|
||||
# Keywords in lua 5.1
|
||||
keywords = [
|
||||
"and"
|
||||
"break"
|
||||
"do"
|
||||
"else"
|
||||
"elseif"
|
||||
"end"
|
||||
"false"
|
||||
"for"
|
||||
"function"
|
||||
"if"
|
||||
"in"
|
||||
"local"
|
||||
"nil"
|
||||
"not"
|
||||
"or"
|
||||
"repeat"
|
||||
"return"
|
||||
"then"
|
||||
"true"
|
||||
"until"
|
||||
"while"
|
||||
];
|
||||
identifiers = [
|
||||
"validIdentifier"
|
||||
"valid_identifier"
|
||||
"_also_valid_"
|
||||
"_weirdNameFMT"
|
||||
];
|
||||
other = [
|
||||
"1_starts_with_digit"
|
||||
"01234"
|
||||
"12340"
|
||||
"kebab-case"
|
||||
];
|
||||
};
|
||||
|
||||
results = pkgs.lib.runTests {
|
||||
testToLuaObject = {
|
||||
expr = helpers.toLuaObject {
|
||||
|
@ -114,6 +153,51 @@ let
|
|||
expected = ''{["c"] = { },["d"] = {["g"] = { }}}'';
|
||||
};
|
||||
|
||||
testIsLuaKeyword = {
|
||||
expr = builtins.mapAttrs (_: builtins.filter helpers.lua.isKeyword) luaNames;
|
||||
expected = {
|
||||
keywords = [
|
||||
"and"
|
||||
"break"
|
||||
"do"
|
||||
"else"
|
||||
"elseif"
|
||||
"end"
|
||||
"false"
|
||||
"for"
|
||||
"function"
|
||||
"if"
|
||||
"in"
|
||||
"local"
|
||||
"nil"
|
||||
"not"
|
||||
"or"
|
||||
"repeat"
|
||||
"return"
|
||||
"then"
|
||||
"true"
|
||||
"until"
|
||||
"while"
|
||||
];
|
||||
identifiers = [ ];
|
||||
other = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
testIsLuaIdentifier = {
|
||||
expr = builtins.mapAttrs (_: builtins.filter helpers.lua.isIdentifier) luaNames;
|
||||
expected = {
|
||||
keywords = [ ];
|
||||
identifiers = [
|
||||
"validIdentifier"
|
||||
"valid_identifier"
|
||||
"_also_valid_"
|
||||
"_weirdNameFMT"
|
||||
];
|
||||
other = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
testUpperFirstChar = {
|
||||
expr = map helpers.upperFirstChar [
|
||||
"foo"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue