summaryrefslogtreecommitdiff
path: root/internal/lsp/code_fences_table_test.go
blob: c217bce1bde0572295022180c7e7b3549e01dd04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package lsp

import "testing"

func TestStripCodeFences_Table(t *testing.T) {
    cases := []struct{ name, in, want string }{
        {"no_fence", "return x", "return x"},
        {"plain_fence", "```\nA\nB\n```", "A\nB"},
        {"lang_fence", "```go\nfmt.Println()\n```", "fmt.Println()"},
        {"spaces", " \n```python\nprint('x')\n```\n ", "print('x')"},
    }
    for _, c := range cases {
        if got := stripCodeFences(c.in); got != c.want {
            t.Fatalf("%s: got %q want %q", c.name, got, c.want)
        }
    }
}

func TestStripInlineCodeSpan_Table(t *testing.T) {
    cases := []struct{ name, in, want string }{
        {"no_ticks", "text", "text"},
        {"single_span", "Use `foo()` here", "foo()"},
        {"multiple", "`a` + `b`", "a"},
        {"unmatched", "`missing end", "`missing end"},
    }
    for _, c := range cases {
        if got := stripInlineCodeSpan(c.in); got != c.want {
            t.Fatalf("%s: got %q want %q", c.name, got, c.want)
        }
    }
}