Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automated testing #3490

Merged
merged 37 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6ae3061
feat: automated testing
Rathoz Nov 7, 2023
6910aeb
fix lint check
Rathoz Nov 7, 2023
9634870
Move busted config to file to allow for local runs too
Rathoz Nov 7, 2023
5289487
move the root to all
Rathoz Nov 7, 2023
c36ef05
pipeline update
Rathoz Nov 7, 2023
def5b3e
split testing to it's own workflow
Rathoz Nov 7, 2023
60e046a
name
Rathoz Nov 7, 2023
bedec16
remove unneeded dep
Rathoz Nov 7, 2023
1a26a53
Try to improve the pipeline
Rathoz Nov 8, 2023
4577237
Job names
Rathoz Nov 8, 2023
55e39dc
Merge workflow fiels
Rathoz Nov 8, 2023
1a664c0
fix typo
Rathoz Nov 8, 2023
cd80ce9
add logic test
Rathoz Nov 8, 2023
b322d92
try to have some handling for files not on git
Rathoz Nov 8, 2023
c9191b6
Remove now unneeded old style tests
Rathoz Nov 8, 2023
b25d2f7
Move Abbr to automated testing
Rathoz Nov 8, 2023
31878b4
Clean ups
Rathoz Nov 8, 2023
4840f23
Auto enable busted and luassert vscode addons
Rathoz Nov 8, 2023
482e351
Remove unneeded custom path
Rathoz Nov 8, 2023
d763d71
undo last, is needed
Rathoz Nov 8, 2023
d1b439f
typo
Rathoz Nov 8, 2023
8d745da
Move folder for currency
Rathoz Nov 8, 2023
d947f9e
Clean the package change
Rathoz Nov 8, 2023
3ab8a6c
Currency Tests plus stupid mediawiki mocking
Rathoz Nov 8, 2023
0a27ab8
remove print
Rathoz Nov 8, 2023
f992bee
name tests
Rathoz Nov 8, 2023
3341e8f
Flags, rework mw handling
Rathoz Nov 8, 2023
851f1b3
Page
Rathoz Nov 8, 2023
e676a14
Add `ustring` to mw defines
Rathoz Nov 8, 2023
bec3cb5
Fix flag testcases
Rathoz Nov 8, 2023
ddafc63
add `varexists`
Rathoz Nov 8, 2023
fd77126
Fix comment
Rathoz Nov 8, 2023
0bb674e
Handle bad input in flags.lua
Rathoz Nov 8, 2023
bbd9b90
Migrate variable tests, fix var sim
Rathoz Nov 8, 2023
76c70ba
Migrate Locale tests
Rathoz Nov 8, 2023
4db03b7
Migrate date tests
Rathoz Nov 8, 2023
e34c7d4
unused import
Rathoz Nov 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
return {
_all = {
verbose = true,
helper = 'spec/test_helper.lua',
},
default = {
ROOT = {"spec"},
},
ci = {
ROOT = {"spec"},
},
}
54 changes: 43 additions & 11 deletions .github/workflows/luacheck.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,66 @@
name: Code Style
name: Code Style and Unit Tests

on: [pull_request, workflow_dispatch]

jobs:
test-lua:
lua-code-style:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- name: Checkout
uses: actions/checkout@master

- uses: leafo/gh-actions-lua@v9
- name: Setup lua
uses: leafo/gh-actions-lua@v9
with:
luaVersion: "5.1"
luaVersion: '5.1'

- uses: leafo/gh-actions-luarocks@v4
- name: Setup luarock
uses: leafo/gh-actions-luarocks@v4

- name: setup
- name: Setup dependencies
run: |
luarocks install luacheck

- name: test
- name: Run lint
run: |
luacheck ./ |
luacheck ./ --formatter=JUnit > report.xml

- name: junit
- name: Report lint
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: 'report.xml'
check_name: 'junit-report'
annotate_notice: false
check_name: 'Lint Report'

lua-unit-test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@master

- name: Setup lua
uses: leafo/gh-actions-lua@v9
with:
luaVersion: '5.1'

- name: Setup luarocks
uses: leafo/gh-actions-luarocks@v4

- name: Setup dependencies
run: |
luarocks install busted

- name: Run test
uses: lunarmodules/[email protected]
with:
args: --run=ci --output=junit > busted.xml

- name: Report test
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: 'busted.xml'
check_name: 'Test Report'
6 changes: 5 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"diagnostics.neededFileStatus": {
"codestyle-check": "None",
"name-style-check": "None"
}
},
"workspace.library": [
"${3rd}/busted/library",
"${3rd}/luassert/library"
]
}
36 changes: 25 additions & 11 deletions plugins/sumneko_plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ local liquipedia = {}

