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

Side by Side 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: check status 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package indented
6
7 import (
8 "bytes"
9 "fmt"
10 "testing"
11
12 . "github.com/smartystreets/goconvey/convey"
13 )
14
15 func TestWriter(t *testing.T) {
16 Convey("Writer", t, func() {
17 var buf bytes.Buffer
18 w := &Writer{Writer: &buf}
19
20 print := func(s string) {
21 fmt.Fprint(w, s)
22 }
23 expect := func(s string) {
24 So(buf.String(), ShouldEqual, s)
25 }
26
27 Convey("Without indentation", func() {
28 Convey("Print once", func() {
29 Convey("Line", func() {
30 print("abc\n")
31 expect("abc\n")
32 })
33 Convey("Unfinished line", func() {
34 print("abc")
35 expect("abc")
36 })
37 Convey("Blank line", func() {
38 print("\n")
39 expect("\n")
40 })
41 Convey("Line and empty", func() {
42 print("abc\nabc\n")
43 print("")
44 expect("abc\nabc\n")
45 })
46 Convey("Two lines", func() {
47 print("abc\nabc\n")
48 expect("abc\nabc\n")
49 })
50 Convey("Line and unfinished", func() {
51 print("abc\nabc")
52 expect("abc\nabc")
53 })
54 })
55 Convey("Print twice", func() {
56 Convey("Line", func() {
57 print("abc\n")
58 print("def\n")
59 expect("abc\ndef\n")
60 })
61 Convey("Unfinished line", func() {
62 print("abc")
63 print("def")
64 expect("abcdef")
65 })
66 Convey("Blank line", func() {
67 print("\n")
68 print("\n")
69 expect("\n\n")
70 })
71 Convey("Line and empty", func() {
72 print("abc\nabc\n")
73 print("")
74 print("def\ndef\n")
75 print("")
76 expect("abc\nabc\ndef\ndef\n")
77 })
78 Convey("Two lines", func() {
79 print("abc\nabc\n")
80 print("def\ndef\n")
81 expect("abc\nabc\ndef\ndef\n")
82 })
83 Convey("Line and unfinished", func() {
84 print("abc\nabc")
85 print("def\ndef")
86 expect("abc\nabcdef\ndef")
87 })
88 })
89 })
90
91 Convey("With indentation", func() {
92 w.Level++
93
94 Convey("Print once", func() {
95 Convey("Line", func() {
96 print("abc\n")
97 expect("\tabc\n")
98 })
99 Convey("Unfinished line", func() {
100 print("abc")
101 expect("\tabc")
102 })
103 Convey("Blank line", func() {
104 print("\n")
105 expect("\n")
106 })
107 Convey("Line and empty", func() {
108 print("abc\nabc\n")
109 print("")
110 expect("\tabc\n\tabc\n")
111 })
112 Convey("Two lines", func() {
113 print("abc\nabc\n")
114 expect("\tabc\n\tabc\n")
115 })
116 Convey("Line and unfinished", func() {
117 print("abc\nabc")
118 expect("\tabc\n\tabc")
119 })
120 })
121 Convey("Print twice", func() {
122 Convey("Line", func() {
123 print("abc\n")
124 print("def\n")
125 expect("\tabc\n\tdef\n")
126 })
127 Convey("Unfinished line", func() {
128 print("abc")
129 print("def")
130 expect("\tabcdef")
131 })
132 Convey("Blank line", func() {
133 print("\n")
134 print("\n")
135 expect("\n\n")
136 })
137 Convey("Line and empty", func() {
138 print("abc\nabc\n")
139 print("")
140 print("def\ndef\n")
141 print("")
142 expect("\tabc\n\tabc\n\tdef\n\tdef\n")
143 })
144 Convey("Two lines", func() {
145 print("abc\nabc\n")
146 print("def\ndef\n")
147 expect("\tabc\n\tabc\n\tdef\n\tdef\n")
148 })
149 Convey("Line and unfinished", func() {
150 print("abc\nabc")
151 print("def\ndef")
152 expect("\tabc\n\tabcdef\n\tdef")
153 })
154 })
155 })
156 })
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698