-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencode_test.go
59 lines (49 loc) · 937 Bytes
/
encode_test.go
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
package mdcodec
import (
"fmt"
"testing"
)
func ExampleMarshal() {
type Person struct {
Name string `md:"title"`
Age int
Address struct {
Street string
City string
}
}
p := Person{}
p.Name = "John Doe"
p.Age = 30
p.Address.Street = "123 Maple St."
p.Address.City = "Springfield"
md, _ := Marshal(p)
fmt.Println(md)
// Output:
// # John Doe (Person)
//
// - **Age**: 30
// - **Address**:
// - **Street**: 123 Maple St.
// - **City**: Springfield
}
func TestMarshal(t *testing.T) {
p := Person{}
p.Name = "John Doe"
p.Age = 30
p.Address.Street = "123 Maple St."
p.Address.City = "Springfield"
md, err := Marshal(p)
if err != nil {
t.Fatalf("Error during Marshal: %v", err)
}
expected := `# John Doe (Person)
- **Age**: 30
- **Address**:
- **Street**: 123 Maple St.
- **City**: Springfield
`
if md != expected {
t.Errorf("Expected:\n%s\nGot:\n%s", expected, md)
}
}