local importFunctions = {}
importFunctions.functions = {'require', 'mw%.loadData', 'Lua%.import', 'Lua%.requireIfExists'}
importFunctions.prefixModules = {table = 'standard.', math = 'standard.', string = 'standard.'}
importFunctions.prefixModules = {table = 'standard.', math = 'standard.', string = 'standard.', array = 'standard.'}
mbergen marked this conversation as resolved.
Show resolved Hide resolved

function importFunctions._row(name)
local normModuleName =
name
:gsub('Module:', '') -- Remove starting Module:
:gsub('^%u', string.lower) -- Lower case first letter
:gsub('%u', '_%0') -- Prefix uppercase letters with an underscore
:gsub('/', '_') -- Change slash to underscore
:gsub('__', '_') -- Never have two underscores in a row
:lower() -- Lowercase everything
---Transforms a MediaWiki module name, e.g. `Module:Array`, into a lua repository name, e.g. `array`
---@param name string
---@return string
function importFunctions.luaifyModuleName(name)
local normModuleName = name
:gsub('Module:', '')-- Remove starting Module:
:gsub('^%u', string.lower)-- Lower case first letter
:gsub('%u', '_%0')-- Prefix uppercase letters with an underscore
:gsub('/', '_')-- Change slash to underscore
:gsub('__', '_')-- Never have two underscores in a row
:lower() -- Lowercase everything

if importFunctions.prefixModules[normModuleName] then
normModuleName = importFunctions.prefixModules[normModuleName] .. normModuleName
end

return ' ---@module \'' .. normModuleName ..'\''
return normModuleName
end

function importFunctions._row(name)
local normModuleName = importFunctions.luaifyModuleName(name)

return ' ---@module \'' .. normModuleName .. '\''
end

function importFunctions.annotate(text, funcName, diffs)
Expand Down Expand Up @@ -57,9 +65,15 @@ function OnSetText(uri, text)
return nil
end

if text:sub(1, 8) == '---@meta' then
return nil
end

local diffs = {}

liquipedia.annotate(text, diffs)

return diffs
end

