Skip to content

Commit

Permalink
去除一点点依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong committed Nov 3, 2023
1 parent 8168132 commit 8998612
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions parser_res_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httparser

import (
"bytes"
"reflect"
"testing"

Expand Down Expand Up @@ -181,10 +182,21 @@ func Test_ParserResponse_Content_Length_Body(t *testing.T) {
}
}

assert.Equal(t, rcvBuf, append(rsp[1], rsp[2]...))
assert.Equal(t, p.Major, uint8(1))
assert.Equal(t, p.Minor, uint8(1))
assert.True(t, messageBegin)
if !bytes.Equal(rcvBuf, append(rsp[1], rsp[2]...)) {
t.Errorf("rcvBuf is %v, expect %v", rcvBuf, append(rsp[1], rsp[2]...))
}

if p.Major != 1 {
t.Errorf("major is %d, expect 1", p.Major)
}

if p.Minor != 1 {
t.Errorf("minor is %d, expect 1", p.Minor)
}

if !messageBegin {
t.Error("message begin is false, expect true")
}
}

func Test_ParserResponse_Chunked(t *testing.T) {
Expand Down Expand Up @@ -232,10 +244,26 @@ func Test_ParserResponse_Chunked(t *testing.T) {
sentTotal += len(buf)
}

assert.Equal(t, rcvBuf, []byte("MozillaDeveloperNetworknew year"))
assert.Equal(t, p.Major, uint8(1))
assert.Equal(t, p.Minor, uint8(1))
assert.True(t, messageBegin)
assert.Equal(t, sentTotal, parserTotal)
assert.True(t, p.EOF())
if !bytes.Equal(rcvBuf, []byte("MozillaDeveloperNetworknew year")) {
t.Errorf("rcvBuf is %v, expect %v", rcvBuf, []byte("MozillaDeveloperNetworknew year"))
}

if p.Major != 1 {
t.Errorf("major is %d, expect 1", p.Major)
}

if p.Minor != 1 {
t.Errorf("minor is %d, expect 1", p.Minor)
}
if !messageBegin {
t.Error("message begin is false, expect true")
}

if sentTotal != parserTotal {
t.Errorf("sentTotal is %d, parserTotal is %d", sentTotal, parserTotal)
}

if !p.EOF() {
t.Error("EOF is true, expect false")
}
}

0 comments on commit 8998612

Please sign in to comment.