File: list_items_test.go

package info (click to toggle)
golang-github-johanneskaufmann-html-to-markdown 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: makefile: 3
file content (123 lines) | stat: -rw-r--r-- 2,459 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package domutils

import (
	"context"
	"testing"

	"github.com/JohannesKaufmann/html-to-markdown/v2/internal/tester"
)

func TestMoveListItems(t *testing.T) {
	runs := []struct {
		desc     string
		input    string
		expected string
	}{
		{
			desc:  "not needed in normal list",
			input: "<div><ul><li>A</li><li>B</li><li>C</li></ul></div>",
			expected: `
├─body
│ ├─div
│ │ ├─ul
│ │ │ ├─li
│ │ │ │ ├─#text "A"
│ │ │ ├─li
│ │ │ │ ├─#text "B"
│ │ │ ├─li
│ │ │ │ ├─#text "C"
			`,
		},
		{
			desc:  "#text moves into the previous li",
			input: "<ul><li>A</li>B</ul>",
			expected: `
├─body
│ ├─ul
│ │ ├─li
│ │ │ ├─#text "A"
│ │ │ ├─#text "B"
			`,
		},
		{
			desc:  "div moves into the previous li",
			input: "<ul><li>A</li><div>B</div></ul>",
			expected: `
├─body
│ ├─ul
│ │ ├─li
│ │ │ ├─#text "A"
│ │ │ ├─div
│ │ │ │ ├─#text "B"
			`,
		},
		{
			desc:  "ol moves into the previous li",
			input: "<ul><li>A</li><ol><li>B</li></ol></ul>",
			expected: `
├─body
│ ├─ul
│ │ ├─li
│ │ │ ├─#text "A"
│ │ │ ├─ol
│ │ │ │ ├─li
│ │ │ │ │ ├─#text "B"
			`,
		},
		{
			desc:  "no existing li",
			input: "<ul><span>A</span><span>B</span></ul>",
			expected: `
├─body
│ ├─ul
│ │ ├─li
│ │ │ ├─span
│ │ │ │ ├─#text "A"
│ │ │ ├─span
│ │ │ │ ├─#text "B"
			`,
		},
		{
			desc: "basic moved list",
			input: `
<ol>
	<li>One</li>
	<li>Two</li>
	<ol>
		<li>Two point one</li>
		<li>Two point two</li>
	</ol>
</ol>
			`,
			expected: `
├─body
│ ├─ol
│ │ ├─#text "\n\t"
│ │ ├─li
│ │ │ ├─#text "One"
│ │ ├─#text "\n\t"
│ │ ├─li
│ │ │ ├─#text "Two"
│ │ │ ├─ol
│ │ │ │ ├─#text "\n\t\t"
│ │ │ │ ├─li
│ │ │ │ │ ├─#text "Two point one"
│ │ │ │ ├─#text "\n\t\t"
│ │ │ │ ├─li
│ │ │ │ │ ├─#text "Two point two"
│ │ │ │ ├─#text "\n\t"
│ │ ├─#text "\n\t"
│ │ ├─#text "\n"
			`,
		},
	}
	for _, run := range runs {
		t.Run(run.desc, func(t *testing.T) {
			doc := tester.Parse(t, run.input, "")

			MoveListItems(context.TODO(), doc)

			tester.ExpectRepresentation(t, doc, "output", run.expected)
		})
	}
}