nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: gavv/httpexpect
Pull request #114 (2022-05-26 07:28:48)

add a new func Number to String

gavv: Thanks!

Patch:
diff --git a/string.go b/string.go
index 6507e35..3617c86 100644
--- a/string.go
+++ b/string.go
@@ -3,6 +3,7 @@ package httpexpect
 import (
 	"net/http"
 	"regexp"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -55,7 +56,20 @@ func (s *String) Length() *Number {
 	return &Number{s.chain, float64(len(s.value))}
 }
 
-// DateTime parses date/time from string an returns a new DateTime object.
+// Number parses float from string and returns a new Number object.
+//
+// Example:
+//  str := NewString(t, "1234")
+//  str.Number()
+func (v *String) Number() *Number {
+	num, err := strconv.ParseFloat(v.value, 64)
+	if err != nil {
+		v.chain.fail(err.Error())
+	}
+	return &Number{v.chain, num}
+}
+
+// DateTime parses date/time from string and returns a new DateTime object.
 //
 // If layout is given, DateTime() uses time.Parse() with given layout.
 // Otherwise, it uses http.ParseTime(). If pasing error occurred,


Test patch:
diff --git a/string_test.go b/string_test.go
index db01171..1065f96 100644
--- a/string_test.go
+++ b/string_test.go
@@ -193,6 +193,28 @@ func TestStringLength(t *testing.T) {
 	assert.Equal(t, 7.0, num.Raw())
 }
 
+func TestStringNumber(t *testing.T) {
+	reporter := newMockReporter(t)
+
+	value1 := NewString(reporter, "1234567")
+	num1 := value1.Number()
+	value1.chain.assertOK(t)
+	num1.chain.assertOK(t)
+	assert.Equal(t, float64(1234567), num1.Raw())
+
+	value2 := NewString(reporter, "11.22")
+	num2 := value2.Number()
+	value2.chain.assertOK(t)
+	num2.chain.assertOK(t)
+	assert.Equal(t, float64(11.22), num2.Raw())
+
+	value3 := NewString(reporter, "a1")
+	num3 := value3.Number()
+	value3.chain.assertFailed(t)
+	num3.chain.assertFailed(t)
+	assert.Equal(t, float64(0), num3.Raw())
+}
+
 func TestStringDateTime(t *testing.T) {
 	reporter := newMockReporter(t)
Repository: gavv/httpexpect
Pull request #115 (2022-06-14 12:03:06)

tests: fix expected filename in TestRequestBodyMultipartFile
currently TestRequestBodyMultipartFile expect the filename given by

func (*multipartPart) FileName() string

to be a fullpath in one of the test cases, however the documentation
states that:

> the filename is passed through filepath.Base (which is platform
> dependent) before being returned.

then the test fails.

This change fix the expected filename for this test, using the same
filepath.Base function.

Fixes: #103

EstebanJesus: Hi @aries-zhang, I really don't know what the strategy is like, but I don't see a problem with it.
clobrano: Hey, let me know if there is more I can do to improve this PR.

Patch:
diff --git a/string.go b/string.go
index 6507e35..3617c86 100644
--- a/string.go
+++ b/string.go
@@ -3,6 +3,7 @@ package httpexpect
 import (
 	"net/http"
 	"regexp"
+	"strconv"
 	"strings"
 	"time"
 )
@@ -55,7 +56,20 @@ func (s *String) Length() *Number {
 	return &Number{s.chain, float64(len(s.value))}
 }
 
-// DateTime parses date/time from string an returns a new DateTime object.
+// Number parses float from string and returns a new Number object.
+//
+// Example:
+//  str := NewString(t, "1234")
+//  str.Number()
+func (v *String) Number() *Number {
+	num, err := strconv.ParseFloat(v.value, 64)
+	if err != nil {
+		v.chain.fail(err.Error())
+	}
+	return &Number{v.chain, num}
+}
+
+// DateTime parses date/time from string and returns a new DateTime object.
 //
 // If layout is given, DateTime() uses time.Parse() with given layout.
 // Otherwise, it uses http.ParseTime(). If pasing error occurred,


Test patch:
diff --git a/request_test.go b/request_test.go
index 5baeaf9..092d30e 100644
--- a/request_test.go
+++ b/request_test.go
@@ -9,6 +9,7 @@ import (
 	"mime/multipart"
 	"net/http"
 	"os"
+	"path/filepath"
 	"strings"
 	"testing"
 	"time"
@@ -1211,7 +1212,7 @@ func TestRequestBodyMultipartFile(t *testing.T) {
 
 	part2, _ := reader.NextPart()
 	assert.Equal(t, "b", part2.FormName())
-	assert.Equal(t, filename2, part2.FileName())
+	assert.Equal(t, filepath.Base(filename2), part2.FileName())
 	b2, _ := ioutil.ReadAll(part2)
 	assert.Equal(t, "2", string(b2))
 
diff --git a/string_test.go b/string_test.go
index db01171..1065f96 100644
--- a/string_test.go
+++ b/string_test.go
@@ -193,6 +193,28 @@ func TestStringLength(t *testing.T) {
 	assert.Equal(t, 7.0, num.Raw())
 }
 
+func TestStringNumber(t *testing.T) {
+	reporter := newMockReporter(t)
+
+	value1 := NewString(reporter, "1234567")
+	num1 := value1.Number()
+	value1.chain.assertOK(t)
+	num1.chain.assertOK(t)
+	assert.Equal(t, float64(1234567), num1.Raw())
+
+	value2 := NewString(reporter, "11.22")
+	num2 := value2.Number()
+	value2.chain.assertOK(t)
+	num2.chain.assertOK(t)
+	assert.Equal(t, float64(11.22), num2.Raw())
+
+	value3 := NewString(reporter, "a1")
+	num3 := value3.Number()
+	value3.chain.assertFailed(t)
+	num3.chain.assertFailed(t)
+	assert.Equal(t, float64(0), num3.Raw())
+}
+
 func TestStringDateTime(t *testing.T) {
 	reporter := newMockReporter(t)
Repository: gavv/httpexpect
Pull request #300 (2023-02-20 18:19:02)

Add Environment.Clear method
PR addresses the following issue #260 

Any change recommendations or best practice tips are greatly appreciated. 

coveralls: 
[![Coverage Status](https://coveralls.io/builds/57109943/badge)](https://coveralls.io/builds/57109943)

Coverage: 95.223% (+0.005%) from 95.218% when pulling **11578e3f407590b50d2e9b1f7aeae14867c7f426 on e-berman:eberman_clear_method** into **30a0c13c69b68598f51c37aae0ff1d63fe72d5c7 on gavv:master**.


Patch:
diff --git a/environment.go b/environment.go
index b2d4da6..aa303a7 100644
--- a/environment.go
+++ b/environment.go
@@ -85,6 +85,24 @@ func (e *Environment) Delete(key string) {
 	delete(e.data, key)
 }
 
+// Clear will delete all key value pairs from the environment
+//
+// Example:
+//
+//	env := NewEnvironment(t)
+//	env.Put("key1", 123)
+//	env.Put("key2", 456)
+//	env.Clear()
+func (e *Environment) Clear() {
+	opChain := e.chain.enter("Clear()")
+	defer opChain.leave()
+
+	e.mu.Lock()
+	defer e.mu.Unlock()
+
+	e.data = make(map[string]interface{})
+}
+
 // Has returns true if value exists in the environment.
 //
 // Example:


Test patch:
diff --git a/environment_test.go b/environment_test.go
index 77932eb..8983ded 100644
--- a/environment_test.go
+++ b/environment_test.go
@@ -90,6 +90,34 @@ func TestEnvironment_Delete(t *testing.T) {
 	env.chain.clearFailed()
 }
 
+func TestEnvironment_Clear(t *testing.T) {
+	env := newEnvironment(newMockChain(t))
+
+	for i := 1; i < 11; i++ {
+		key := fmt.Sprint("key", i)
+		env.Put(key, i)
+		env.chain.assertNotFailed(t)
+		assert.True(t, env.Has(key))
+		assert.NotNil(t, env.Get(key))
+		assert.Equal(t, i, env.Get(key).(int))
+		env.chain.assertNotFailed(t)
+	}
+
+	env.Clear()
+	env.chain.assertNotFailed(t)
+
+	for i := 1; i < 11; i++ {
+		key := fmt.Sprint("key", i)
+		assert.False(t, env.Has(key))
+		assert.Nil(t, env.Get(key))
+		env.chain.assertFailed(t)
+		env.chain.clearFailed()
+	}
+
+	assert.Zero(t, len(env.data))
+	env.chain.assertNotFailed(t)
+}
+
 func TestEnvironment_NotFound(t *testing.T) {
 	env := newEnvironment(newMockChain(t))