Skip to content

Commit

Permalink
Test File.Split and use -update flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nochso committed Nov 12, 2016
1 parent b6bb7b1 commit 8e29f89
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Security invites users to upgrade in case of vulnerabilities.
[Unreleased]
------------

### Added
- `func (f File) Split(sep string) []string`
- Split the file into a string slice using separator sep.


[0.2.0] - 2016-11-07
--------------------
Expand All @@ -41,5 +45,5 @@ Security invites users to upgrade in case of vulnerabilities.
- Initial public release under the MIT license.


[Unreleased]: https://github.com/nochso/golden/compare/0.1.0...HEAD
[Unreleased]: https://github.com/nochso/golden/compare/0.2.0...HEAD
[0.2.0]: https://github.com/nochso/golden/compare/0.1.0...0.2.0
20 changes: 19 additions & 1 deletion golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ package golden

import (
"bytes"
"flag"
"io/ioutil"
"os"
"testing"

"github.com/k0kubun/pp"
)

var update = flag.Bool("update", false, "update golden files")

func TestFile(t *testing.T) {
c := NewCase(t, "test-fixtures/in.txt")
exp := []byte("abc")
Expand Down Expand Up @@ -37,17 +42,30 @@ func TestFile_Update(t *testing.T) {
func TestCase_Diff(t *testing.T) {
c := NewCase(t, "test-fixtures/in.txt")
act := bytes.Repeat(c.In.Bytes(), 2)
if *update {
c.Out.Update(act)
}
c.Diff(string(act))
}

func TestDirSlice(t *testing.T) {
cases := DirSlice(t, "test-fixtures")
expLen := 1
expLen := 2
if expLen != len(cases) {
t.Errorf("expected %d case; got %d", expLen, len(cases))
}
}

func TestFile_Split(t *testing.T) {
c := NewCase(t, "test-fixtures/split.txt")
s := c.In.Split("===")
pp.ColoringEnabled = false
if *update {
c.Out.Update([]byte(pp.Sprint(s)))
}
c.Diff(pp.Sprint(s))
}

func bEqual(t *testing.T, exp, act []byte) {
if !bytes.Equal(exp, act) {
t.Fatal(diff(t, exp, act))
Expand Down
16 changes: 16 additions & 0 deletions test-fixtures/split.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
this part will not have a new line
===
this one will have a trailing one

===

this one has a leading one
===

this one has both

===


two new lines each

7 changes: 7 additions & 0 deletions test-fixtures/split.txt.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[]string{
"this part will not have a new line",
"this one will have a trailing one\n",
"\nthis one has a leading one",
"\nthis one has both\n",
"\n\ntwo new lines each\n\n",
}

0 comments on commit 8e29f89

Please sign in to comment.