MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / TestExtractFencedCodeBlock

Function TestExtractFencedCodeBlock

internal/domain/codeblock_test.go:5–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestExtractFencedCodeBlock(t *testing.T) {
6 tests := []struct {
7 name string
8 input string
9 last bool
10 want string
11 wantFound bool
12 }{
13 {
14 name: "no code block",
15 input: "Just some prose.\nNo code here.",
16 want: "",
17 },
18 {
19 name: "backtick fence with language tag",
20 input: "Here you go:\n```python\ndef f():\n return 1\n```\nHope that helps.",
21 want: "def f():\n return 1",
22 wantFound: true,
23 },
24 {
25 name: "tilde fence",
26 input: "~~~\necho hi\n~~~",
27 want: "echo hi",
28 wantFound: true,
29 },
30 {
31 name: "first block by default",
32 input: "```go\nfirst\n```\ntext\n```go\nsecond\n```",
33 want: "first",
34 wantFound: true,
35 },
36 {
37 name: "last block when requested",
38 input: "```go\nfirst\n```\ntext\n```go\nsecond\n```",
39 last: true,
40 want: "second",
41 wantFound: true,
42 },
43 {
44 name: "four backtick fence containing a three backtick fence",
45 input: "````markdown\n```bash\nls\n```\n````",
46 want: "```bash\nls\n```",
47 wantFound: true,
48 },
49 {
50 name: "closing fence may be longer than opening fence",
51 input: "```\ncode\n`````\nafter",
52 want: "code",
53 wantFound: true,
54 },
55 {
56 name: "tilde line does not close backtick fence",
57 input: "```\n~~~\ncode\n```",
58 want: "~~~\ncode",
59 wantFound: true,
60 },
61 {
62 name: "closing fence with info string is content",

Callers

nothing calls this directly

Calls 1

ExtractFencedCodeBlockFunction · 0.85

Tested by

no test coverage detected