-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable_test.go
More file actions
44 lines (41 loc) · 1.02 KB
/
table_test.go
File metadata and controls
44 lines (41 loc) · 1.02 KB
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
package markdownTable
import (
"testing"
)
func TestCreateMarkdownTable(t *testing.T) {
tests := []struct {
name string
head []string
body [][]string
expected string
}{
{
name: "Basic table",
head: []string{"ID", "Name", "Age"},
body: [][]string{
{"1", "John", "26"},
{"2", "Bob", "25"},
{"3", "Alice", "27"},
},
expected: "| ID | Name | Age |\n| -- | ----- | --- |\n| 1 | John | 26 |\n| 2 | Bob | 25 |\n| 3 | Alice | 27 |\n",
},
{
name: "Uneven rows",
head: []string{"ID", "Name", "Age"},
body: [][]string{
{"1", "John", "26"},
{"2", "Bob", "25"},
{"3", "Alice", "27", "ExtraColumn"},
},
expected: "| ID | Name | Age |\n| -- | ----- | --- |\n| 1 | John | 26 |\n| 2 | Bob | 25 |\n| 3 | Alice | 27 |\n",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := CreateMarkdownTable(tt.head, tt.body)
if got != tt.expected {
t.Errorf("CreateMarkdownTable() = %v, want %v", got, tt.expected)
}
})
}
}