-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
568 additions
and
401 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
fmt: | ||
go fmt | ||
|
||
test: | ||
go test ./... -race -v | ||
|
||
cyclo: | ||
gocyclo . | ||
|
||
all: fmt test cyclo |
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,110 @@ | ||
package gtree | ||
|
||
import ( | ||
"bytes" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestExecute_encodeJSON(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
in in | ||
out out | ||
}{ | ||
{ | ||
name: "case 1(tab spaces & multi root & output json)", | ||
in: in{ | ||
input: strings.NewReader(strings.TrimSpace(` | ||
- a | ||
- i | ||
- u | ||
- k | ||
- kk | ||
- t | ||
- e | ||
- o | ||
- g | ||
- a | ||
- i | ||
- u | ||
- k | ||
- kk | ||
- t | ||
- e | ||
- o | ||
- g`)), | ||
optFns: []OptFn{EncodeJSON()}, | ||
}, | ||
out: out{ | ||
output: strings.TrimPrefix(` | ||
{"value":"a","children":[{"value":"i","children":[{"value":"u","children":[{"value":"k","children":null},{"value":"kk","children":null}]},{"value":"t","children":null}]},{"value":"e","children":[{"value":"o","children":null}]},{"value":"g","children":null}]} | ||
{"value":"a","children":[{"value":"i","children":[{"value":"u","children":[{"value":"k","children":null},{"value":"kk","children":null}]},{"value":"t","children":null}]},{"value":"e","children":[{"value":"o","children":null}]},{"value":"g","children":null}]} | ||
`, "\n"), | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
name: "case 2(indent 2spaces & output json)", | ||
in: in{ | ||
input: strings.NewReader(strings.TrimSpace(` | ||
- a | ||
- i | ||
- u | ||
- k | ||
- kk | ||
- t | ||
- e | ||
- o | ||
- g`)), | ||
optFns: []OptFn{IndentTwoSpaces(), EncodeJSON()}, | ||
}, | ||
out: out{ | ||
output: strings.TrimPrefix(` | ||
{"value":"a","children":[{"value":"i","children":[{"value":"u","children":[{"value":"k","children":null},{"value":"kk","children":null}]},{"value":"t","children":null}]},{"value":"e","children":[{"value":"o","children":null}]},{"value":"g","children":null}]} | ||
`, "\n"), | ||
err: nil, | ||
}, | ||
}, | ||
{ | ||
name: "case 3(indent 4spaces & output json)", | ||
in: in{ | ||
input: strings.NewReader(strings.TrimSpace(` | ||
- a | ||
- i | ||
- u | ||
- k | ||
- kk | ||
- t | ||
- e | ||
- o | ||
- g`)), | ||
optFns: []OptFn{IndentFourSpaces(), EncodeJSON()}, | ||
}, | ||
out: out{ | ||
output: strings.TrimPrefix(` | ||
{"value":"a","children":[{"value":"i","children":[{"value":"u","children":[{"value":"k","children":null},{"value":"kk","children":null}]},{"value":"t","children":null}]},{"value":"e","children":[{"value":"o","children":null}]},{"value":"g","children":null}]} | ||
`, "\n"), | ||
err: nil, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
out := &bytes.Buffer{} | ||
gotErr := Execute(out, tt.in.input, tt.in.optFns...) | ||
gotOutput := out.String() | ||
|
||
if gotOutput != tt.out.output { | ||
t.Errorf("\ngot: \n%s\nwant: \n%s", gotOutput, tt.out.output) | ||
} | ||
if gotErr != tt.out.err { | ||
t.Errorf("\ngotErr: \n%v\nwantErr: \n%v", gotErr, tt.out.err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.