mirror of
https://github.com/Myzel394/jsonfly.nvim.git
synced 2025-06-17 19:55:26 +02:00
commit
ec7326783d
21
.github/workflows/run-tests.yaml
vendored
Normal file
21
.github/workflows/run-tests.yaml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: Run tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
debug-builds:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: "recursive"
|
||||
|
||||
- name: Install Lua
|
||||
uses: leafo/gh-actions-lua@v10
|
||||
with:
|
||||
luaVersion: "5.4.6"
|
||||
|
||||
- name: Run tests
|
||||
run: lua -v ./tests/$(ls ./tests)
|
||||
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "luaunit"]
|
||||
path = luaunit
|
||||
url = https://github.com/bluebird75/luaunit
|
1
luaunit
Submodule
1
luaunit
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 0e0d3dd06fe1955a01f0e6763bc8dc6847ee3e8d
|
198
tests/test_utils.lua
Normal file
198
tests/test_utils.lua
Normal file
@ -0,0 +1,198 @@
|
||||
local lu = require"luaunit.luaunit"
|
||||
local utils = require"lua.jsonfly.utils"
|
||||
|
||||
function testBasicKey()
|
||||
local key = "foo.bar"
|
||||
---@type KeyDescription[]
|
||||
local EXPECTED = {
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "foo",
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "bar",
|
||||
}
|
||||
}
|
||||
|
||||
local descriptor = utils:extract_key_description(key)
|
||||
|
||||
lu.assertEquals(descriptor, EXPECTED)
|
||||
end
|
||||
|
||||
function testArrayKey()
|
||||
local key = "foo.0.bar"
|
||||
---@type KeyDescription[]
|
||||
local EXPECTED = {
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "foo",
|
||||
},
|
||||
{
|
||||
type = "array_wrapper",
|
||||
},
|
||||
{
|
||||
type = "array_index",
|
||||
key = 0,
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "bar",
|
||||
}
|
||||
}
|
||||
|
||||
local descriptor = utils:extract_key_description(key)
|
||||
|
||||
lu.assertEquals(descriptor, EXPECTED)
|
||||
end
|
||||
|
||||
function testNestedArrayKey()
|
||||
local key = "foo.0.bar.1.baz"
|
||||
---@type KeyDescription[]
|
||||
local EXPECTED = {
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "foo",
|
||||
},
|
||||
{
|
||||
type = "array_wrapper",
|
||||
},
|
||||
{
|
||||
type = "array_index",
|
||||
key = 0,
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "bar",
|
||||
},
|
||||
{
|
||||
type = "array_wrapper",
|
||||
},
|
||||
{
|
||||
type = "array_index",
|
||||
key = 1,
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "baz",
|
||||
}
|
||||
}
|
||||
|
||||
local descriptor = utils:extract_key_description(key)
|
||||
|
||||
lu.assertEquals(descriptor, EXPECTED)
|
||||
end
|
||||
|
||||
function testEscapedArrayDoesNotCreateArray()
|
||||
local key = "foo.\\0.bar"
|
||||
---@type KeyDescription[]
|
||||
local EXPECTED = {
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "foo",
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "0",
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "bar",
|
||||
}
|
||||
}
|
||||
|
||||
local descriptor = utils:extract_key_description(key)
|
||||
|
||||
lu.assertEquals(descriptor, EXPECTED)
|
||||
end
|
||||
|
||||
function testBracketArrayKey()
|
||||
local key = "foo.[0].bar"
|
||||
---@type KeyDescription[]
|
||||
local EXPECTED = {
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "foo",
|
||||
},
|
||||
{
|
||||
type = "array_wrapper",
|
||||
},
|
||||
{
|
||||
type = "array_index",
|
||||
key = 0,
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "bar",
|
||||
}
|
||||
}
|
||||
|
||||
local descriptor = utils:extract_key_description(key)
|
||||
|
||||
lu.assertEquals(descriptor, EXPECTED)
|
||||
end
|
||||
|
||||
function testRootArrayKey()
|
||||
local key = "0.foo"
|
||||
---@type KeyDescription[]
|
||||
local EXPECTED = {
|
||||
{
|
||||
type = "array_wrapper",
|
||||
},
|
||||
{
|
||||
type = "array_index",
|
||||
key = 0,
|
||||
},
|
||||
{
|
||||
type = "object_wrapper",
|
||||
},
|
||||
{
|
||||
type = "key",
|
||||
key = "foo",
|
||||
}
|
||||
}
|
||||
|
||||
local descriptor = utils:extract_key_description(key)
|
||||
|
||||
lu.assertEquals(descriptor, EXPECTED)
|
||||
end
|
||||
|
||||
|
||||
os.exit( lu.LuaUnit.run() )
|
||||
|
Loading…
x
Reference in New Issue
Block a user