Skip to content

Commit 139c915

Browse files
committed
Add test TestNewGHDocWithDebug
1 parent 03cfbb1 commit 139c915

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ghdoc.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,28 @@ type GHDoc struct {
3939
Indent int
4040
Debug bool
4141
html string
42+
logger *log.Logger
4243
}
4344

4445
// NewGHDoc create GHDoc
4546
func NewGHDoc(Path string, AbsPaths bool, StartDepth int, Depth int, Escape bool, Token string, Indent int, Debug bool) *GHDoc {
46-
return &GHDoc{Path, AbsPaths, StartDepth, Depth, Escape, Token, Indent, Debug, ""}
47+
return &GHDoc{
48+
Path: Path,
49+
AbsPaths: AbsPaths,
50+
StartDepth: StartDepth,
51+
Depth: Depth,
52+
Escape: Escape,
53+
GhToken: Token,
54+
Indent: Indent,
55+
Debug: Debug,
56+
html: "",
57+
logger: log.New(os.Stderr, "", log.LstdFlags),
58+
}
4759
}
4860

4961
func (doc *GHDoc) d(msg string) {
5062
if doc.Debug {
51-
log.Println(msg)
63+
doc.logger.Println(msg)
5264
}
5365
}
5466

ghdoc_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ghtoc
22

33
import (
44
"bytes"
5+
"log"
56
"testing"
67
)
78

@@ -362,5 +363,18 @@ func TestGHToc_Print(t *testing.T) {
362363
}
363364

364365
func TestNewGHDocWithDebug(t *testing.T) {
366+
noMatterN := 1
367+
noMatterS := "test"
368+
noMatterB := false
369+
var got bytes.Buffer
370+
371+
doc := NewGHDoc(noMatterS, noMatterB, noMatterN, noMatterN,
372+
noMatterB, noMatterS, noMatterN, true)
373+
doc.logger = log.New(&got, "", 0)
365374

375+
want := "test"
376+
doc.d(want)
377+
if got.String() != want+"\n" {
378+
t.Error("\nGot :", got.String(), "\nWant:", want)
379+
}
366380
}

0 commit comments

Comments
 (0)