|
1 | | -// Copyright (c) Microsoft Corporation. |
| 1 | +// Copyright (c) Microsoft Corporation. |
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | /** |
@@ -46,23 +46,30 @@ function checkEquals(lhs, rhs) { |
46 | 46 | } |
47 | 47 | } |
48 | 48 | } else if (typeof(lhs) === 'object') { |
| 49 | + var props = new Set(); |
| 50 | + var lhsProps = new Set(); // For removal, to validate equality |
49 | 51 | for (var prop in lhs) { |
50 | | - if (!rhs.hasOwnProperty(prop)) { |
51 | | - return { |
52 | | - success: false, |
53 | | - msg: 'Object does not have property \'' + prop + '\'' |
54 | | - }; |
55 | | - } |
| 52 | + props.add(prop); |
| 53 | + lhsProps.add(prop); |
56 | 54 | } |
57 | 55 |
|
58 | 56 | for (var prop in rhs) { |
59 | | - if (!lhs.hasOwnProperty(prop)) { |
| 57 | + if (!lhsProps.delete(prop)) { |
60 | 58 | return { |
61 | 59 | success: false, |
62 | 60 | msg: 'Object does not have property \'' + prop + '\'' |
63 | 61 | }; |
64 | 62 | } |
| 63 | + } |
| 64 | + |
| 65 | + if (lhsProps.size != 0) { |
| 66 | + return { |
| 67 | + success: false, |
| 68 | + msg: 'Object does not have property \'' + lhsProps.values().next().value + '\'' |
| 69 | + }; |
| 70 | + } |
65 | 71 |
|
| 72 | + for (var prop of props) { |
66 | 73 | var result = checkEquals(lhs[prop], rhs[prop]); |
67 | 74 | if (!result.success) return result; |
68 | 75 | } |
@@ -309,16 +316,16 @@ export const TestValues = { |
309 | 316 | propertyValues: { |
310 | 317 | valid: [true, 12723, "hello", { x: 12, y: 23 }, { width: 10, height: 20 }, { x: 12, y: 23, width: 10, height: 20 }, |
311 | 318 | [true, false], [21, 23, 43], ["sasa", "sa"], [{ x: 12, y: 23 }, {x: 24, y: 34}], [{width: 10, height: 20}], |
312 | | - [{ x: 12, y: 23, width: 10, height: 20 }, { x: 12, y: 23, width: 10, height: 20 }], [new TestComponent.TestObject(1)] |
| 319 | + [{ x: 12, y: 23, width: 10, height: 20 }, { x: 12, y: 23, width: 10, height: 20 }], [new TestComponent.TestObject(1)] |
313 | 320 | ], |
314 | 321 | validValueTypePairs: [ |
315 | | - [8, "UInt8"], [8, "Int16"], [8, "UInt16"], [8, "Int32"], [8, "UInt32"], [8, "Int64"], [8, "UInt64"], [8, "Single"], [8, "Double"], |
| 322 | + [8, "UInt8"], [8, "Int16"], [8, "UInt16"], [8, "Int32"], [8, "UInt32"], [8, "Int64"], [8, "UInt64"], [8, "Single"], [8, "Double"], |
316 | 323 | ["a", "Char16"], [true, "Boolean"], ["Hello", "String"], [new Date(2020, 2, 3, 4, 5, 6, 7), "DateTime"], [223213, "TimeSpan"], |
317 | 324 | [{x: 10, y: 20}, "Point"], [{width: 100, height: 200}, "Size"], [{x: 10, y: 20, width: 100, height: 200}, "Rect"], |
318 | 325 | [[8, 9], "UInt8Array"], [[8, 9], "Int16Array"], [[8, 9], "UInt16Array"], [[8, 9], "Int32Array"], [[8, 9], "UInt32Array"], [[8, 9], "Int64Array"], [[8, 9], "UInt64Array"], |
319 | 326 | [[8, 9], "SingleArray"], [[8, 9], "DoubleArray"], [["a", "b"], "Char16Array"], [[true, false], "BooleanArray"], [["Hello", "World"], "StringArray"], |
320 | 327 | [[new Date(2020, 2, 3, 4, 5, 6, 7), new Date(2021, 2, 2, 1, 5, 6, 7)], "DateTimeArray"], [[81212, 932322], "TimeSpanArray"], |
321 | | - [[{x: 10, y: 20}, {x: 10, y: 20}], "PointArray"], [[{width: 100, height: 200}, {width: 100, height: 200}], "SizeArray"], |
| 328 | + [[{x: 10, y: 20}, {x: 10, y: 20}], "PointArray"], [[{width: 100, height: 200}, {width: 100, height: 200}], "SizeArray"], |
322 | 329 | [[{x: 10, y: 20, width: 100, height: 200}], "RectArray"], |
323 | 330 | ], |
324 | 331 | invalid: [{}, ["hi", true], [{ width: 10, height: 20 }, { x: 12, y: 23, width: 10, height: 20 }]] |
|
0 commit comments