-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Pinta365/tests
Tests
- Loading branch information
Showing
7 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Bun CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: antongolub/[email protected] | ||
with: | ||
bun-version: v1.x # Uses latest bun 1 | ||
- run: bun x jsr add @cross/test @std/assert # Installs dependencies | ||
- run: bun test # Runs the tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Deno CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Setup repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Deno | ||
uses: denoland/setup-deno@v1 | ||
with: | ||
deno-version: v1.x | ||
|
||
- name: Verify formatting | ||
run: deno fmt --check | ||
|
||
- name: Run linter | ||
run: deno lint | ||
|
||
- name: Check types | ||
run: deno check mod.ts | ||
|
||
- name: Run tests | ||
run: deno test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Node.js CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x, 21.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- run: npx jsr add @cross/test @std/assert | ||
- run: "echo '{ \"type\": \"module\" }' > package.json" # Needed for tsx to work | ||
- run: npx --yes tsx --test tests/*.test.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
.env | ||
.vscode | ||
test.ts | ||
wip | ||
dev | ||
package.json | ||
package-lock.json | ||
deno.lock | ||
node_modules | ||
bun.lockb | ||
bunfig.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { assertEquals } from "@std/assert"; | ||
import { test } from "@cross/test"; | ||
import { deepMerge, DeepMergeOptions } from "../mod.ts"; | ||
|
||
test("Basic deepMerge scenario", () => { | ||
const options: DeepMergeOptions = { | ||
arrayMergeStrategy: "unique", | ||
setMergeStrategy: "combine", | ||
mapMergeStrategy: "combine", | ||
}; | ||
|
||
const obj1 = { | ||
arr: [1, 2, 3], | ||
mySet: new Set(["a", "b"]), | ||
myMap: new Map([["x", 1], ["y", 2]]), | ||
}; | ||
|
||
const obj2 = { | ||
arr: [3, 4, 5], | ||
mySet: new Set(["c"]), | ||
myMap: new Map([["y", 3]]), | ||
}; | ||
|
||
const merged = deepMerge.withOptions(options, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.arr), [1, 2, 3, 4, 5]); | ||
assertEquals(Array.from(merged.mySet), ["a", "b", "c"]); | ||
assertEquals(Array.from(merged.myMap), [["x", 1], ["y", 3]]); | ||
}); | ||
|
||
test("Array Combine", () => { | ||
const obj1 = { arr: [1, 2, 3] }; | ||
const obj2 = { arr: [3, 4, 5] }; | ||
const merged = deepMerge.withOptions({ arrayMergeStrategy: "combine" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.arr), [1, 2, 3, 3, 4, 5]); | ||
}); | ||
|
||
test("Array Unique", () => { | ||
const obj1 = { arr: [1, 2, 3] }; | ||
const obj2 = { arr: [3, 4, 5] }; | ||
const merged = deepMerge.withOptions({ arrayMergeStrategy: "unique" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.arr), [1, 2, 3, 4, 5]); | ||
}); | ||
|
||
test("Array Replace", () => { | ||
const obj1 = { arr: [1, 2, 3] }; | ||
const obj2 = { arr: [3, 4, 5] }; | ||
const merged = deepMerge.withOptions({ arrayMergeStrategy: "replace" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.arr), [3, 4, 5]); | ||
}); | ||
|
||
test("Set Combine", () => { | ||
const obj1 = { mySet: new Set(["a", "b"]) }; | ||
const obj2 = { mySet: new Set(["c"]) }; | ||
const merged = deepMerge.withOptions({ setMergeStrategy: "combine" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.mySet), ["a", "b", "c"]); | ||
}); | ||
|
||
test("Set Replace", () => { | ||
const obj1 = { mySet: new Set(["a", "b"]) }; | ||
const obj2 = { mySet: new Set(["c"]) }; | ||
const merged = deepMerge.withOptions({ setMergeStrategy: "replace" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.mySet), ["c"]); | ||
}); | ||
|
||
test("Map Combine", () => { | ||
const obj1 = { myMap: new Map([["x", 1], ["y", 2]]) }; | ||
const obj2 = { myMap: new Map([["y", 3]]) }; | ||
const merged = deepMerge.withOptions({ mapMergeStrategy: "combine" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.myMap), [["x", 1], ["y", 3]]); | ||
}); | ||
|
||
test("Map Replace", () => { | ||
const obj1 = { myMap: new Map([["x", 1], ["y", 2]]) }; | ||
const obj2 = { myMap: new Map([["y", 3]]) }; | ||
const merged = deepMerge.withOptions({ mapMergeStrategy: "replace" }, obj1, obj2); | ||
|
||
assertEquals(Array.from(merged.myMap), [["y", 3]]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { assertEquals } from "@std/assert"; | ||
import { test } from "@cross/test"; | ||
import { simpleMerge } from "../mod.ts"; | ||
|
||
test("Basic simpleMerge scenario", () => { | ||
interface MergeableObj { | ||
a?: number; | ||
b?: { | ||
c?: number; | ||
d?: number; | ||
e?: number; | ||
}; | ||
} | ||
|
||
const object1: MergeableObj = { | ||
a: 1, | ||
b: { | ||
c: 2, | ||
d: 1, | ||
e: 3, | ||
}, | ||
}; | ||
const object2: MergeableObj = { | ||
b: { | ||
d: 3, | ||
}, | ||
}; | ||
|
||
const merged = simpleMerge(object1, object2); | ||
assertEquals(merged.a, 1); | ||
assertEquals(typeof merged.b, "object"); | ||
assertEquals(merged.b!.c, 2); | ||
assertEquals(merged.b!.d, 3); | ||
assertEquals(merged.b!.e, 3); | ||
}); |