|
| 1 | +---@module 'luassert' |
| 2 | + |
| 3 | +local util = require('tests.util') |
| 4 | + |
| 5 | +---@param row integer |
| 6 | +---@param col integer |
| 7 | +---@param expected lsp.CompletionItem[] |
| 8 | +local function assert_items(row, col, expected) |
| 9 | + local source = require('render-markdown.integ.source') |
| 10 | + local actual = source.items(0, row, col) or {} |
| 11 | + table.sort(actual, function(a, b) |
| 12 | + return a.label < b.label |
| 13 | + end) |
| 14 | + assert.are.same(expected, actual) |
| 15 | +end |
| 16 | + |
| 17 | +---@param prefix string |
| 18 | +---@param label string |
| 19 | +---@param detail string |
| 20 | +---@param description? string |
| 21 | +---@return lsp.CompletionItem |
| 22 | +local function item(prefix, label, detail, description) |
| 23 | + ---@type lsp.CompletionItem |
| 24 | + return { |
| 25 | + kind = 12, |
| 26 | + label = prefix .. label, |
| 27 | + labelDetails = { |
| 28 | + detail = detail, |
| 29 | + description = description, |
| 30 | + }, |
| 31 | + } |
| 32 | +end |
| 33 | + |
| 34 | +describe('comp.md', function() |
| 35 | + it('checkbox', function() |
| 36 | + util.setup('tests/data/comp.md') |
| 37 | + |
| 38 | + ---@param prefix string |
| 39 | + ---@return lsp.CompletionItem[] |
| 40 | + local function items(prefix) |
| 41 | + return { |
| 42 | + item(prefix, '[ ] ', ' ', 'unchecked'), |
| 43 | + item(prefix, '[-] ', ' ', 'todo'), |
| 44 | + item(prefix, '[x] ', ' ', 'checked'), |
| 45 | + } |
| 46 | + end |
| 47 | + |
| 48 | + assert_items(2, 1, items(' ')) |
| 49 | + assert_items(4, 2, items('')) |
| 50 | + assert_items(6, 3, items('')) |
| 51 | + assert_items(8, 4, items('')) |
| 52 | + assert_items(10, 5, {}) |
| 53 | + assert_items(12, 6, {}) |
| 54 | + assert_items(14, 10, {}) |
| 55 | + assert_items(16, 6, {}) |
| 56 | + assert_items(17, 0, {}) |
| 57 | + end) |
| 58 | + |
| 59 | + it('callout', function() |
| 60 | + util.setup('tests/data/comp.md') |
| 61 | + |
| 62 | + ---@param prefix string |
| 63 | + ---@return lsp.CompletionItem[] |
| 64 | + local function items(prefix) |
| 65 | + return { |
| 66 | + item(prefix, '[!ABSTRACT]', ' Abstract'), |
| 67 | + item(prefix, '[!ATTENTION]', ' Attention'), |
| 68 | + item(prefix, '[!BUG]', ' Bug'), |
| 69 | + item(prefix, '[!CAUTION]', ' Caution'), |
| 70 | + item(prefix, '[!CHECK]', ' Check'), |
| 71 | + item(prefix, '[!CITE]', ' Cite'), |
| 72 | + item(prefix, '[!DANGER]', ' Danger'), |
| 73 | + item(prefix, '[!DONE]', ' Done'), |
| 74 | + item(prefix, '[!ERROR]', ' Error'), |
| 75 | + item(prefix, '[!EXAMPLE]', ' Example'), |
| 76 | + item(prefix, '[!FAILURE]', ' Failure'), |
| 77 | + item(prefix, '[!FAIL]', ' Fail'), |
| 78 | + item(prefix, '[!FAQ]', ' Faq'), |
| 79 | + item(prefix, '[!HELP]', ' Help'), |
| 80 | + item(prefix, '[!HINT]', ' Hint'), |
| 81 | + item(prefix, '[!IMPORTANT]', ' Important'), |
| 82 | + item(prefix, '[!INFO]', ' Info'), |
| 83 | + item(prefix, '[!MISSING]', ' Missing'), |
| 84 | + item(prefix, '[!NOTE]', ' Note'), |
| 85 | + item(prefix, '[!QUESTION]', ' Question'), |
| 86 | + item(prefix, '[!QUOTE]', ' Quote'), |
| 87 | + item(prefix, '[!SUCCESS]', ' Success'), |
| 88 | + item(prefix, '[!SUMMARY]', ' Summary'), |
| 89 | + item(prefix, '[!TIP]', ' Tip'), |
| 90 | + item(prefix, '[!TLDR]', ' Tldr'), |
| 91 | + item(prefix, '[!TODO]', ' Todo'), |
| 92 | + item(prefix, '[!WARNING]', ' Warning'), |
| 93 | + } |
| 94 | + end |
| 95 | + |
| 96 | + assert_items(20, 1, items(' ')) |
| 97 | + assert_items(22, 2, items('')) |
| 98 | + assert_items(24, 3, items('')) |
| 99 | + assert_items(26, 4, items('')) |
| 100 | + assert_items(28, 7, items('')) |
| 101 | + assert_items(30, 8, {}) |
| 102 | + assert_items(32, 15, {}) |
| 103 | + assert_items(34, 6, {}) |
| 104 | + end) |
| 105 | +end) |
0 commit comments