Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed May 23, 2020
1 parent 9ee22f2 commit 4be9939
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 57 deletions.
1 change: 0 additions & 1 deletion bytes/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ func Replace(b []byte, src, dest []byte, n int) []byte {
}

// ---------------------------------------------------

1 change: 0 additions & 1 deletion bytes/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ func TestInsertAt(t *testing.T) {
t.Fatal("InsertAt failed:", ret)
}
}

87 changes: 43 additions & 44 deletions cmdline/cmdline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,52 +55,52 @@ func TestParse(t *testing.T) {

cases := []caseParse{
{
code: ";b",
cmd: []string{"b"},
code: ";b",
cmd: []string{"b"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: ";b;abc",
cmd: []string{"b"},
code: ";b;abc",
cmd: []string{"b"},
codeNext: "abc",
err: nil,
err: nil,
},
{
code: "a`b`\\c",
cmd: []string{"a[b]c"},
code: "a`b`\\c",
cmd: []string{"a[b]c"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "a`b`c 'c\\n`123`' \"c\\n\"",
cmd: []string{"a[b]c", "c\\n`123`", "cn"},
code: "a`b`c 'c\\n`123`' \"c\\n\"",
cmd: []string{"a[b]c", "c\\n`123`", "cn"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "auth qboxtest 'mac AccessKey SecretKey'",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
code: "auth qboxtest 'mac AccessKey SecretKey'",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "post http://rs.qiniu.com/delete/`base64 Bucket:Key`",
cmd: []string{"post", "http://rs.qiniu.com/delete/[base64 Bucket:Key]"},
code: "post http://rs.qiniu.com/delete/`base64 Bucket:Key`",
cmd: []string{"post", "http://rs.qiniu.com/delete/[base64 Bucket:Key]"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "post http://rs.qiniu.com/delete `base64 Bucket:Key`",
cmd: []string{"post", "http://rs.qiniu.com/delete", "[base64 Bucket:Key]"},
code: "post http://rs.qiniu.com/delete `base64 Bucket:Key`",
cmd: []string{"post", "http://rs.qiniu.com/delete", "[base64 Bucket:Key]"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "post http://rs.qiniu.com/delete/|base64 Bucket:Key|",
cmd: []string{"post", "http://rs.qiniu.com/delete/[base64 Bucket:Key]"},
code: "post http://rs.qiniu.com/delete/|base64 Bucket:Key|",
cmd: []string{"post", "http://rs.qiniu.com/delete/[base64 Bucket:Key]"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: `json '[
Expand All @@ -110,43 +110,43 @@ func TestParse(t *testing.T) {
{"code": 200}, {"code": 612}
]`},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "auth qboxtest ```\nmac AccessKey SecretKey```",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
code: "auth qboxtest ```\nmac AccessKey SecretKey```",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "auth qboxtest ===\nmac AccessKey SecretKey```",
cmd: []string{"auth", "qboxtest"},
code: "auth qboxtest ===\nmac AccessKey SecretKey```",
cmd: []string{"auth", "qboxtest"},
codeNext: "mac AccessKey SecretKey```",
err: "incomplete string, expect ===",
err: "incomplete string, expect ===",
},
{
code: "auth qboxtest ===\rmac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
code: "auth qboxtest ===\rmac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "auth qboxtest ===\n\rmac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "\rmac AccessKey SecretKey"},
code: "auth qboxtest ===\n\rmac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "\rmac AccessKey SecretKey"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "auth qboxtest ===\r\n\nmac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "\nmac AccessKey SecretKey"},
code: "auth qboxtest ===\r\n\nmac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "\nmac AccessKey SecretKey"},
codeNext: "",
err: "end of file",
err: "end of file",
},
{
code: "auth qboxtest ===mac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
code: "auth qboxtest ===mac AccessKey SecretKey===",
cmd: []string{"auth", "qboxtest", "mac AccessKey SecretKey"},
codeNext: "",
err: "end of file",
err: "end of file",
},
}

Expand All @@ -170,4 +170,3 @@ func TestParse(t *testing.T) {
}

// ---------------------------------------------------------------------------

7 changes: 3 additions & 4 deletions cmdline/escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package cmdline

const (
escTableBaseChar = '0'
escTableLen = ('z' - escTableBaseChar + 1)
escTableLen = ('z' - escTableBaseChar + 1)
)

var escTable = []byte{
Expand Down Expand Up @@ -88,11 +88,10 @@ var escTable = []byte{

func defaultEscape(c byte) string {

if c - escTableBaseChar < escTableLen {
c = escTable[c - escTableBaseChar]
if c-escTableBaseChar < escTableLen {
c = escTable[c-escTableBaseChar]
}
return string(c)
}

// ---------------------------------------------------------------------------

1 change: 0 additions & 1 deletion cmdline/escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ func checkEscapeChar(t *testing.T, i, exp int) {
}

// ---------------------------------------------------------------------------

10 changes: 5 additions & 5 deletions errors/error_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func Err(err error) error {
// --------------------------------------------------------------------

type ErrorInfo struct {
err error
why error
cmd []interface{}
pc uintptr
err error
why error
cmd []interface{}
pc uintptr
}

func shortFile(file string) string {
Expand All @@ -84,7 +84,7 @@ func Info(err error, cmd ...interface{}) *ErrorInfo {
}

func InfoEx(calldepth int, err error, cmd ...interface{}) *ErrorInfo {
pc, _, _, ok := runtime.Caller(calldepth+1)
pc, _, _, ok := runtime.Caller(calldepth + 1)
if !ok {
pc = 0
}
Expand Down
2 changes: 1 addition & 1 deletion jsonutil/json_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Unmarshal(data string, v interface{}) error {

sh := *(*reflect.StringHeader)(unsafe.Pointer(&data))
arr := (*[1<<30]byte)(unsafe.Pointer(sh.Data))
arr := (*[1 << 30]byte)(unsafe.Pointer(sh.Data))
return json.Unmarshal(arr[:sh.Len], v)
}

Expand Down

0 comments on commit 4be9939

Please sign in to comment.