nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: evan-liu/karabiner.ts
Pull request #44 (2023-04-28 08:29:13)

✨ Add withMapper()


Patch:
diff --git a/src/index.ts b/src/index.ts
index 8828f27..13ecf94 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -4,6 +4,7 @@ export * from './karabiner/karabiner-config'
 export * from './utils/key-alias'
 export * from './utils/multi-modifier'
 export * from './utils/with-condition'
+export * from './utils/with-mapper'
 export * from './utils/with-modifier'
 
 export * from './config/condition'
diff --git a/src/utils/with-mapper.ts b/src/utils/with-mapper.ts
new file mode 100644
index 0000000..5f07ef0
--- /dev/null
+++ b/src/utils/with-mapper.ts
@@ -0,0 +1,54 @@
+import { FromKeyParam } from '../config/from'
+import { buildManipulators, ManipulatorBuilder } from '../config/manipulator'
+import { Manipulator } from '../karabiner/karabiner-config'
+import { FromKeyCode } from '../karabiner/key-code'
+import { getKeyWithAlias } from './key-alias'
+
+/**
+ *  A high-order function to map an array of keys.
+ *
+ *  @example
+ *    withMapper([1, 2, 3])(
+ *      (key) => map(key).to(key, '⌘⌥')
+ *    )
+ */
+export function withMapper(
+  src: FromKeyParam[],
+): (
+  mapper: (key: FromKeyCode) => Manipulator | ManipulatorBuilder,
+) => ManipulatorBuilder
+
+/**
+ *  A high-order function to map a group of key-value pairs.
+ *
+ *  @example
+ *    withMapper({1: 'a', 2: '⌥b})(
+ *      (k, v) => map(k).to(v)
+ *    )
+ */
+export function withMapper<T = string>(
+  src: Partial<Record<FromKeyParam, T>>,
+): (
+  mapper: (key: FromKeyCode, value: any) => Manipulator | ManipulatorBuilder,
+) => ManipulatorBuilder
+
+export function withMapper(
+  src: FromKeyParam[] | Partial<Record<FromKeyParam, any>>,
+): (
+  mapper: (key: FromKeyCode, value?: any) => Manipulator | ManipulatorBuilder,
+) => ManipulatorBuilder {
+  return (mapper) => ({
+    build: () => {
+      const entries = (
+        Array.isArray(src) ? src.map((v) => [v]) : Object.entries(src)
+      ) as Array<[FromKeyParam, any]>
+      return entries.reduce(
+        (r, [k, v]) => [
+          ...r,
+          ...buildManipulators(mapper(getKeyWithAlias(k) as FromKeyCode, v)),
+        ],
+        [] as Manipulator[],
+      )
+    },
+  })
+}


Test patch:
diff --git a/src/utils/with-mapper.test.ts b/src/utils/with-mapper.test.ts
new file mode 100644
index 0000000..4cee132
--- /dev/null
+++ b/src/utils/with-mapper.test.ts
@@ -0,0 +1,23 @@
+import { expect, test } from 'vitest'
+import { withMapper } from './with-mapper'
+import { map } from '../config/from'
+
+test('withMapper([])', () => {
+  expect(withMapper(['a'])((v) => map(v).to(1)).build()).toEqual([
+    {
+      type: 'basic',
+      from: { key_code: 'a' },
+      to: [{ key_code: '1' }],
+    },
+  ])
+})
+
+test('withMapper({})', () => {
+  expect(withMapper({ a: 'b' })((k, v) => map(k).to(v)).build()).toEqual([
+    {
+      type: 'basic',
+      from: { key_code: 'a' },
+      to: [{ key_code: 'b' }],
+    },
+  ])
+})
Repository: evan-liu/karabiner.ts
Pull request #62 (2023-05-01 18:37:51)

✨ Add toSuperHyper()


Patch:
diff --git a/src/config/manipulator.ts b/src/config/manipulator.ts
index d83c4c7..7f12d39 100644
--- a/src/config/manipulator.ts
+++ b/src/config/manipulator.ts
@@ -32,6 +32,7 @@ import {
   toSetVar,
   toSleepSystem,
   toStickyModifier,
+  toSuperHyper,
 } from './to'
 import { buildCondition, ConditionBuilder } from './condition'
 import { ToConsumerKeyCode } from '../karabiner/consumer-key-code'
@@ -80,6 +81,12 @@ export class BasicManipulatorBuilder implements ManipulatorBuilder {
     return this
   }
 
