@fincity/kirun-js 3.7.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/engine/util/LinkedListTest.ts +15 -0
- package/__tests__/engine/util/deepEqualTest.ts +62 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/engine/runtime/KIRuntime.ts +1 -0
- package/src/engine/util/LinkedList.ts +1 -1
- package/src/engine/util/deepEqual.ts +29 -7
|
@@ -28,6 +28,21 @@ test('LinkedList Test', () => {
|
|
|
28
28
|
expect(x.toArray()).toStrictEqual([1, 2, 3, 4]);
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
+
test('LinkedList Test - set at every index', () => {
|
|
32
|
+
// the walk in set() used to re-read from head each iteration, so any index
|
|
33
|
+
// of 2 or more wrote over element 1 instead of the requested one
|
|
34
|
+
for (let i = 0; i < 5; i++) {
|
|
35
|
+
const x = new LinkedList([10, 20, 30, 40, 50]);
|
|
36
|
+
x.set(i, 999);
|
|
37
|
+
const expected = [10, 20, 30, 40, 50];
|
|
38
|
+
expected[i] = 999;
|
|
39
|
+
expect(x.toArray()).toStrictEqual(expected);
|
|
40
|
+
}
|
|
41
|
+
const y = new LinkedList([1, 2, 3]);
|
|
42
|
+
expect(() => y.set(-1, 0)).toThrow();
|
|
43
|
+
expect(() => y.set(3, 0)).toThrow();
|
|
44
|
+
});
|
|
45
|
+
|
|
31
46
|
test('LinkedList Test - peekLastTest', () => {
|
|
32
47
|
let x = new LinkedList();
|
|
33
48
|
x.push(230);
|
|
@@ -102,3 +102,65 @@ test('deepEqual', () => {
|
|
|
102
102
|
deepEqual([1, 2, 3, { a: [3, 4], b: null }], [1, 2, 3, { a: [3, 4], b: undefined }]),
|
|
103
103
|
).toBeTruthy();
|
|
104
104
|
});
|
|
105
|
+
|
|
106
|
+
test('deepEqual key sets of the same size but different names', () => {
|
|
107
|
+
expect(deepEqual({ x: 1 }, { y: 1 })).toBeFalsy();
|
|
108
|
+
expect(deepEqual({ a: 1, b: 2 }, { a: 1, c: 2 })).toBeFalsy();
|
|
109
|
+
// a present-but-undefined key still counts towards the key set
|
|
110
|
+
expect(deepEqual({ a: 1 }, { a: 1, b: undefined })).toBeFalsy();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('deepEqual does not conflate falsy values of different types', () => {
|
|
114
|
+
expect(deepEqual(0, '')).toBeFalsy();
|
|
115
|
+
expect(deepEqual(0, false)).toBeFalsy();
|
|
116
|
+
expect(deepEqual({ a: 0 }, { a: false })).toBeFalsy();
|
|
117
|
+
expect(deepEqual([1], null)).toBeFalsy();
|
|
118
|
+
expect(deepEqual(null, [1])).toBeFalsy();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// An array is never equal to a plain object, in either direction. This matches
|
|
122
|
+
// kirun-java (LogicalEqualOperator guards both directions explicitly) and
|
|
123
|
+
// kirun-py (deep_equal rejects on type(a) is not type(b)).
|
|
124
|
+
test('deepEqual never equates an object with an array', () => {
|
|
125
|
+
expect(deepEqual([], {})).toBeFalsy();
|
|
126
|
+
expect(deepEqual({}, [])).toBeFalsy();
|
|
127
|
+
expect(deepEqual([1], { 0: 1 })).toBeFalsy();
|
|
128
|
+
expect(deepEqual({ 0: 1 }, [1])).toBeFalsy();
|
|
129
|
+
expect(deepEqual([1], { a: 1 })).toBeFalsy();
|
|
130
|
+
expect(deepEqual({ a: 1 }, [1])).toBeFalsy();
|
|
131
|
+
// nested, not just at the top level
|
|
132
|
+
expect(deepEqual({ v: {} }, { v: [] })).toBeFalsy();
|
|
133
|
+
expect(deepEqual({ v: [] }, { v: {} })).toBeFalsy();
|
|
134
|
+
expect(deepEqual([[]], [{}])).toBeFalsy();
|
|
135
|
+
// and the cases that must keep working
|
|
136
|
+
expect(deepEqual([], [])).toBeTruthy();
|
|
137
|
+
expect(deepEqual({}, {})).toBeTruthy();
|
|
138
|
+
expect(deepEqual({ v: [1, 2] }, { v: [1, 2] })).toBeTruthy();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('deepEqual short circuits on shared references', () => {
|
|
142
|
+
const shared = { big: Array.from({ length: 1000 }, (_, i) => ({ i })) };
|
|
143
|
+
expect(deepEqual({ v: shared }, { v: shared })).toBeTruthy();
|
|
144
|
+
expect(deepEqual({ v: shared }, { v: { ...shared } })).toBeTruthy();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('deepEqual handles deeply nested values without overflowing the stack', () => {
|
|
148
|
+
const chain = (n: number) => {
|
|
149
|
+
const root: any = {};
|
|
150
|
+
let cur = root;
|
|
151
|
+
for (let i = 0; i < n; i++) {
|
|
152
|
+
cur.next = {};
|
|
153
|
+
cur = cur.next;
|
|
154
|
+
}
|
|
155
|
+
cur.value = 1;
|
|
156
|
+
return root;
|
|
157
|
+
};
|
|
158
|
+
expect(deepEqual(chain(50000), chain(50000))).toBeTruthy();
|
|
159
|
+
|
|
160
|
+
const nestedArray = (n: number) => {
|
|
161
|
+
let a: any = [1];
|
|
162
|
+
for (let i = 0; i < n; i++) a = [a];
|
|
163
|
+
return a;
|
|
164
|
+
};
|
|
165
|
+
expect(deepEqual(nestedArray(50000), nestedArray(50000))).toBeTruthy();
|
|
166
|
+
});
|