nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: markbates/goth
Pull request #306 (2020-01-18 16:43:15)

Helper method for setting provider in http context
This pull request adds a `GetContextWithProvider` method to `gothic/gothic.go` to reduce the boilerplate required to set a `provider` in the http context.

I have included a test but I am not sure it is useful.

https://github.com/markbates/goth/pull/301#pullrequestreview-342869518


Patch:
diff --git a/gothic/gothic.go b/gothic/gothic.go
index 359a3cc..edd0e98 100644
--- a/gothic/gothic.go
+++ b/gothic/gothic.go
@@ -10,6 +10,7 @@ package gothic
 import (
 	"bytes"
 	"compress/gzip"
+	"context"
 	"crypto/rand"
 	"encoding/base64"
 	"errors"
@@ -36,6 +37,7 @@ var defaultStore sessions.Store
 var keySet = false
 
 type key int
+
 // ProviderParamKey can be used as a key in context when passing in a provider
 const ProviderParamKey key = iota
 
@@ -289,6 +291,11 @@ func getProviderName(req *http.Request) (string, error) {
 	return "", errors.New("you must select a provider")
 }
 
+// GetContextWithProvider returns a new request context containing the provider
+func GetContextWithProvider(req *http.Request, provider string) *http.Request {
+	return req.WithContext(context.WithValue(req.Context(), ProviderParamKey, provider))
+}
+
 // StoreInSession stores a specified key/value pair in the session.
 func StoreInSession(key string, value string, req *http.Request, res http.ResponseWriter) error {
 	session, _ := Store.New(req, SessionName)


Test patch:
diff --git a/gothic/gothic_test.go b/gothic/gothic_test.go
index fecde6c..4f8aa20 100644
--- a/gothic/gothic_test.go
+++ b/gothic/gothic_test.go
@@ -166,6 +166,28 @@ func Test_CompleteUserAuthWithSessionDeducedProvider(t *testing.T) {
 	a.Equal(user.Email, "homer@example.com")
 }
 
+func Test_CompleteUserAuthWithContextParamProvider(t *testing.T) {
+	a := assert.New(t)
+
+	res := httptest.NewRecorder()
+	req, err := http.NewRequest("GET", "/auth/callback", nil)
+	a.NoError(err)
+
+	req = GetContextWithProvider(req, "faux")
+
+	sess := faux.Session{Name: "Homer Simpson", Email: "homer@example.com"}
+	session, _ := Store.Get(req, SessionName)
+	session.Values["faux"] = gzipString(sess.Marshal())
+	err = session.Save(req, res)
+	a.NoError(err)
+
+	user, err := CompleteUserAuth(res, req)
+	a.NoError(err)
+
+	a.Equal(user.Name, "Homer Simpson")
+	a.Equal(user.Email, "homer@example.com")
+}
+
 func Test_Logout(t *testing.T) {
 	a := assert.New(t)
Repository: codypearce/material-bread
Pull request #324 (2019-11-01 11:27:21)

Add style props to DrawerHeader component
Fix missing style props on DrawerHeader component


Patch:
diff --git a/src/Components/Drawer/DrawerHeader/DrawerHeader.js b/src/Components/Drawer/DrawerHeader/DrawerHeader.js
index 5e7a83c..ff5b5cd 100644
--- a/src/Components/Drawer/DrawerHeader/DrawerHeader.js
+++ b/src/Components/Drawer/DrawerHeader/DrawerHeader.js
@@ -20,10 +20,10 @@ class DrawerHeader extends Component {
   }
 
   render() {
-    const { avatar, title, subtitle } = this.props;
+    const { avatar, title, subtitle, style } = this.props;
 
     return (
-      <View style={styles.drawerHeader}>
+      <View style={[styles.drawerHeader, style]}>
         {avatar ? this._renderAvatar() : null}
         <Text style={styles.title}>{title}</Text>
         <Text style={styles.subtitle}>{subtitle}</Text>


Test patch:
diff --git a/src/Components/Drawer/DrawerHeader/__snapshots__/DrawerHeader.test.js.snap b/src/Components/Drawer/DrawerHeader/__snapshots__/DrawerHeader.test.js.snap
index 66d35b8..719f715 100644
--- a/src/Components/Drawer/DrawerHeader/__snapshots__/DrawerHeader.test.js.snap
+++ b/src/Components/Drawer/DrawerHeader/__snapshots__/DrawerHeader.test.js.snap
@@ -3,12 +3,15 @@
 exports[`DrawerHeader Renders 1`] = `
 <View
   style={
-    Object {
-      "borderBottomColor": "rgba(0,0,0,.12)",
-      "borderBottomWidth": 0.5,
-      "paddingHorizontal": 16,
-      "paddingVertical": 18,
-    }
+    Array [
+      Object {
+        "borderBottomColor": "rgba(0,0,0,.12)",
+        "borderBottomWidth": 0.5,
+        "paddingHorizontal": 16,
+        "paddingVertical": 18,
+      },
+      undefined,
+    ]
   }
 >
   <Text
Repository: unexpectedjs/unexpected
Pull request #371 (2017-02-16 00:50:18)

Fix: `to exhaustively satisfy` doesn't consider a missing property to be identical to a property with a value of undefined (#370)


Patch:
diff --git a/lib/assertions.js b/lib/assertions.js
index aec38df5..b38da21d 100644
--- a/lib/assertions.js
+++ b/lib/assertions.js
@@ -1248,10 +1248,16 @@ module.exports = function (expect) {
         return expect.promise.all([
             expect.promise(function () {
                 if (expect.flags.exhaustively) {
-                    var nonOwnKeys = keys.filter(function (key) {
-                        return !Object.prototype.hasOwnProperty.call(subject, key);
+                    var nonOwnKeysWithDefinedValues = keys.filter(function (key) {
+                        return !Object.prototype.hasOwnProperty.call(subject, key) && typeof subject[key] !== 'undefined';
                     });
-                    expect(keys.length - nonOwnKeys.length, 'to equal', subjectKeys.length);
+                    var valueKeysWithDefinedValues = keys.filter(function (key) {
+                        return typeof value[key] !== 'undefined';
+                    });
+                    var subjectKeysWithDefinedValues = subjectKeys.filter(function (key) {
+                        return typeof subject[key] !== 'undefined';
+                    });
+                    expect(valueKeysWithDefinedValues.length - nonOwnKeysWithDefinedValues.length, 'to equal', subjectKeysWithDefinedValues.length);
                 }
             }),
             expect.promise.all(promiseByKey)


Test patch:
diff --git a/test/assertions/to-satisfy.spec.js b/test/assertions/to-satisfy.spec.js
index 6f208642..0a1a12bb 100644
--- a/test/assertions/to-satisfy.spec.js
+++ b/test/assertions/to-satisfy.spec.js
@@ -788,6 +788,14 @@ describe('to satisfy assertion', function () {
                     );
                 });
             });
+
+            it('should treat a missing value property the same as a subject property of undefined', function () {
+                expect({ foo: undefined }, 'to exhaustively satisfy', {});
+            });
+
+            it('should treat a missing subject property the same as a value property of undefined', function () {
+                expect({}, 'to exhaustively satisfy', { foo: undefined });
+            });
         });
 
         it('should support satisfying against a regexp', function () {
Repository: unexpectedjs/unexpected
Pull request #389 (2017-04-24 19:47:38)

Support expect.it(function (value) {...})


Patch:
diff --git a/lib/Unexpected.js b/lib/Unexpected.js
index c300168c..c63ab01f 100644
--- a/lib/Unexpected.js
+++ b/lib/Unexpected.js
@@ -132,7 +132,16 @@ function evaluateGroup(expect, subject, orGroup) {
         return {
             expectation: args,
             promise: makePromise(function () {
-                return expect.apply(expect, args);
+                if (typeof args[1] === 'function') {
+                    if (args.length > 2) {
+                        throw new Error('expect.it(<function>) does not accept additional arguments');
+                    } else {
+                        // expect.it(function (value) { ... })
+                        return args[1](args[0]);
+                    }
+                } else {
+                    return expect.apply(expect, args);
+                }
             })
         };
     });


Test patch:
diff --git a/test/api/it.spec.js b/test/api/it.spec.js
index 84dc3958..a0940c32 100644
--- a/test/api/it.spec.js
+++ b/test/api/it.spec.js
@@ -265,4 +265,33 @@ describe('expect.it', function () {
             );
         });
     });
+
+    describe('when passed a function', function () {
+        it('should succeed', function () {
+            expect.it(function (value) {
+                expect(value, 'to equal', 'foo');
+            })('foo');
+        });
+
+        it('should fail with a diff', function () {
+            expect(function () {
+                expect.it(function (value) {
+                    expect(value, 'to equal', 'bar');
+                })('foo');
+            }, 'to throw',
+                "expected 'foo' to equal 'bar'\n" +
+                "\n" +
+                "-foo\n" +
+                "+bar"
+            );
+        });
+
+        it('should fail when passed more than two arguments', function () {
+            expect(function () {
+                expect.it(function (value) {
+                    expect(value, 'to equal', 'bar');
+                }, 'yadda')('foo');
+            }, 'to throw', 'expect.it(<function>) does not accept additional arguments');
+        });
+    });
 });
Repository: unexpectedjs/unexpected
Pull request #397 (2017-05-08 18:05:45)

to be (a|an) <string>: Always die when a non-existent type is specified


Patch:
diff --git a/lib/assertions.js b/lib/assertions.js
index 97e27abe..cc0d8c77 100644
--- a/lib/assertions.js
+++ b/lib/assertions.js
@@ -107,6 +107,12 @@ module.exports = function (expect) {
         expect.argsOutput[0] = function (output) {
             output.jsString(typeName);
         };
+        if (!expect.getType(typeName)) {
+            expect.errorMode = 'nested';
+            expect.fail(function (output) {
+                output.error('Unknown type:').sp().jsString(typeName);
+            });
+        }
         expect(expect.subjectType.is(typeName), '[not] to be truthy');
     });
 


Test patch:
diff --git a/test/assertions/to-be-a.spec.js b/test/assertions/to-be-a.spec.js
index 5145b997..45c4476b 100644
--- a/test/assertions/to-be-a.spec.js
+++ b/test/assertions/to-be-a.spec.js
@@ -53,7 +53,19 @@ describe('to be a/an assertion', function () {
         it('should fail when the type is not defined', function () {
             expect(function () {
                 expect(123, 'to be a', 'FoopQuuxDoop');
-            }, 'to throw', 'expected 123 to be a FoopQuuxDoop');
+            }, 'to throw',
+                'expected 123 to be a FoopQuuxDoop\n' +
+                '  Unknown type: FoopQuuxDoop'
+            );
+        });
+
+        it('should fail when the type is not defined in the "not" case', function () {
+            expect(function () {
+                expect(123, 'not to be a', 'FoopQuuxDoop');
+            }, 'to throw',
+                'expected 123 not to be a FoopQuuxDoop\n' +
+                '  Unknown type: FoopQuuxDoop'
+            );
         });
     });
Repository: unexpectedjs/unexpected
Pull request #400 (2017-06-16 15:00:30)

addStyle & installTheme: Return the expect function rather than the magicpen instance (for chaining)
I noticed that `expect.addStyle(...).addAssertion(...)` didn't work, and it turns out that we return the magicpen instance instead of the expect function in a couple of cases.


Patch:
diff --git a/lib/Unexpected.js b/lib/Unexpected.js
index dbfd04e5..a03c6f51 100644
--- a/lib/Unexpected.js
+++ b/lib/Unexpected.js
@@ -764,11 +764,13 @@ Unexpected.prototype.addType = function (type, childUnexpected) {
 };
 
 Unexpected.prototype.addStyle = function () { // ...
-    return this.output.addStyle.apply(this.output, arguments);
+    this.output.addStyle.apply(this.output, arguments);
+    return this.expect;
 };
 
 Unexpected.prototype.installTheme = function () { // ...
-    return this.output.installTheme.apply(this.output, arguments);
+    this.output.installTheme.apply(this.output, arguments);
+    return this.expect;
 };
 
 function getPluginName(plugin) {


Test patch:
diff --git a/test/api/addStyle.spec.js b/test/api/addStyle.spec.js
new file mode 100644
index 00000000..ab45d22e
--- /dev/null
+++ b/test/api/addStyle.spec.js
@@ -0,0 +1,13 @@
+/*global expect*/
+describe('addStyle', function () {
+    var clonedExpect;
+    beforeEach(function () {
+        clonedExpect = expect.clone();
+    });
+
+    it('is chainable (returns the expect function, not the magicpen instance)', function () {
+        clonedExpect
+            .addStyle('foo', function () {})
+            ('bar', 'to equal', 'bar');
+    });
+});
diff --git a/test/api/installTheme.spec.js b/test/api/installTheme.spec.js
new file mode 100644
index 00000000..6b9329be
--- /dev/null
+++ b/test/api/installTheme.spec.js
@@ -0,0 +1,13 @@
+/*global expect*/
+describe('installTheme', function () {
+    var clonedExpect;
+    beforeEach(function () {
+        clonedExpect = expect.clone();
+    });
+
+    it('is chainable (returns the expect function, not the magicpen instance)', function () {
+        clonedExpect
+            .installTheme('html', { comment: 'gray' })
+            ('bar', 'to equal', 'bar');
+    });
+});
Repository: unexpectedjs/unexpected
Pull request #415 (2017-08-14 08:25:34)

Don't break when a function has its own custom #toString
I ran into a problem with chance-generators instances being inspected as `function ( /*...*/ ) { /*...*/ }`. Turns out it's because [chance-generators defines a custom `toString`](https://github.com/sunesimonsen/chance-generators/blob/dd59a69190ba8ee47fb2c1dede48261b8d8122f5/lib/chance-generators.js#L65-L67).

The enclosed fix handles that by getting the `toString` from `Function.prototype` instead.


Patch:
diff --git a/lib/types.js b/lib/types.js
index 5314025d..92fba6fa 100644
--- a/lib/types.js
+++ b/lib/types.js
@@ -760,7 +760,8 @@ module.exports = function (expect) {
             return a === b;
         },
         inspect: function (f, depth, output, inspect) {
-            var source = f.toString().replace(/\r\n?|\n\r?/g, '\n');
+            // Don't break when a function has its own custom #toString:
+            var source = Function.prototype.toString.call(f).replace(/\r\n?|\n\r?/g, '\n');
             var name = utils.getFunctionName(f) || '';
             var preamble;
             var body;


Test patch:
diff --git a/test/api/inspect.spec.js b/test/api/inspect.spec.js
index a2745f09..041bd1d1 100644
--- a/test/api/inspect.spec.js
+++ b/test/api/inspect.spec.js
@@ -328,23 +328,6 @@ describe('inspect', function () {
         });
     }
 
-    it('should output ellipsis when the toString method of a function returns something unparsable', function () {
-        function foo() {}
-        foo.toString = function () {
-            return 'quux';
-        };
-        expect(foo, 'to inspect as', 'function foo( /*...*/ ) { /*...*/ }');
-    });
-
-    it('should render a function within a nested structure ellipsis when the toString method of a function returns something unparsable', function () {
-        function foo() {}
-        foo.toString = function () {
-            return 'quux';
-        };
-        expect({ bar: { quux: foo } }, 'to inspect as',
-               '{ bar: { quux: function foo( /*...*/ ) { /*...*/ } } }');
-    });
-
     it('should bail out of removing the indentation of functions that use multiline string literals', function () {
         /*eslint-disable no-multi-str*/
         expect(function () {
diff --git a/test/types/function-type.spec.js b/test/types/function-type.spec.js
index 0ef77e0d..d9531cbe 100644
--- a/test/types/function-type.spec.js
+++ b/test/types/function-type.spec.js
@@ -16,6 +16,16 @@ describe('function type', function () {
         );
     });
 
+    it('should inspect a function with a custom toString correctly', function () {
+        var fn = function foo() {};
+        fn.toString = 'breakage';
+        expect(
+            fn,
+            'to inspect as',
+            'function foo() {}'
+        );
+    });
+
     var isNodeJs3OrBelow = typeof process === 'object' && /^v[0123]\./.test(process.version);
     var isPhantomJs = typeof navigator !== 'undefined' && /phantom/i.test(navigator.userAgent);
     if (!isNodeJs3OrBelow && !isPhantomJs) {
Repository: unexpectedjs/unexpected
Pull request #433 (2018-01-18 23:03:26)

Adding a failing test for expect.child not honoring type order
I expect the exported type to take precedence here.


Patch:
diff --git a/lib/Unexpected.js b/lib/Unexpected.js
index 1f640967..638d39fa 100644
--- a/lib/Unexpected.js
+++ b/lib/Unexpected.js
@@ -1366,6 +1366,10 @@ Unexpected.prototype.child = function () {
         return this;
     };
     childExpect.exportType = function (type) {
+        if (childExpect.getType(type.name) !== type) {
+            childExpect.addType(type);
+        }
+
         parent.addType(type, childUnexpected);
         return this;
     };


Test patch:
diff --git a/test/api/child.spec.js b/test/api/child.spec.js
index 183481f1..bc689886 100644
--- a/test/api/child.spec.js
+++ b/test/api/child.spec.js
@@ -272,5 +272,35 @@ describe('#child', function () {
 
         expect(childExpect.createOutput('text').appendInspected('yaddayaddafoo').toString(), 'to equal', '>>yaddayaddafoo<<>>yaddayaddafoo<<');
     });
+
+    it('#inspect should use the exported types when inspecting failed assertions', () => {
+        childExpect.addStyle('fancyQuotes', function (text) {
+            this.text('>>').text(text).text('<<');
+        });
+
+        childExpect.addType({
+            name: 'yadda-no-qoutes',
+            identify: (obj) => /^yaddayadda/.test(obj),
+            inspect: (value, depth, output) => {
+                output.text(value);
+            }
+        });
+
+        childExpect.exportType({
+            name: 'yadda',
+            identify: (obj) => /^yaddayadda/.test(obj),
+            inspect: (value, depth, output) => {
+                output.fancyQuotes(value);
+            }
+        });
+
+        childExpect.exportAssertion('<yadda> to be short gibberish', (expect, gibberish) => (
+            expect(gibberish.length < 10, 'to be true')
+        ));
+
+        expect(() => {
+            parentExpect('yaddayaddafoo', 'to be short gibberish');
+        }, 'to throw', 'expected >>yaddayaddafoo<< to be short gibberish');
+    });
 });
Repository: unexpectedjs/unexpected
Pull request #465 (2018-05-03 20:00:56)

Fix key in value check that were not converted to type.hasKey().


Patch:
diff --git a/lib/types.js b/lib/types.js
index 41b49b58..ddf1ff92 100644
--- a/lib/types.js
+++ b/lib/types.js
@@ -348,10 +348,10 @@ module.exports = function(expect) {
             let isInlineDiff = false;
             let valueOutput;
             if (conflicting) {
-              if (!(key in expected)) {
+              if (!type.hasKey(expected, key)) {
                 annotation.error('should be removed');
                 isInlineDiff = true;
-              } else if (!(key in actual)) {
+              } else if (!type.hasKey(actual, key)) {
                 this.error('// missing').sp();
                 valueOutput = output.clone().appendInspected(valueExpected);
                 isInlineDiff = true;


Test patch:
diff --git a/test/types/object-type.spec.js b/test/types/object-type.spec.js
index 06f9d9c2..4712e025 100644
--- a/test/types/object-type.spec.js
+++ b/test/types/object-type.spec.js
@@ -462,4 +462,65 @@ describe('object type', function() {
       }
     );
   });
+
+  describe('with a subtype that key presence and retrieval', function() {
+    function NestedObject(contentObject) {
+      this.contentObject = contentObject;
+    }
+
+    var clonedExpect = expect.clone();
+
+    clonedExpect.addType({
+      name: 'NestedObject',
+      base: 'object',
+      identify: function(obj) {
+        return obj && obj instanceof NestedObject;
+      },
+      getKeys: function(obj) {
+        return Object.keys(obj.contentObject);
+      },
+      hasKey: function(obj, key) {
+        return obj.contentObject[key];
+      },
+      valueForKey: function(obj, key) {
+        return obj.contentObject[key];
+      }
+    });
+
+    it('should mark keys missing', function() {
+      expect(
+        function() {
+          clonedExpect(
+            new NestedObject({}),
+            'to equal',
+            new NestedObject({ foo: 'bar' })
+          );
+        },
+        'to throw',
+        "expected NestedObject({}) to equal NestedObject({ foo: 'bar' })\n" +
+          '\n' +
+          'NestedObject({\n' +
+          "  // missing foo: 'bar'\n" +
+          '})'
+      );
+    });
+
+    it('should mark keys unecessary', function() {
+      expect(
+        function() {
+          clonedExpect(
+            new NestedObject({ foo: 'bar' }),
+            'to equal',
+            new NestedObject({})
+          );
+        },
+        'to throw',
+        "expected NestedObject({ foo: 'bar' }) to equal NestedObject({})\n" +
+          '\n' +
+          'NestedObject({\n' +
+          "  foo: 'bar' // should be removed\n" +
+          '})'
+      );
+    });
+  });
 });
Repository: unexpectedjs/unexpected
Pull request #517 (2018-09-28 17:54:29)

Freeze the top-level expect
As discussed on #476


Patch:
diff --git a/lib/index.js b/lib/index.js
index de1ff88c..f825a7bc 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -2,7 +2,8 @@ module.exports = require('./Unexpected')
   .create()
   .use(require('./styles'))
   .use(require('./types'))
-  .use(require('./assertions'));
+  .use(require('./assertions'))
+  .freeze();
 
 // Add an inspect method to all the promises we return that will make the REPL, console.log, and util.inspect render it nicely in node.js:
 require('unexpected-bluebird').prototype.inspect = function() {


Test patch:
diff --git a/externaltests/assertionSucceedsWhilePromiseIsPending.spec.js b/externaltests/assertionSucceedsWhilePromiseIsPending.spec.js
index a1303ac6..6d87b2fb 100644
--- a/externaltests/assertionSucceedsWhilePromiseIsPending.spec.js
+++ b/externaltests/assertionSucceedsWhilePromiseIsPending.spec.js
@@ -1,4 +1,4 @@
-var expect = require('../lib');
+var expect = require('../lib').clone();
 
 expect.addAssertion('<any> to bar', function(expect, subject) {
   expect(subject, 'to equal', 'bar');
diff --git a/externaltests/failingAsync.spec.js b/externaltests/failingAsync.spec.js
index c05be2e7..24781cb0 100644
--- a/externaltests/failingAsync.spec.js
+++ b/externaltests/failingAsync.spec.js
@@ -1,4 +1,4 @@
-var expect = require('../lib');
+var expect = require('../lib').clone();
 
 expect.addAssertion('<any> when delayed a little bit <assertion?>', function(
   expect,
diff --git a/externaltests/forgotToReturnPromiseRejectedInTheNextTick.spec.js b/externaltests/forgotToReturnPromiseRejectedInTheNextTick.spec.js
index 821dae9e..7e0d4ef7 100644
--- a/externaltests/forgotToReturnPromiseRejectedInTheNextTick.spec.js
+++ b/externaltests/forgotToReturnPromiseRejectedInTheNextTick.spec.js
@@ -1,4 +1,4 @@
-var expect = require('../lib');
+var expect = require('../lib').clone();
 
 it('should fail', function() {
   expect.addAssertion('<any> to foo', function(expect, subject) {
diff --git a/test/unexpected.spec.js b/test/unexpected.spec.js
index 23a4d312..320f8f5e 100644
--- a/test/unexpected.spec.js
+++ b/test/unexpected.spec.js
@@ -1,4 +1,4 @@
-/*global unexpected*/
+/*global unexpected, weknowhow*/
 
 it.skipIf = function(condition) {
   (condition ? it.skip : it).apply(
@@ -10,6 +10,19 @@ it.skipIf = function(condition) {
 describe('unexpected', function() {
   var expect = unexpected.clone();
 
+  it('should freeze the top-level unexpected instance', function() {
+    const topLevelExpect =
+      typeof weknowhow === 'undefined' ? require('../lib/') : weknowhow.expect;
+
+    expect(
+      function() {
+        topLevelExpect.addAssertion('<any> to foo', function() {});
+      },
+      'to throw',
+      'Cannot add an assertion to a frozen instance, please run .clone() first'
+    );
+  });
+
   describe('argument validation', function() {
     it('fails when given no parameters', function() {
       expect(