From e427c5f2248af327aab7a0c9300696fb0656ce45 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:34:37 +0200 Subject: [PATCH 1/5] feat: Add luaunit --- luaunit | 1 + tests/tests.lua | 5 +++++ 2 files changed, 6 insertions(+) create mode 160000 luaunit create mode 100644 tests/tests.lua diff --git a/luaunit b/luaunit new file mode 160000 index 0000000..0e0d3dd --- /dev/null +++ b/luaunit @@ -0,0 +1 @@ +Subproject commit 0e0d3dd06fe1955a01f0e6763bc8dc6847ee3e8d diff --git a/tests/tests.lua b/tests/tests.lua new file mode 100644 index 0000000..fb7f278 --- /dev/null +++ b/tests/tests.lua @@ -0,0 +1,5 @@ +local lu = require"luaunit.luaunit" + + +os.exit( lu.LuaUnit.run() ) + From 342823df2093fbdfcbafb1852d33db0d0968d815 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:46:09 +0200 Subject: [PATCH 2/5] test: Add tests for utils module --- tests/test_utils.lua | 198 +++++++++++++++++++++++++++++++++++++++++++ tests/tests.lua | 5 -- 2 files changed, 198 insertions(+), 5 deletions(-) create mode 100644 tests/test_utils.lua delete mode 100644 tests/tests.lua diff --git a/tests/test_utils.lua b/tests/test_utils.lua new file mode 100644 index 0000000..e934dbb --- /dev/null +++ b/tests/test_utils.lua @@ -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() ) + diff --git a/tests/tests.lua b/tests/tests.lua deleted file mode 100644 index fb7f278..0000000 --- a/tests/tests.lua +++ /dev/null @@ -1,5 +0,0 @@ -local lu = require"luaunit.luaunit" - - -os.exit( lu.LuaUnit.run() ) - From 9d581c501709f33be772138f79861c93f6d8ebc8 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:51:20 +0200 Subject: [PATCH 3/5] feat(ci-cd): Run lua tests on pull requests --- .github/workflows/run-tests.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/run-tests.yaml diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml new file mode 100644 index 0000000..9fcf87c --- /dev/null +++ b/.github/workflows/run-tests.yaml @@ -0,0 +1,19 @@ +name: Run tests + +on: + pull_request: + +jobs: + debug-builds: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Lua + uses: leafo/gh-actions-lua@v10 + with: + luaVersion: "5.4.6" + + - name: Run tests + run: lua -v ./tests/$(ls ./tests) + From e0323d2e13d8ef02d91612d17796c0e8e7dd5dfa Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:54:04 +0200 Subject: [PATCH 4/5] fix(ci-cd): Recursively checkout submodules --- .github/workflows/run-tests.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 9fcf87c..8e18e29 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -8,6 +8,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + submodules: "recursive" - name: Install Lua uses: leafo/gh-actions-lua@v10 From 9435fbe1f384c63c537a0063c64929341265b568 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 27 Apr 2024 20:58:05 +0200 Subject: [PATCH 5/5] fix: Add luaunit as submodule --- .gitmodules | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4b72ba1 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "luaunit"] + path = luaunit + url = https://github.com/bluebird75/luaunit