@@ -1530,14 +1530,16 @@ func Test_Request_MaxRedirects(t *testing.T) {
1530
1530
func Test_SetValWithStruct (t * testing.T ) {
1531
1531
t .Parallel ()
1532
1532
1533
- // test SetValWithStruct vai QueryParam struct.
1533
+ // test SetValWithStruct via QueryParam struct.
1534
1534
type args struct {
1535
1535
TString string
1536
1536
TSlice []string
1537
1537
TIntSlice []int `param:"int_slice"`
1538
1538
unexport int
1539
1539
TInt int
1540
+ TUint uint
1540
1541
TFloat float64
1542
+ TComplex complex128
1541
1543
TBool bool
1542
1544
}
1543
1545
@@ -1550,18 +1552,22 @@ func Test_SetValWithStruct(t *testing.T) {
1550
1552
SetValWithStruct (p , "param" , args {
1551
1553
unexport : 5 ,
1552
1554
TInt : 5 ,
1555
+ TUint : 5 ,
1553
1556
TString : "string" ,
1554
1557
TFloat : 3.1 ,
1558
+ TComplex : 3 + 4i ,
1555
1559
TBool : false ,
1556
1560
TSlice : []string {"foo" , "bar" },
1557
- TIntSlice : []int {1 , 2 },
1561
+ TIntSlice : []int {0 , 1 , 2 },
1558
1562
})
1559
1563
1560
1564
require .Equal (t , "" , string (p .Peek ("unexport" )))
1561
1565
require .Equal (t , []byte ("5" ), p .Peek ("TInt" ))
1566
+ require .Equal (t , []byte ("5" ), p .Peek ("TUint" ))
1562
1567
require .Equal (t , []byte ("string" ), p .Peek ("TString" ))
1563
1568
require .Equal (t , []byte ("3.1" ), p .Peek ("TFloat" ))
1564
- require .Equal (t , "" , string (p .Peek ("TBool" )))
1569
+ require .Equal (t , []byte ("(3+4i)" ), p .Peek ("TComplex" ))
1570
+ require .Equal (t , []byte ("false" ), p .Peek ("TBool" ))
1565
1571
require .True (t , func () bool {
1566
1572
for _ , v := range p .PeekMulti ("TSlice" ) {
1567
1573
if string (v ) == "foo" {
@@ -1580,6 +1586,15 @@ func Test_SetValWithStruct(t *testing.T) {
1580
1586
return false
1581
1587
}())
1582
1588
1589
+ require .True (t , func () bool {
1590
+ for _ , v := range p .PeekMulti ("int_slice" ) {
1591
+ if string (v ) == "0" {
1592
+ return true
1593
+ }
1594
+ }
1595
+ return false
1596
+ }())
1597
+
1583
1598
require .True (t , func () bool {
1584
1599
for _ , v := range p .PeekMulti ("int_slice" ) {
1585
1600
if string (v ) == "1" {
@@ -1655,24 +1670,6 @@ func Test_SetValWithStruct(t *testing.T) {
1655
1670
}())
1656
1671
})
1657
1672
1658
- t .Run ("the zero val should be ignore" , func (t * testing.T ) {
1659
- t .Parallel ()
1660
- p := & QueryParam {
1661
- Args : fasthttp .AcquireArgs (),
1662
- }
1663
- SetValWithStruct (p , "param" , & args {
1664
- TInt : 0 ,
1665
- TString : "" ,
1666
- TFloat : 0.0 ,
1667
- })
1668
-
1669
- require .Equal (t , "" , string (p .Peek ("TInt" )))
1670
- require .Equal (t , "" , string (p .Peek ("TString" )))
1671
- require .Equal (t , "" , string (p .Peek ("TFloat" )))
1672
- require .Empty (t , p .PeekMulti ("TSlice" ))
1673
- require .Empty (t , p .PeekMulti ("int_slice" ))
1674
- })
1675
-
1676
1673
t .Run ("error type should ignore" , func (t * testing.T ) {
1677
1674
t .Parallel ()
1678
1675
p := & QueryParam {
@@ -1684,14 +1681,16 @@ func Test_SetValWithStruct(t *testing.T) {
1684
1681
}
1685
1682
1686
1683
func Benchmark_SetValWithStruct (b * testing.B ) {
1687
- // test SetValWithStruct vai QueryParam struct.
1684
+ // test SetValWithStruct via QueryParam struct.
1688
1685
type args struct {
1689
1686
TString string
1690
1687
TSlice []string
1691
1688
TIntSlice []int `param:"int_slice"`
1692
1689
unexport int
1693
1690
TInt int
1691
+ TUint uint
1694
1692
TFloat float64
1693
+ TComplex complex128
1695
1694
TBool bool
1696
1695
}
1697
1696
@@ -1707,19 +1706,23 @@ func Benchmark_SetValWithStruct(b *testing.B) {
1707
1706
SetValWithStruct (p , "param" , args {
1708
1707
unexport : 5 ,
1709
1708
TInt : 5 ,
1709
+ TUint : 5 ,
1710
1710
TString : "string" ,
1711
1711
TFloat : 3.1 ,
1712
+ TComplex : 3 + 4i ,
1712
1713
TBool : false ,
1713
1714
TSlice : []string {"foo" , "bar" },
1714
- TIntSlice : []int {1 , 2 },
1715
+ TIntSlice : []int {0 , 1 , 2 },
1715
1716
})
1716
1717
}
1717
1718
1718
1719
require .Equal (b , "" , string (p .Peek ("unexport" )))
1719
1720
require .Equal (b , []byte ("5" ), p .Peek ("TInt" ))
1721
+ require .Equal (b , []byte ("5" ), p .Peek ("TUint" ))
1720
1722
require .Equal (b , []byte ("string" ), p .Peek ("TString" ))
1721
1723
require .Equal (b , []byte ("3.1" ), p .Peek ("TFloat" ))
1722
- require .Equal (b , "" , string (p .Peek ("TBool" )))
1724
+ require .Equal (b , []byte ("(3+4i)" ), p .Peek ("TComplex" ))
1725
+ require .Equal (b , []byte ("false" ), p .Peek ("TBool" ))
1723
1726
require .True (b , func () bool {
1724
1727
for _ , v := range p .PeekMulti ("TSlice" ) {
1725
1728
if string (v ) == "foo" {
@@ -1738,6 +1741,15 @@ func Benchmark_SetValWithStruct(b *testing.B) {
1738
1741
return false
1739
1742
}())
1740
1743
1744
+ require .True (b , func () bool {
1745
+ for _ , v := range p .PeekMulti ("int_slice" ) {
1746
+ if string (v ) == "0" {
1747
+ return true
1748
+ }
1749
+ }
1750
+ return false
1751
+ }())
1752
+
1741
1753
require .True (b , func () bool {
1742
1754
for _ , v := range p .PeekMulti ("int_slice" ) {
1743
1755
if string (v ) == "1" {
@@ -1817,29 +1829,6 @@ func Benchmark_SetValWithStruct(b *testing.B) {
1817
1829
}())
1818
1830
})
1819
1831
1820
- b .Run ("the zero val should be ignore" , func (b * testing.B ) {
1821
- p := & QueryParam {
1822
- Args : fasthttp .AcquireArgs (),
1823
- }
1824
-
1825
- b .ReportAllocs ()
1826
- b .StartTimer ()
1827
-
1828
- for i := 0 ; i < b .N ; i ++ {
1829
- SetValWithStruct (p , "param" , & args {
1830
- TInt : 0 ,
1831
- TString : "" ,
1832
- TFloat : 0.0 ,
1833
- })
1834
- }
1835
-
1836
- require .Empty (b , string (p .Peek ("TInt" )))
1837
- require .Empty (b , string (p .Peek ("TString" )))
1838
- require .Empty (b , string (p .Peek ("TFloat" )))
1839
- require .Empty (b , p .PeekMulti ("TSlice" ))
1840
- require .Empty (b , p .PeekMulti ("int_slice" ))
1841
- })
1842
-
1843
1832
b .Run ("error type should ignore" , func (b * testing.B ) {
1844
1833
p := & QueryParam {
1845
1834
Args : fasthttp .AcquireArgs (),
0 commit comments