return importFunctions
18 changes: 18 additions & 0 deletions spec/abbreviation_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- Triple Comment to Enable our LLS Plugin
describe('abbreviation', function()
local Abbreviation = require('Module:Abbreviation')

describe('make abbreviation', function()
it('Empty input returns nil', function()
assert.is_nil(Abbreviation.make())
assert.is_nil(Abbreviation.make(''))
end)
it('Only one input returns nil', function()
assert.is_nil(Abbreviation.make('Abc', nil))
assert.is_nil(Abbreviation.make('', 'Def'))
end)
it('Abbreviation works', function()
assert.are_same('<abbr title="Cookie">Cake</abbr>', Abbreviation.make('Cake', 'Cookie'))
end)
end)
end)
208 changes: 208 additions & 0 deletions spec/array_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
--- Triple Comment to Enable our LLS Plugin
describe('array', function()
local Array = require('Module:Array')
local Table = require('Module:Table')

describe('isArray', function()
it('Empty table is array', function()
assert.is_true(Array.isArray{})
end)
it('Arrays are array', function()
assert.is_true(Array.isArray{5, 2, 3})
end)
it('Tables are array', function()
assert.is_false(Array.isArray{a = 1, [3] = 2, c = 3})
assert.is_false(Array.isArray{5, 2, c = 3})
end)
end)

describe('Copy', function()
it('check', function()
local a, b, c = {1, 2, 3}, {}, {{5}}
assert.are_same(a, Array.copy(a))
assert.is_false(Array.copy(b) == b)
assert.is_true(Array.copy(c)[1] == c[1])
end)
end)

describe('Sub', function()
it('check', function()
local a = {3, 5, 7, 11}
assert.are_same({5, 7, 11}, Array.sub(a, 2))
assert.are_same({5, 7}, Array.sub(a, 2, 3))
assert.are_same({7, 11}, Array.sub(a, -2, -1))
end)
end)

describe('Map', function()
it('check', function()
local a = {1, 2, 3}
assert.are_same({2, 4, 6}, Array.map(a, function(x)
return 2 * x
end))
end)
end)

describe('Filter', function()
it('check', function()
local a = {1, 2, 3}
assert.are_same({1, 3}, Array.filter(a, function(x)
return x % 2 == 1
end
))
end)
end)

describe('Flatten', function()
it('check', function()
local a = {1, 2, 3, {5, 3}, {6, 4}}
assert.are_same({1, 2, 3, 5, 3, 6, 4}, Array.flatten(a))
end)
end)

describe('All', function()
it('check', function()
local a = {1, 2, 3}
assert.is_true(Array.all(a, function(value)
return type(value) == 'number'
end))
assert.is_false(Array.all(a, function(value)
return value < 3
end))
end)
end)

describe('Any', function()
it('check', function()
local a = {1, 2, 3}
assert.is_false(Array.any(a, function(value)
return type(value) == 'string'
end))
assert.is_true(Array.any(a, function(value)
return value < 3
end))
end)
end)

describe('Find', function()
it('check', function()
local a = {4, 6, 9}
local b = Array.find(a, function(value, index)
return index == 2
end)
local c = Array.find(a, function(value, index)
return index == -1
end)
assert.are_equal(6, b)
assert.are_equal(nil, c)
end)
end)

describe('Revese', function()
it('check', function()
local a = {4, 6, 9}
assert.are_same({9, 6, 4}, Array.reverse(a))
end)
end)

describe('Append', function()
it('check', function()
local a = {2, 3}
assert.are_same({2, 3, 5, 7, 11}, Array.append(a, 5, 7, 11))
assert.are_same({2, 3}, a)
end)
end)

describe('AppendWith', function()
it('check', function()
local a = {2, 3}
assert.are_same({2, 3, 5, 7, 11}, Array.appendWith(a, 5, 7, 11))
assert.are_same({2, 3, 5, 7, 11}, a)
end)
end)

describe('Extend', function()
it('check', function()
local a, b, c = {2, 3}, {5, 7, 11}, {13}
assert.are_same({2, 3, 5, 7, 11, 13}, Array.extend(a, b, c))
assert.are_same({2, 3}, a)
end)
end)

describe('ExtendWith', function()
it('check', function()
local a, b, c = {2, 3}, {5, 7, 11}, {13}
assert.are_same({2, 3, 5, 7, 11, 13}, Array.extendWith(a, b, c))
assert.are_same({2, 3, 5, 7, 11, 13}, a)
end)
end)

describe('MapIndexes', function()
it('check', function()
local a = {p1 = 'Abc', p2 = 'cd', p3 = 'cake'}
assert.are_same({'p1Abc', 'p2cd'}, Array.mapIndexes(function(x)
local prefix = 'p' .. x
return a[prefix] ~= 'cake' and (prefix .. a[prefix]) or nil
end))
end)
end)

describe('Range', function()
it('check', function()
assert.are_same({1, 2, 3}, Array.range(1, 3))
assert.are_same({2, 3}, Array.range(2, 3))
end)
end)

describe('ForEach', function()
it('check', function()
local a = {}
Array.forEach(Array.range(1, 3), function(x)
table.insert(a, 1, x)
end)
assert.are_same({3, 2, 1}, a)
end)
end)

describe('Reduce', function()
it('check', function()
local function pow(x, y) return x ^ y end
assert.are_same(32768, Array.reduce({2, 3, 5}, pow))
assert.are_same(1, Array.reduce({2, 3, 5}, pow, 1))
end)
end)

describe('ExtractValues', function()
it('check', function()
local a = {i = 1, j = 2, k = 3, z = 0}

local customOrder1 = function(_, key1, key2) return key1 > key2 end
local customOrder2 = function(tbl, key1, key2) return tbl[key1] < tbl[key2] end

assert.are_same({1, 2, 3, 0}, Array.extractValues(a, Table.iter.spairs))
assert.are_same({0, 3, 2, 1}, Array.extractValues(a, Table.iter.spairs, customOrder1))
assert.are_same({0, 1, 2, 3}, Array.extractValues(a, Table.iter.spairs, customOrder2))

local extractedArray = Array.extractValues(a)
table.sort(extractedArray)
assert.are_same({0, 1, 2, 3}, extractedArray)
end)
end)

describe('ExtractKeys', function()
it('check', function()
local a = {k = 3, i = 1, z = 0, j = 2}

local customOrder1 = function(_, key1, key2) return key1 > key2 end
local customOrder2 = function(tbl, key1, key2) return tbl[key1] < tbl[key2] end

assert.are_same({'i', 'j', 'k', 'z'}, Array.extractKeys(a, Table.iter.spairs))
assert.are_same({'z', 'k', 'j', 'i'}, Array.extractKeys(a, Table.iter.spairs, customOrder1))
assert.are_same({'z', 'i', 'j', 'k'}, Array.extractKeys(a, Table.iter.spairs, customOrder2))

local extractedKeys = Array.extractKeys(a)
table.sort(extractedKeys)
assert.are_same({'i', 'j', 'k', 'z'}, extractedKeys)
end)
end)
end)
Loading
Loading