Skip to content

Commit

Permalink
完善单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
FishGoddess committed Feb 23, 2024
1 parent 5fe928d commit bbb95e2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion FUTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### v1.8.x

* [ ] 融合 Go 官方设计的正式版本
* [ ] 进一步提高单元测试覆盖率到 80%
* [ ] 提高单元测试覆盖率到 90%

### v1.5.x
Expand All @@ -21,7 +22,6 @@
* [x] 增加一个高可读性且高性能的 handler 实现
* [x] TapeHandler 转义处理
* [x] 提高单元测试覆盖率到 70%
* [ ] 进一步提高单元测试覆盖率到 80%

### v1.2.x

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: test bench benchfile fmt
.PHONY: test bench fmt

all: test bench

Expand Down
2 changes: 2 additions & 0 deletions extension/config/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func TestParseTimeDuration(t *testing.T) {
{name: "12s", s: "12s", want: 12 * time.Second, wantErr: false},
{name: "3m", s: "3m", want: 3 * time.Minute, wantErr: false},
{name: "24h", s: "24h", want: 24 * time.Hour, wantErr: false},
{name: "24h50m12s", s: "24h50m12s", want: 24*time.Hour + 50*time.Minute + 12*time.Second, wantErr: false},
{name: "7d", s: "7d", want: 7 * 24 * time.Hour, wantErr: false},
{name: "90D", s: "90D", want: 90 * 24 * time.Hour, wantErr: false},
{name: "''", s: "", want: 0, wantErr: true},
{name: "14", s: "14", want: 0, wantErr: true},
}
Expand Down
2 changes: 1 addition & 1 deletion handler/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/FishGoddess/logit/defaults"
)

// go test -v -cover -count=1 -test.cpu=1 -run=^TestNewBuffer$
// go test -v -cover -count=1 -test.cpu=1 -run=^TestBufferPool$
func TestBufferPool(t *testing.T) {
for i := 0; i < 100; i++ {
bs := make([]byte, 0, 2*defaults.MaxBufferSize)
Expand Down
8 changes: 4 additions & 4 deletions handler/escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import "testing"

// go test -v -cover -count=1 -test.cpu=1 -run=^TestAppendEscapedByte$
func TestAppendEscapedByte(t *testing.T) {
testcases := []byte{'a', '0', '\n', '\t', '\\', '\b', '\f', '\r', '"'}
want := `a0\n\t\\b\f\r"`
testcases := []byte{'a', '0', '\n', '\t', '\\', '\b', '\f', '\r', '"', 15, 31}
want := `a0\n\t\\b\f\r"\u000f\u001f`

buffer := make([]byte, 0, 16)
for _, b := range testcases {
Expand All @@ -33,8 +33,8 @@ func TestAppendEscapedByte(t *testing.T) {

// go test -v -cover -count=1 -test.cpu=1 -run=^TestAppendEscapedString$
func TestAppendEscapedString(t *testing.T) {
testcases := []string{"a0国\n\t\\b\f\r\""}
want := `a0国\n\t\b\f\r"`
testcases := []string{"a0国\n\t\\\b\f\r\"\\b" + string([]byte{15}) + string([]byte{31})}
want := `a0国\n\t\\b\f\r"\b\u000f\u001f`

buffer := make([]byte, 0, 16)
for _, str := range testcases {
Expand Down

0 comments on commit bbb95e2

Please sign in to comment.