+  /** To SuperHyper key ⌘⌥⌃⇧fn */
+  toSuperHyper(options?: ToEventOptions): this {
+    this.addToEvent(toSuperHyper(options))
+    return this
+  }
+
   /** To vk_none (Disable this key) */
   toNone(options?: ToEventOptions): this {
     this.addToEvent(toNone(options))
diff --git a/src/config/to.ts b/src/config/to.ts
index 69d51df..ce2dc0d 100644
--- a/src/config/to.ts
+++ b/src/config/to.ts
@@ -37,6 +37,11 @@ export function toMeh(options?: ToEventOptions): ToEvent {
   return toKey('left_option', '⌃⇧', options)
 }
 
+/** Create ToEvent with key_code ⌘⌥⌃⇧fn */
+export function toSuperHyper(options?: ToEventOptions): ToEvent {
+  return toKey('fn', '⌘⌥⌃⇧', options)
+}
+
 /** Create ToEvent with key_code vk_none (Disable this key) */
 export function toNone(options?: ToEventOptions): ToEvent {
   return toKey('vk_none', undefined, options)
diff --git a/src/utils/multi-modifier.ts b/src/utils/multi-modifier.ts
index 153efea..b066607 100644
--- a/src/utils/multi-modifier.ts
+++ b/src/utils/multi-modifier.ts
@@ -14,6 +14,7 @@ export const multiModifierAliases = {
   '⌘⌥⌃⇧': ['command', 'option', 'control', 'shift'],
   Meh: ['option', 'control', 'shift'],
   Hyper: ['command', 'option', 'control', 'shift'],
+  SuperHyper: ['command', 'option', 'control', 'shift', 'fn'],
 } /* c8 ignore next */ satisfies Record<string, Modifier[]>
 
 export type MultiModifierAlias = keyof typeof multiModifierAliases


Test patch:
diff --git a/src/config/manipulator.test.ts b/src/config/manipulator.test.ts
index 40345f2..4dd12f0 100644
--- a/src/config/manipulator.test.ts
+++ b/src/config/manipulator.test.ts
@@ -27,13 +27,18 @@ describe('ManipulatorBuilder', () => {
     expect(new BasicManipulatorBuilder(from).to([]).build()[0].to).toEqual([])
   })
 
-  test('toHyper(), toMeh()', () => {
+  test('toHyper(), toMeh(), toSuperHyper()', () => {
     expect(new BasicManipulatorBuilder(from).toHyper().build()[0].to).toEqual([
       { key_code: 'left_command', modifiers: ['option', 'control', 'shift'] },
     ])
     expect(new BasicManipulatorBuilder(from).toMeh().build()[0].to).toEqual([
       { key_code: 'left_option', modifiers: ['control', 'shift'] },
     ])
+    expect(
+      new BasicManipulatorBuilder(from).toSuperHyper().build()[0].to,
+    ).toEqual([
+      { key_code: 'fn', modifiers: ['command', 'option', 'control', 'shift'] },
+    ])
   })
 
   test('toNone()', () => {
Repository: evan-liu/karabiner.ts
Pull request #81 (2023-05-13 09:18:55)

🧑‍💻 Add modifierLayer() and hyperLayer()


Patch:
diff --git a/src/config/layer.ts b/src/config/layer.ts
index abdd3a9..f0af0f2 100644
--- a/src/config/layer.ts
+++ b/src/config/layer.ts
@@ -22,7 +22,7 @@ import { BasicRuleBuilder } from './rule'
 import { toArray } from '../utils/to-array'
 import { BuildContext } from '../utils/build-context'
 import { BasicManipulatorBuilder } from './manipulator'
-import { FromModifierParam, SideModifierAlias } from './modifier'
+import { FromModifierParam, ModifierParam, SideModifierAlias } from './modifier'
 import {
   FromModifierOverloadParam,
   parseFromModifierOverload,
@@ -59,6 +59,25 @@ export function layer(
   return new LayerRuleBuilder(key, varName, onValue, offValue)
 }
 
+export function modifierLayer(
+  modifiers: ModifierParam,
+  key: LayerKeyParam | LayerKeyParam[],
+  varName?: string,
+  onValue: ToVariable['value'] = 1,
+  offValue: ToVariable['value'] = 0,
+) {
+  return layer(key, varName, onValue, offValue).modifiers(modifiers)
+}
+
+export function hyperLayer(
+  key: LayerKeyParam | LayerKeyParam[],
+  varName?: string,
+  onValue: ToVariable['value'] = 1,
+  offValue: ToVariable['value'] = 0,
+) {
+  return modifierLayer('Hyper', key, varName, onValue, offValue)
+}
+
 export class LayerRuleBuilder extends BasicRuleBuilder {
   protected readonly keys: LayerKeyCode[]
   protected varName: string


Test patch:
diff --git a/src/config/layer.test.ts b/src/config/layer.test.ts
index 63f1848..fd081ff 100644
--- a/src/config/layer.test.ts
+++ b/src/config/layer.test.ts
@@ -1,5 +1,5 @@
 import { expect, test } from 'vitest'
-import { layer } from './layer'
+import { hyperLayer, layer } from './layer'
 import { map } from './from'
 import { BasicManipulator } from '../karabiner/karabiner-config'
 import { ifVar } from './condition'
@@ -192,6 +192,16 @@ test('layer().modifier()', () => {
     { mandatory: ['any'] },
   ])
 
+  expect(
+    hyperLayer('a')
+      .manipulators([map(1).to(2)])
+      .build()
+      .manipulators.map((v) => v.from?.modifiers),
+  ).toEqual([
+    { mandatory: ['command', 'option', 'control', 'shift'] },
+    { mandatory: ['any'] },
+  ])
+
   expect(
     layer('a', 'v')
       .modifiers('⌘')
Repository: defi-wonderland/smock
Pull request #75 (2021-09-17 19:45:44)

fix: make sure connect returns the correct factory instance
**Description**
Slightly updates the way we create mock contract factories so that `.connect` also returns a mock contract factory.


Patch:
diff --git a/src/factories/smock-contract.ts b/src/factories/smock-contract.ts
index 54d6c09..9c790c6 100644
--- a/src/factories/smock-contract.ts
+++ b/src/factories/smock-contract.ts
@@ -32,13 +32,11 @@ export async function createFakeContract<Contract extends BaseContract>(
   return fake;
 }
 
-export async function createMockContractFactory<T extends ContractFactory>(
+function mockifyContractFactory<T extends ContractFactory>(
   vm: ObservableVM,
   contractName: string,
-  signerOrOptions?: ethers.Signer | FactoryOptions
-): Promise<MockContractFactory<T>> {
-  const factory = (await hardhatEthers.getContractFactory(contractName, signerOrOptions)) as unknown as MockContractFactory<T>;
-
+  factory: MockContractFactory<T>
+): MockContractFactory<T> {
   const realDeploy = factory.deploy;
   factory.deploy = async (...args: Parameters<T['deploy']>) => {
     const mock = await realDeploy.apply(factory, args);
@@ -58,9 +56,24 @@ export async function createMockContractFactory<T extends ContractFactory>(
     return mock;
   };
 
+  const realConnect = factory.connect;
+  factory.connect = (...args: Parameters<T['connect']>): MockContractFactory<T> => {
+    const newFactory = realConnect.apply(factory, args) as MockContractFactory<T>;
+    return mockifyContractFactory(vm, contractName, newFactory);
+  };
+
   return factory;
 }
 
+export async function createMockContractFactory<T extends ContractFactory>(
+  vm: ObservableVM,
+  contractName: string,
+  signerOrOptions?: ethers.Signer | FactoryOptions
+): Promise<MockContractFactory<T>> {
+  const factory = (await hardhatEthers.getContractFactory(contractName, signerOrOptions)) as unknown as MockContractFactory<T>;
+  return mockifyContractFactory(vm, contractName, factory);
+}
+
 async function initContract(
   vm: ObservableVM,
   address: string,


Test patch:
diff --git a/test/unit/mock/initialization.spec.ts b/test/unit/mock/initialization.spec.ts
index f326c7f..a7b25cd 100644
--- a/test/unit/mock/initialization.spec.ts
+++ b/test/unit/mock/initialization.spec.ts
@@ -21,6 +21,11 @@ describe('Mock: Initialization', () => {
     expect(await mock.callStatic.deployer()).to.equal(deployer.address);
   });
 
+  it('should have the setVariable property after using the connect function', async () => {
+    const mock = await mockFactory.connect(deployer).deploy(0);
+    expect(mock.setVariable).to.not.be.undefined;
+  });
+
   it('should be able to use libraries', async () => {
     const testLibrary = await (await ethers.getContractFactory('TestLibrary')).deploy();
     const librarian = await (