github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/util/format/format_test.go (about) 1 // Copyright 2015 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package format 15 16 import ( 17 "bytes" 18 "io/ioutil" 19 "testing" 20 21 . "github.com/insionng/yougam/libraries/pingcap/check" 22 "github.com/insionng/yougam/libraries/pingcap/tidb/util/testleak" 23 ) 24 25 func TestT(t *testing.T) { 26 TestingT(t) 27 } 28 29 var _ = Suite(&testFormatSuite{}) 30 31 type testFormatSuite struct { 32 } 33 34 func checkFormat(c *C, f Formatter, buf *bytes.Buffer, str, expect string) { 35 _, err := f.Format(str, 3) 36 c.Assert(err, IsNil) 37 b, err := ioutil.ReadAll(buf) 38 c.Assert(err, IsNil) 39 c.Assert(string(b), Equals, expect) 40 } 41 42 func (s *testFormatSuite) TestFormat(c *C) { 43 defer testleak.AfterTest(c)() 44 str := "abc%d%%e%i\nx\ny\n%uz\n" 45 buf := &bytes.Buffer{} 46 f := IndentFormatter(buf, "\t") 47 expect := `abc3%e 48 x 49 y 50 z 51 ` 52 checkFormat(c, f, buf, str, expect) 53 54 str = "abc%d%%e%i\nx\ny\n%uz\n%i\n" 55 buf = &bytes.Buffer{} 56 f = FlatFormatter(buf) 57 expect = "abc3%e x y z\n " 58 checkFormat(c, f, buf, str, expect) 59 }