diff --git a/spec/init_spec.lua b/spec/init_spec.lua index 5702349..2e9fb5d 100644 --- a/spec/init_spec.lua +++ b/spec/init_spec.lua @@ -10,6 +10,14 @@ end local forge = require('forge') +local function flatten(segments) + local parts = {} + for _, seg in ipairs(segments) do + parts[#parts + 1] = seg[1] + end + return table.concat(parts) +end + describe('config', function() after_each(function() vim.g.forge = nil @@ -53,7 +61,7 @@ describe('format_pr', function() it('formats open PR with state icon', function() local entry = { number = 42, title = 'fix bug', state = 'OPEN', login = 'alice', created_at = '' } - local result = forge.format_pr(entry, fields, true) + local result = flatten(forge.format_pr(entry, fields, true)) assert.truthy(result:find('+')) assert.truthy(result:find('#42')) assert.truthy(result:find('fix bug')) @@ -62,20 +70,20 @@ describe('format_pr', function() it('formats merged PR', function() local entry = { number = 7, title = 'add feature', state = 'MERGED', login = 'bob', created_at = '' } - local result = forge.format_pr(entry, fields, true) + local result = flatten(forge.format_pr(entry, fields, true)) assert.truthy(result:find('m')) assert.truthy(result:find('#7')) end) it('formats closed PR', function() local entry = { number = 3, title = 'stale', state = 'CLOSED', login = 'eve', created_at = '' } - local result = forge.format_pr(entry, fields, true) + local result = flatten(forge.format_pr(entry, fields, true)) assert.truthy(result:find('x')) end) it('omits state prefix when show_state is false', function() local entry = { number = 1, title = 'no state', state = 'OPEN', login = 'dev', created_at = '' } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result:find('#1')) assert.falsy(result:match('^+')) end) @@ -83,14 +91,14 @@ describe('format_pr', function() it('truncates long titles', function() local long_title = string.rep('a', 100) local entry = { number = 9, title = long_title, state = 'OPEN', login = 'x', created_at = '' } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.falsy(result:find(long_title)) end) it('extracts author from table with login field', function() local entry = { number = 5, title = 't', state = 'OPEN', login = { login = 'nested' }, created_at = '' } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result:find('nested')) end) end) @@ -107,59 +115,59 @@ describe('format_issue', function() it('formats open issue', function() local entry = { number = 10, title = 'bug report', state = 'open', author = 'alice', created_at = '' } - local result = forge.format_issue(entry, fields, true) + local result = flatten(forge.format_issue(entry, fields, true)) assert.truthy(result:find('+')) assert.truthy(result:find('#10')) end) it('formats closed issue', function() local entry = { number = 11, title = 'done', state = 'closed', author = 'bob', created_at = '' } - local result = forge.format_issue(entry, fields, true) + local result = flatten(forge.format_issue(entry, fields, true)) assert.truthy(result:find('x')) end) it('handles opened state (GitLab)', function() local entry = { number = 12, title = 'mr issue', state = 'opened', author = 'c', created_at = '' } - local result = forge.format_issue(entry, fields, true) + local result = flatten(forge.format_issue(entry, fields, true)) assert.truthy(result:find('+')) end) end) describe('format_check', function() it('maps pass bucket', function() - local result = forge.format_check({ name = 'lint', bucket = 'pass' }) + local result = flatten(forge.format_check({ name = 'lint', bucket = 'pass' })) assert.truthy(result:find('%*')) assert.truthy(result:find('lint')) end) it('maps fail bucket', function() - local result = forge.format_check({ name = 'build', bucket = 'fail' }) + local result = flatten(forge.format_check({ name = 'build', bucket = 'fail' })) assert.truthy(result:find('x')) end) it('maps pending bucket', function() - local result = forge.format_check({ name = 'test', bucket = 'pending' }) + local result = flatten(forge.format_check({ name = 'test', bucket = 'pending' })) assert.truthy(result:find('~')) end) it('maps skipping bucket', function() - local result = forge.format_check({ name = 'optional', bucket = 'skipping' }) + local result = flatten(forge.format_check({ name = 'optional', bucket = 'skipping' })) assert.truthy(result:find('%-')) end) it('maps cancel bucket', function() - local result = forge.format_check({ name = 'cancelled', bucket = 'cancel' }) + local result = flatten(forge.format_check({ name = 'cancelled', bucket = 'cancel' })) assert.truthy(result:find('%-')) end) it('maps unknown bucket', function() - local result = forge.format_check({ name = 'mystery', bucket = 'something_else' }) + local result = flatten(forge.format_check({ name = 'mystery', bucket = 'something_else' })) assert.truthy(result:find('%?')) end) it('defaults to pending when bucket is nil', function() - local result = forge.format_check({ name = 'none' }) + local result = flatten(forge.format_check({ name = 'none' })) assert.truthy(result:find('~')) end) end) @@ -168,7 +176,7 @@ describe('format_run', function() it('formats successful run with branch', function() local run = { name = 'CI', branch = 'main', status = 'success', event = 'push', created_at = '' } - local result = forge.format_run(run) + local result = flatten(forge.format_run(run)) assert.truthy(result:find('%*')) assert.truthy(result:find('CI')) assert.truthy(result:find('main')) @@ -183,7 +191,7 @@ describe('format_run', function() event = 'workflow_dispatch', created_at = '', } - local result = forge.format_run(run) + local result = flatten(forge.format_run(run)) assert.truthy(result:find('x')) assert.truthy(result:find('manual')) end) @@ -191,13 +199,13 @@ describe('format_run', function() it('maps in_progress status', function() local run = { name = 'Test', branch = '', status = 'in_progress', event = 'push', created_at = '' } - local result = forge.format_run(run) + local result = flatten(forge.format_run(run)) assert.truthy(result:find('~')) end) it('maps cancelled status', function() local run = { name = 'Old', branch = '', status = 'cancelled', event = 'push', created_at = '' } - local result = forge.format_run(run) + local result = flatten(forge.format_run(run)) assert.truthy(result:find('%-')) end) end) @@ -242,39 +250,39 @@ describe('relative_time via format_pr', function() it('shows minutes for recent timestamps', function() local ts = os.date('%Y-%m-%dT%H:%M:%SZ', os.time() - 120) local entry = { n = 1, t = 'x', s = 'open', a = 'u', ts = ts } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result:match('%d+m')) end) it('shows hours', function() local ts = os.date('%Y-%m-%dT%H:%M:%SZ', os.time() - 7200) local entry = { n = 1, t = 'x', s = 'open', a = 'u', ts = ts } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result:match('%d+h')) end) it('shows days', function() local ts = os.date('%Y-%m-%dT%H:%M:%SZ', os.time() - 172800) local entry = { n = 1, t = 'x', s = 'open', a = 'u', ts = ts } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result:match('%d+d')) end) it('returns empty for nil timestamp', function() local entry = { n = 1, t = 'x', s = 'open', a = 'u', ts = nil } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result) end) it('returns empty for empty string timestamp', function() local entry = { n = 1, t = 'x', s = 'open', a = 'u', ts = '' } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result) end) it('returns empty for garbage timestamp', function() local entry = { n = 1, t = 'x', s = 'open', a = 'u', ts = 'not-a-date' } - local result = forge.format_pr(entry, fields, false) + local result = flatten(forge.format_pr(entry, fields, false)) assert.truthy(result) end) end) diff --git a/spec/sources_spec.lua b/spec/sources_spec.lua index 9a33f0f..802b4d8 100644 --- a/spec/sources_spec.lua +++ b/spec/sources_spec.lua @@ -86,7 +86,10 @@ describe('github', function() end) it('preserves in_progress status in normalize_run', function() - assert.equals('in_progress', gh:normalize_run({ databaseId = 1, status = 'in_progress' }).status) + assert.equals( + 'in_progress', + gh:normalize_run({ databaseId = 1, status = 'in_progress' }).status + ) end) end)