-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand/collapse sections, filling out some tests
- Loading branch information
Kyle Banks
committed
Jun 12, 2018
1 parent
b509071
commit beba17d
Showing
15 changed files
with
445 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ install: | |
.PHONY: install | ||
|
||
test: | ||
@go vet ./... | ||
@go test -cover ./... | ||
.PHONY: test | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
package debug | ||
|
||
import "os" | ||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
) | ||
|
||
var Enabled = os.Getenv("KURZ_DEBUG") == "true" | ||
var Enabled = false | ||
var Out io.Writer = os.Stdout | ||
|
||
// Log outputs a debug log message (with formatting) if | ||
// the Enabled flag is set to true. | ||
func Log(msg string, a ...interface{}) { | ||
if !Enabled { | ||
return | ||
} | ||
|
||
if !strings.HasSuffix(msg, "\n") { | ||
msg += "\n" | ||
} | ||
fmt.Fprintf(Out, msg, a...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package debug | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestLog(t *testing.T) { | ||
|
||
// Disabled | ||
output := bytes.Buffer{} | ||
Out = &output | ||
Enabled = false | ||
Log("Message") | ||
if len(output.String()) > 0 { | ||
t.Errorf("Unexpected logging when disabled, expected='', got=%v", output.String()) | ||
} | ||
|
||
// Enabled | ||
output = bytes.Buffer{} | ||
Out = &output | ||
Enabled = true | ||
Log("Message") | ||
if output.String() != "Message\n" { | ||
t.Errorf("Unexpected log, expected=Message\n, got=%v", output.String()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package doc | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"io" | ||
"io/ioutil" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
type mockResolver struct { | ||
resolveFn func(string) (io.ReadCloser, error) | ||
} | ||
|
||
func (m mockResolver) Resolve(path string) (io.ReadCloser, error) { | ||
return m.resolveFn(path) | ||
} | ||
|
||
type mockParser struct { | ||
parseFn func(io.Reader) (Document, error) | ||
} | ||
|
||
func (m mockParser) Parse(r io.Reader) (Document, error) { | ||
return m.parseFn(r) | ||
} | ||
|
||
func TestNewDocument(t *testing.T) { | ||
expectPath := "/path/to/file" | ||
expectContent := "CONTENT" | ||
var expectDoc Document | ||
|
||
r := mockResolver{ | ||
resolveFn: func(path string) (io.ReadCloser, error) { | ||
if path != expectPath { | ||
t.Fatalf("Unexpected path, expected=%v, got=%v", expectPath, path) | ||
} | ||
|
||
b := bytes.NewBufferString(expectContent) | ||
return ioutil.NopCloser(b), nil | ||
}, | ||
} | ||
p := mockParser{ | ||
parseFn: func(r io.Reader) (Document, error) { | ||
got, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if string(got) != expectContent { | ||
t.Fatalf("Unexpected content, expected=%v, got=%s", expectContent, got) | ||
} | ||
|
||
return expectDoc, nil | ||
}, | ||
} | ||
|
||
d, err := NewDocument(expectPath, r, p) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !reflect.DeepEqual(d, expectDoc) { | ||
t.Fatalf("Unexpected document, expected=%v, got=%v", expectDoc, d) | ||
} | ||
} | ||
|
||
func TestNewDocument_errors(t *testing.T) { | ||
// Resolver Error | ||
{ | ||
expectErr := errors.New("resolver error") | ||
r := mockResolver{ | ||
resolveFn: func(path string) (io.ReadCloser, error) { | ||
return nil, expectErr | ||
}, | ||
} | ||
|
||
if _, err := NewDocument("", r, nil); err != expectErr { | ||
t.Fatalf("Unexpected error, expected=%v, got=%v", expectErr, err) | ||
} | ||
} | ||
|
||
// Parser Error | ||
{ | ||
expectErr := errors.New("parser error") | ||
r := mockResolver{ | ||
resolveFn: func(path string) (io.ReadCloser, error) { | ||
return ioutil.NopCloser(&bytes.Buffer{}), nil | ||
}, | ||
} | ||
p := mockParser{ | ||
parseFn: func(r io.Reader) (Document, error) { | ||
return Document{}, expectErr | ||
}, | ||
} | ||
|
||
if _, err := NewDocument("", r, p); err != expectErr { | ||
t.Fatalf("Unexpected error, expected=%v, got=%v", expectErr, err) | ||
} | ||
} | ||
} | ||
|
||
func TestNopStyler_Style(t *testing.T) { | ||
var ns NopStyler | ||
styles := []Style{Bold, Italic, Underline, Code} | ||
for _, s := range styles { | ||
got := ns.Style("string", s) | ||
if got != "string" { | ||
t.Errorf("Unexpected output for style %v, expected=string, got=%v", s, got) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ var ( | |
{" ⬅ / ESC ", "Go Back"}, | ||
{"⬆ ", "Up"}, | ||
{"⬇ ", "Down"}, | ||
{" SPACE ", "Collapse"}, | ||
} | ||
) | ||
|
||
|
Oops, something went wrong.