Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Unified Diff: common/indented/writer_test.go

Issue 1587323003: client/cmd/rpc: RPC CLI (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@discovery
Patch Set: rebased Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « common/indented/writer.go ('k') | common/proto/google/descriptor/generate.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/indented/writer_test.go
diff --git a/common/indented/writer_test.go b/common/indented/writer_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..f974d8e7715ae4cba18a7dc95758795de3757269
--- /dev/null
+++ b/common/indented/writer_test.go
@@ -0,0 +1,157 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package indented
+
+import (
+ "bytes"
+ "fmt"
+ "testing"
+
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestWriter(t *testing.T) {
+ Convey("Writer", t, func() {
+ var buf bytes.Buffer
+ w := &Writer{Writer: &buf}
+
+ print := func(s string) {
+ fmt.Fprint(w, s)
+ }
+ expect := func(s string) {
+ So(buf.String(), ShouldEqual, s)
+ }
+
+ Convey("Without indentation", func() {
+ Convey("Print once", func() {
+ Convey("Line", func() {
+ print("abc\n")
+ expect("abc\n")
+ })
+ Convey("Unfinished line", func() {
+ print("abc")
+ expect("abc")
+ })
+ Convey("Blank line", func() {
+ print("\n")
+ expect("\n")
+ })
+ Convey("Line and empty", func() {
+ print("abc\nabc\n")
+ print("")
+ expect("abc\nabc\n")
+ })
+ Convey("Two lines", func() {
+ print("abc\nabc\n")
+ expect("abc\nabc\n")
+ })
+ Convey("Line and unfinished", func() {
+ print("abc\nabc")
+ expect("abc\nabc")
+ })
+ })
+ Convey("Print twice", func() {
+ Convey("Line", func() {
+ print("abc\n")
+ print("def\n")
+ expect("abc\ndef\n")
+ })
+ Convey("Unfinished line", func() {
+ print("abc")
+ print("def")
+ expect("abcdef")
+ })
+ Convey("Blank line", func() {
+ print("\n")
+ print("\n")
+ expect("\n\n")
+ })
+ Convey("Line and empty", func() {
+ print("abc\nabc\n")
+ print("")
+ print("def\ndef\n")
+ print("")
+ expect("abc\nabc\ndef\ndef\n")
+ })
+ Convey("Two lines", func() {
+ print("abc\nabc\n")
+ print("def\ndef\n")
+ expect("abc\nabc\ndef\ndef\n")
+ })
+ Convey("Line and unfinished", func() {
+ print("abc\nabc")
+ print("def\ndef")
+ expect("abc\nabcdef\ndef")
+ })
+ })
+ })
+
+ Convey("With indentation", func() {
+ w.Level++
+
+ Convey("Print once", func() {
+ Convey("Line", func() {
+ print("abc\n")
+ expect("\tabc\n")
+ })
+ Convey("Unfinished line", func() {
+ print("abc")
+ expect("\tabc")
+ })
+ Convey("Blank line", func() {
+ print("\n")
+ expect("\n")
+ })
+ Convey("Line and empty", func() {
+ print("abc\nabc\n")
+ print("")
+ expect("\tabc\n\tabc\n")
+ })
+ Convey("Two lines", func() {
+ print("abc\nabc\n")
+ expect("\tabc\n\tabc\n")
+ })
+ Convey("Line and unfinished", func() {
+ print("abc\nabc")
+ expect("\tabc\n\tabc")
+ })
+ })
+ Convey("Print twice", func() {
+ Convey("Line", func() {
+ print("abc\n")
+ print("def\n")
+ expect("\tabc\n\tdef\n")
+ })
+ Convey("Unfinished line", func() {
+ print("abc")
+ print("def")
+ expect("\tabcdef")
+ })
+ Convey("Blank line", func() {
+ print("\n")
+ print("\n")
+ expect("\n\n")
+ })
+ Convey("Line and empty", func() {
+ print("abc\nabc\n")
+ print("")
+ print("def\ndef\n")
+ print("")
+ expect("\tabc\n\tabc\n\tdef\n\tdef\n")
+ })
+ Convey("Two lines", func() {
+ print("abc\nabc\n")
+ print("def\ndef\n")
+ expect("\tabc\n\tabc\n\tdef\n\tdef\n")
+ })
+ Convey("Line and unfinished", func() {
+ print("abc\nabc")
+ print("def\ndef")
+ expect("\tabc\n\tabcdef\n\tdef")
+ })
+ })
+ })
+ })
+}
« no previous file with comments | « common/indented/writer.go ('k') | common/proto/google/descriptor/generate.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698