@fluid-experimental/property-properties 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.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/README.md +1 -0
- package/dist/containerSerializer.d.ts.map +1 -1
- package/dist/containerSerializer.js +5 -5
- package/dist/containerSerializer.js.map +1 -1
- package/dist/enableValidations.js.map +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/properties/abstractStaticCollectionProperty.d.ts +10 -10
- package/dist/properties/abstractStaticCollectionProperty.d.ts.map +1 -1
- package/dist/properties/abstractStaticCollectionProperty.js +70 -53
- package/dist/properties/abstractStaticCollectionProperty.js.map +1 -1
- package/dist/properties/arrayProperty.d.ts.map +1 -1
- package/dist/properties/arrayProperty.js +152 -103
- package/dist/properties/arrayProperty.js.map +1 -1
- package/dist/properties/baseProperty.d.ts +4 -4
- package/dist/properties/baseProperty.d.ts.map +1 -1
- package/dist/properties/baseProperty.js +69 -47
- package/dist/properties/baseProperty.js.map +1 -1
- package/dist/properties/boolProperty.d.ts.map +1 -1
- package/dist/properties/boolProperty.js +3 -3
- package/dist/properties/boolProperty.js.map +1 -1
- package/dist/properties/containerProperty.d.ts +8 -8
- package/dist/properties/containerProperty.d.ts.map +1 -1
- package/dist/properties/containerProperty.js +33 -26
- package/dist/properties/containerProperty.js.map +1 -1
- package/dist/properties/enumArrayProperty.d.ts.map +1 -1
- package/dist/properties/enumArrayProperty.js +14 -14
- package/dist/properties/enumArrayProperty.js.map +1 -1
- package/dist/properties/enumProperty.d.ts.map +1 -1
- package/dist/properties/enumProperty.js +17 -17
- package/dist/properties/enumProperty.js.map +1 -1
- package/dist/properties/floatProperties.js +4 -4
- package/dist/properties/floatProperties.js.map +1 -1
- package/dist/properties/index.d.ts +23 -23
- package/dist/properties/index.d.ts.map +1 -1
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/indexedCollectionBaseProperty.d.ts.map +1 -1
- package/dist/properties/indexedCollectionBaseProperty.js +47 -37
- package/dist/properties/indexedCollectionBaseProperty.js.map +1 -1
- package/dist/properties/intProperties.d.ts.map +1 -1
- package/dist/properties/intProperties.js +10 -10
- package/dist/properties/intProperties.js.map +1 -1
- package/dist/properties/lazyLoadedProperties.js.map +1 -1
- package/dist/properties/mapProperty.d.ts.map +1 -1
- package/dist/properties/mapProperty.js +21 -17
- package/dist/properties/mapProperty.js.map +1 -1
- package/dist/properties/namedNodeProperty.d.ts.map +1 -1
- package/dist/properties/namedNodeProperty.js +3 -3
- package/dist/properties/namedNodeProperty.js.map +1 -1
- package/dist/properties/namedProperty.d.ts.map +1 -1
- package/dist/properties/namedProperty.js +7 -5
- package/dist/properties/namedProperty.js.map +1 -1
- package/dist/properties/nodeProperty.d.ts.map +1 -1
- package/dist/properties/nodeProperty.js +5 -3
- package/dist/properties/nodeProperty.js.map +1 -1
- package/dist/properties/primitiveTypeCasts.d.ts.map +1 -1
- package/dist/properties/primitiveTypeCasts.js +9 -9
- package/dist/properties/primitiveTypeCasts.js.map +1 -1
- package/dist/properties/referenceArrayProperty.d.ts.map +1 -1
- package/dist/properties/referenceArrayProperty.js +31 -25
- package/dist/properties/referenceArrayProperty.js.map +1 -1
- package/dist/properties/referenceMapProperty.d.ts.map +1 -1
- package/dist/properties/referenceMapProperty.js +18 -18
- package/dist/properties/referenceMapProperty.js.map +1 -1
- package/dist/properties/referenceProperty.d.ts.map +1 -1
- package/dist/properties/referenceProperty.js +33 -29
- package/dist/properties/referenceProperty.js.map +1 -1
- package/dist/properties/setProperty.d.ts.map +1 -1
- package/dist/properties/setProperty.js +31 -29
- package/dist/properties/setProperty.js.map +1 -1
- package/dist/properties/stringProperty.d.ts.map +1 -1
- package/dist/properties/stringProperty.js +56 -40
- package/dist/properties/stringProperty.js.map +1 -1
- package/dist/properties/uintProperties.js +5 -5
- package/dist/properties/uintProperties.js.map +1 -1
- package/dist/properties/valueArrayProperty.d.ts +1 -1
- package/dist/properties/valueArrayProperty.d.ts.map +1 -1
- package/dist/properties/valueArrayProperty.js +30 -29
- package/dist/properties/valueArrayProperty.js.map +1 -1
- package/dist/properties/valueMapProperty.d.ts.map +1 -1
- package/dist/properties/valueMapProperty.js +31 -29
- package/dist/properties/valueMapProperty.js.map +1 -1
- package/dist/properties/valueProperty.d.ts.map +1 -1
- package/dist/properties/valueProperty.js +11 -9
- package/dist/properties/valueProperty.js.map +1 -1
- package/dist/propertyFactory.d.ts.map +1 -1
- package/dist/propertyFactory.js +309 -252
- package/dist/propertyFactory.js.map +1 -1
- package/dist/propertyTemplate.d.ts +17 -17
- package/dist/propertyTemplate.d.ts.map +1 -1
- package/dist/propertyTemplate.js +64 -45
- package/dist/propertyTemplate.js.map +1 -1
- package/dist/propertyTemplateWrapper.d.ts.map +1 -1
- package/dist/propertyTemplateWrapper.js +40 -25
- package/dist/propertyTemplateWrapper.js.map +1 -1
- package/dist/propertyUtils.d.ts.map +1 -1
- package/dist/propertyUtils.js.map +1 -1
- package/dist/test/properties/arrayProperty.spec.js +566 -490
- package/dist/test/properties/arrayProperty.spec.js.map +1 -1
- package/dist/test/properties/baseProperty.spec.js +293 -280
- package/dist/test/properties/baseProperty.spec.js.map +1 -1
- package/dist/test/properties/containerProperty.spec.js +100 -94
- package/dist/test/properties/containerProperty.spec.js.map +1 -1
- package/dist/test/properties/customArrayProperty.spec.js +174 -147
- package/dist/test/properties/customArrayProperty.spec.js.map +1 -1
- package/dist/test/properties/enumArrayProperty.spec.js +67 -63
- package/dist/test/properties/enumArrayProperty.spec.js.map +1 -1
- package/dist/test/properties/enumProperty.spec.js +115 -97
- package/dist/test/properties/enumProperty.spec.js.map +1 -1
- package/dist/test/properties/float32.spec.js +5 -5
- package/dist/test/properties/float32.spec.js.map +1 -1
- package/dist/test/properties/int64ArrayProperty.spec.js +157 -93
- package/dist/test/properties/int64ArrayProperty.spec.js.map +1 -1
- package/dist/test/properties/int64MapProperty.spec.js +185 -166
- package/dist/test/properties/int64MapProperty.spec.js.map +1 -1
- package/dist/test/properties/int64Property.spec.js +109 -109
- package/dist/test/properties/int64Property.spec.js.map +1 -1
- package/dist/test/properties/isLeafNode.spec.js +75 -76
- package/dist/test/properties/isLeafNode.spec.js.map +1 -1
- package/dist/test/properties/mapProperty.spec.js +571 -531
- package/dist/test/properties/mapProperty.spec.js.map +1 -1
- package/dist/test/properties/namedNodeProperty.spec.js +31 -31
- package/dist/test/properties/namedNodeProperty.spec.js.map +1 -1
- package/dist/test/properties/nodeProperty.spec.js +805 -795
- package/dist/test/properties/nodeProperty.spec.js.map +1 -1
- package/dist/test/properties/referenceProperty.spec.js +729 -679
- package/dist/test/properties/referenceProperty.spec.js.map +1 -1
- package/dist/test/properties/relationshipProperty.spec.js +16 -16
- package/dist/test/properties/relationshipProperty.spec.js.map +1 -1
- package/dist/test/properties/setProperty.spec.js +288 -227
- package/dist/test/properties/setProperty.spec.js.map +1 -1
- package/dist/test/properties/stringProperty.spec.js +326 -318
- package/dist/test/properties/stringProperty.spec.js.map +1 -1
- package/dist/test/properties/uint64Property.spec.js +46 -36
- package/dist/test/properties/uint64Property.spec.js.map +1 -1
- package/dist/test/properties/valueMapProperty.spec.js +259 -246
- package/dist/test/properties/valueMapProperty.spec.js.map +1 -1
- package/dist/test/properties/valueProperty.spec.js +49 -43
- package/dist/test/properties/valueProperty.spec.js.map +1 -1
- package/dist/test/propertyFactory.spec.js +2038 -1631
- package/dist/test/propertyFactory.spec.js.map +1 -1
- package/dist/test/propertyTemplateWrapper.spec.js +72 -102
- package/dist/test/propertyTemplateWrapper.spec.js.map +1 -1
- package/dist/test/propertyUtils.spec.js +22 -21
- package/dist/test/propertyUtils.spec.js.map +1 -1
- package/dist/test/reversibleChangeset.spec.js +857 -703
- package/dist/test/reversibleChangeset.spec.js.map +1 -1
- package/dist/test/setup.js +5 -5
- package/dist/test/setup.js.map +1 -1
- package/dist/test/tsconfig.tsbuildinfo +1 -1
- package/dist/test/utils.spec.js +1334 -1144
- package/dist/test/utils.spec.js.map +1 -1
- package/dist/test/validation/badMissingSemverInTypeid.js +20 -20
- package/dist/test/validation/badMissingSemverInTypeid.js.map +1 -1
- package/dist/test/validation/badPrimitiveTypeid.js +12 -12
- package/dist/test/validation/badPrimitiveTypeid.js.map +1 -1
- package/dist/test/validation/goodColorId.js +91 -91
- package/dist/test/validation/goodColorId.js.map +1 -1
- package/dist/test/validation/goodColorPalette.js +4 -4
- package/dist/test/validation/goodColorPalette.js.map +1 -1
- package/dist/test/validation/goodPointId.js +20 -20
- package/dist/test/validation/goodPointId.js.map +1 -1
- package/dist/test/validation/reversibleChangeSetTestData.js +23841 -2
- package/dist/test/validation/reversibleChangeSetTestData.js.map +1 -1
- package/lib/containerSerializer.d.ts.map +1 -1
- package/lib/containerSerializer.js +5 -5
- package/lib/containerSerializer.js.map +1 -1
- package/lib/enableValidations.js.map +1 -1
- package/lib/index.d.ts +19 -19
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +19 -19
- package/lib/index.js.map +1 -1
- package/lib/properties/abstractStaticCollectionProperty.d.ts +10 -10
- package/lib/properties/abstractStaticCollectionProperty.d.ts.map +1 -1
- package/lib/properties/abstractStaticCollectionProperty.js +70 -53
- package/lib/properties/abstractStaticCollectionProperty.js.map +1 -1
- package/lib/properties/arrayProperty.d.ts.map +1 -1
- package/lib/properties/arrayProperty.js +152 -103
- package/lib/properties/arrayProperty.js.map +1 -1
- package/lib/properties/baseProperty.d.ts +4 -4
- package/lib/properties/baseProperty.d.ts.map +1 -1
- package/lib/properties/baseProperty.js +73 -51
- package/lib/properties/baseProperty.js.map +1 -1
- package/lib/properties/boolProperty.d.ts.map +1 -1
- package/lib/properties/boolProperty.js +3 -3
- package/lib/properties/boolProperty.js.map +1 -1
- package/lib/properties/containerProperty.d.ts +8 -8
- package/lib/properties/containerProperty.d.ts.map +1 -1
- package/lib/properties/containerProperty.js +33 -26
- package/lib/properties/containerProperty.js.map +1 -1
- package/lib/properties/enumArrayProperty.d.ts.map +1 -1
- package/lib/properties/enumArrayProperty.js +14 -14
- package/lib/properties/enumArrayProperty.js.map +1 -1
- package/lib/properties/enumProperty.d.ts.map +1 -1
- package/lib/properties/enumProperty.js +17 -17
- package/lib/properties/enumProperty.js.map +1 -1
- package/lib/properties/floatProperties.js +4 -4
- package/lib/properties/floatProperties.js.map +1 -1
- package/lib/properties/index.d.ts +23 -23
- package/lib/properties/index.d.ts.map +1 -1
- package/lib/properties/index.js +23 -23
- package/lib/properties/index.js.map +1 -1
- package/lib/properties/indexedCollectionBaseProperty.d.ts.map +1 -1
- package/lib/properties/indexedCollectionBaseProperty.js +47 -37
- package/lib/properties/indexedCollectionBaseProperty.js.map +1 -1
- package/lib/properties/intProperties.d.ts.map +1 -1
- package/lib/properties/intProperties.js +10 -10
- package/lib/properties/intProperties.js.map +1 -1
- package/lib/properties/lazyLoadedProperties.js.map +1 -1
- package/lib/properties/mapProperty.d.ts.map +1 -1
- package/lib/properties/mapProperty.js +21 -17
- package/lib/properties/mapProperty.js.map +1 -1
- package/lib/properties/namedNodeProperty.d.ts.map +1 -1
- package/lib/properties/namedNodeProperty.js +3 -3
- package/lib/properties/namedNodeProperty.js.map +1 -1
- package/lib/properties/namedProperty.d.ts.map +1 -1
- package/lib/properties/namedProperty.js +7 -5
- package/lib/properties/namedProperty.js.map +1 -1
- package/lib/properties/nodeProperty.d.ts.map +1 -1
- package/lib/properties/nodeProperty.js +5 -3
- package/lib/properties/nodeProperty.js.map +1 -1
- package/lib/properties/primitiveTypeCasts.d.ts.map +1 -1
- package/lib/properties/primitiveTypeCasts.js +9 -9
- package/lib/properties/primitiveTypeCasts.js.map +1 -1
- package/lib/properties/referenceArrayProperty.d.ts.map +1 -1
- package/lib/properties/referenceArrayProperty.js +31 -25
- package/lib/properties/referenceArrayProperty.js.map +1 -1
- package/lib/properties/referenceMapProperty.d.ts.map +1 -1
- package/lib/properties/referenceMapProperty.js +18 -18
- package/lib/properties/referenceMapProperty.js.map +1 -1
- package/lib/properties/referenceProperty.d.ts.map +1 -1
- package/lib/properties/referenceProperty.js +33 -29
- package/lib/properties/referenceProperty.js.map +1 -1
- package/lib/properties/setProperty.d.ts.map +1 -1
- package/lib/properties/setProperty.js +31 -29
- package/lib/properties/setProperty.js.map +1 -1
- package/lib/properties/stringProperty.d.ts.map +1 -1
- package/lib/properties/stringProperty.js +56 -40
- package/lib/properties/stringProperty.js.map +1 -1
- package/lib/properties/uintProperties.js +5 -5
- package/lib/properties/uintProperties.js.map +1 -1
- package/lib/properties/valueArrayProperty.d.ts +1 -1
- package/lib/properties/valueArrayProperty.d.ts.map +1 -1
- package/lib/properties/valueArrayProperty.js +30 -29
- package/lib/properties/valueArrayProperty.js.map +1 -1
- package/lib/properties/valueMapProperty.d.ts.map +1 -1
- package/lib/properties/valueMapProperty.js +31 -29
- package/lib/properties/valueMapProperty.js.map +1 -1
- package/lib/properties/valueProperty.d.ts.map +1 -1
- package/lib/properties/valueProperty.js +11 -9
- package/lib/properties/valueProperty.js.map +1 -1
- package/lib/propertyFactory.d.ts.map +1 -1
- package/lib/propertyFactory.js +309 -252
- package/lib/propertyFactory.js.map +1 -1
- package/lib/propertyTemplate.d.ts +17 -17
- package/lib/propertyTemplate.d.ts.map +1 -1
- package/lib/propertyTemplate.js +64 -45
- package/lib/propertyTemplate.js.map +1 -1
- package/lib/propertyTemplateWrapper.d.ts.map +1 -1
- package/lib/propertyTemplateWrapper.js +40 -25
- package/lib/propertyTemplateWrapper.js.map +1 -1
- package/lib/propertyUtils.d.ts.map +1 -1
- package/lib/propertyUtils.js.map +1 -1
- package/package.json +28 -28
- package/src/index.d.ts +2750 -2681
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
* @fileoverview In this file, we will test the functions of a BaseProperty object
|
|
8
8
|
* described in /src/properties/baseProperty.js
|
|
9
9
|
*/
|
|
10
|
-
const { ChangeSet } = require(
|
|
11
|
-
const { MSG } = require(
|
|
12
|
-
const { DeterministicRandomGenerator, HashCalculator } = require("@fluid-experimental/property-common");
|
|
13
|
-
_ = require(
|
|
14
|
-
const { PropertyFactory } = require(
|
|
15
|
-
const { BaseProperty } = require(
|
|
10
|
+
const { ChangeSet } = require("@fluid-experimental/property-changeset");
|
|
11
|
+
const { MSG } = require("@fluid-experimental/property-common").constants;
|
|
12
|
+
const { DeterministicRandomGenerator, HashCalculator, } = require("@fluid-experimental/property-common");
|
|
13
|
+
_ = require("lodash");
|
|
14
|
+
const { PropertyFactory } = require("../..");
|
|
15
|
+
const { BaseProperty } = require("../..");
|
|
16
16
|
const deepCopy = _.cloneDeep;
|
|
17
17
|
const { PATH_TOKENS } = BaseProperty;
|
|
18
18
|
var OurArrayTestTemplate;
|
|
@@ -21,9 +21,9 @@ var testFailed = false;
|
|
|
21
21
|
var changeSet2;
|
|
22
22
|
var conflicts;
|
|
23
23
|
var possibleChanges = {
|
|
24
|
-
0:
|
|
25
|
-
1:
|
|
26
|
-
2:
|
|
24
|
+
0: "insert",
|
|
25
|
+
1: "modify",
|
|
26
|
+
2: "remove",
|
|
27
27
|
};
|
|
28
28
|
var getRandomNumbersArray = function (in_size, randomGenerator) {
|
|
29
29
|
var result = [];
|
|
@@ -44,103 +44,82 @@ var compareArrays = function (ap1, ap2) {
|
|
|
44
44
|
return true;
|
|
45
45
|
};
|
|
46
46
|
var TestArrayFloat32 = {
|
|
47
|
-
typeid:
|
|
48
|
-
properties: [
|
|
49
|
-
{ id: 'data', typeid: 'Float32', context: 'array', length: 3 },
|
|
50
|
-
],
|
|
47
|
+
typeid: "autodesk.test:test.arrayfloat32-1.0.0",
|
|
48
|
+
properties: [{ id: "data", typeid: "Float32", context: "array", length: 3 }],
|
|
51
49
|
};
|
|
52
50
|
var TestArrayString = {
|
|
53
|
-
typeid:
|
|
54
|
-
properties: [
|
|
55
|
-
{ id: 'data', typeid: 'String', context: 'array', length: 3 },
|
|
56
|
-
],
|
|
51
|
+
typeid: "autodesk.test:test.arraystring-1.0.0",
|
|
52
|
+
properties: [{ id: "data", typeid: "String", context: "array", length: 3 }],
|
|
57
53
|
};
|
|
58
54
|
var TestArrayBool = {
|
|
59
|
-
typeid:
|
|
60
|
-
properties: [
|
|
61
|
-
{ id: 'data', typeid: 'Bool', context: 'array', length: 3 },
|
|
62
|
-
],
|
|
55
|
+
typeid: "autodesk.test:test.arraybool-1.0.0",
|
|
56
|
+
properties: [{ id: "data", typeid: "Bool", context: "array", length: 3 }],
|
|
63
57
|
};
|
|
64
58
|
var TestString = {
|
|
65
|
-
typeid:
|
|
66
|
-
properties: [
|
|
67
|
-
{ id: 'data', typeid: 'String' },
|
|
68
|
-
],
|
|
59
|
+
typeid: "autodesk.test:test.string-1.0.0",
|
|
60
|
+
properties: [{ id: "data", typeid: "String" }],
|
|
69
61
|
};
|
|
70
62
|
var TestCustomArray = {
|
|
71
|
-
typeid:
|
|
63
|
+
typeid: "autodesk.test:test.customarray-1.0.0",
|
|
72
64
|
properties: [
|
|
73
|
-
{ id:
|
|
65
|
+
{ id: "data", typeid: "autodesk.test:test.string-1.0.0", context: "array", length: 3 },
|
|
74
66
|
],
|
|
75
67
|
};
|
|
76
68
|
var TestDynamicLengthArray = {
|
|
77
|
-
typeid:
|
|
78
|
-
properties: [
|
|
79
|
-
{ id: 'data', typeid: 'Int32', context: 'array' },
|
|
80
|
-
],
|
|
69
|
+
typeid: "autodesk.test:test.dynamicArray-1.0.0",
|
|
70
|
+
properties: [{ id: "data", typeid: "Int32", context: "array" }],
|
|
81
71
|
};
|
|
82
72
|
var TestDynamicLengthNonPrimitiveArray = {
|
|
83
|
-
typeid:
|
|
84
|
-
properties: [
|
|
85
|
-
{ id: 'data', typeid: 'autodesk.test:test.string-1.0.0', context: 'array' },
|
|
86
|
-
],
|
|
73
|
+
typeid: "autodesk.test:test.nonPrimitiveArray-1.0.0",
|
|
74
|
+
properties: [{ id: "data", typeid: "autodesk.test:test.string-1.0.0", context: "array" }],
|
|
87
75
|
};
|
|
88
76
|
var OurArrayTestTemplate = {
|
|
89
|
-
typeid:
|
|
90
|
-
properties: [
|
|
91
|
-
{ id: 'MyArray', typeid: 'Float32', context: 'array' },
|
|
92
|
-
],
|
|
77
|
+
typeid: "autodesk.tests:ArrayTestID-1.0.0",
|
|
78
|
+
properties: [{ id: "MyArray", typeid: "Float32", context: "array" }],
|
|
93
79
|
};
|
|
94
80
|
var NestedArrayTestTemplate = {
|
|
95
|
-
typeid:
|
|
81
|
+
typeid: "autodesk.tests:NestedArrayTest-1.0.0",
|
|
96
82
|
properties: [
|
|
97
83
|
{
|
|
98
|
-
id:
|
|
99
|
-
|
|
100
|
-
],
|
|
84
|
+
id: "nest",
|
|
85
|
+
properties: [{ id: "MyArray", typeid: "Float32", context: "array" }],
|
|
101
86
|
},
|
|
102
87
|
],
|
|
103
88
|
};
|
|
104
89
|
var ComplexTemplate = {
|
|
105
|
-
typeid:
|
|
90
|
+
typeid: "autodesk.tests:ComplexProp-1.0.0",
|
|
106
91
|
properties: [
|
|
107
92
|
{
|
|
108
|
-
id:
|
|
109
|
-
|
|
110
|
-
],
|
|
93
|
+
id: "nest",
|
|
94
|
+
properties: [{ id: "data", typeid: "Float32" }],
|
|
111
95
|
},
|
|
112
96
|
],
|
|
113
97
|
};
|
|
114
98
|
var ComplexTemplate2 = {
|
|
115
|
-
typeid:
|
|
99
|
+
typeid: "autodesk.tests:ComplexProp2-1.0.0",
|
|
116
100
|
properties: [
|
|
117
101
|
{
|
|
118
|
-
id:
|
|
119
|
-
|
|
120
|
-
],
|
|
102
|
+
id: "nest",
|
|
103
|
+
properties: [{ id: "data2", typeid: "Float32" }],
|
|
121
104
|
},
|
|
122
105
|
],
|
|
123
106
|
};
|
|
124
107
|
var ComplexTemplate3 = {
|
|
125
|
-
typeid:
|
|
108
|
+
typeid: "autodesk.tests:ComplexProp3-1.0.0",
|
|
126
109
|
properties: [
|
|
127
|
-
{ id:
|
|
128
|
-
{ id:
|
|
110
|
+
{ id: "complex1", typeid: "autodesk.tests:ComplexProp-1.0.0" },
|
|
111
|
+
{ id: "complex2", typeid: "autodesk.tests:ComplexProp2-1.0.0" },
|
|
129
112
|
],
|
|
130
113
|
};
|
|
131
114
|
var ComplexArrayTemplate = {
|
|
132
|
-
typeid:
|
|
133
|
-
properties: [
|
|
134
|
-
{ id: 'myarray', typeid: 'autodesk.tests:ComplexProp-1.0.0', context: 'array' },
|
|
135
|
-
],
|
|
115
|
+
typeid: "autodesk.tests:ComplexArray-1.0.0",
|
|
116
|
+
properties: [{ id: "myarray", typeid: "autodesk.tests:ComplexProp-1.0.0", context: "array" }],
|
|
136
117
|
};
|
|
137
118
|
var Complex3ArrayTemplate = {
|
|
138
|
-
typeid:
|
|
139
|
-
properties: [
|
|
140
|
-
{ id: 'myarray', typeid: 'autodesk.tests:ComplexProp3-1.0.0', context: 'array' },
|
|
141
|
-
],
|
|
119
|
+
typeid: "autodesk.tests:Complex3Array-1.0.0",
|
|
120
|
+
properties: [{ id: "myarray", typeid: "autodesk.tests:ComplexProp3-1.0.0", context: "array" }],
|
|
142
121
|
};
|
|
143
|
-
describe(
|
|
122
|
+
describe("ArrayProperty", function () {
|
|
144
123
|
/**
|
|
145
124
|
* Get all the objects we need in this test here.
|
|
146
125
|
*/
|
|
@@ -160,206 +139,227 @@ describe('ArrayProperty', function () {
|
|
|
160
139
|
PropertyFactory._reregister(ComplexTemplate3);
|
|
161
140
|
PropertyFactory._reregister(Complex3ArrayTemplate);
|
|
162
141
|
});
|
|
163
|
-
describe(
|
|
142
|
+
describe("API methods - non primitive arrays", function () {
|
|
164
143
|
var myProp, stringProp1, stringProp2, stringProp3, stringProp4, myArray;
|
|
165
144
|
before(function () {
|
|
166
|
-
myProp = PropertyFactory.create(
|
|
167
|
-
stringProp1 = PropertyFactory.create(
|
|
168
|
-
stringProp2 = PropertyFactory.create(
|
|
169
|
-
stringProp3 = PropertyFactory.create(
|
|
170
|
-
stringProp4 = PropertyFactory.create(
|
|
171
|
-
myArray = myProp.get(
|
|
172
|
-
});
|
|
173
|
-
it(
|
|
145
|
+
myProp = PropertyFactory.create("autodesk.test:test.nonPrimitiveArray-1.0.0");
|
|
146
|
+
stringProp1 = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
147
|
+
stringProp2 = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
148
|
+
stringProp3 = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
149
|
+
stringProp4 = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
150
|
+
myArray = myProp.get("data");
|
|
151
|
+
});
|
|
152
|
+
it(".clear should remove all items from an array and return nothing", function () {
|
|
174
153
|
myArray.push(stringProp1);
|
|
175
154
|
myArray.push(stringProp2);
|
|
176
155
|
expect(myArray.length).to.equal(2);
|
|
177
156
|
expect(myArray.clear()).to.equal(undefined);
|
|
178
157
|
expect(myArray.length).to.equal(0);
|
|
179
158
|
});
|
|
180
|
-
it(
|
|
181
|
-
expect(function () {
|
|
182
|
-
|
|
159
|
+
it(".clear should work on an empty array", function () {
|
|
160
|
+
expect(function () {
|
|
161
|
+
myArray.clear();
|
|
162
|
+
}).to.not.throw();
|
|
163
|
+
expect(function () {
|
|
164
|
+
myArray.clear();
|
|
165
|
+
}).to.not.throw();
|
|
183
166
|
});
|
|
184
|
-
it(
|
|
167
|
+
it(".get should return a property", function () {
|
|
185
168
|
myArray.push(stringProp1);
|
|
186
169
|
var result = myArray.get(0) instanceof BaseProperty;
|
|
187
170
|
expect(result).to.be.true;
|
|
188
171
|
expect(myArray.get(0)).to.deep.equal(stringProp1);
|
|
189
172
|
});
|
|
190
|
-
it(
|
|
191
|
-
let root = PropertyFactory.create(
|
|
192
|
-
let reference = PropertyFactory.create(
|
|
193
|
-
let reference2 = PropertyFactory.create(
|
|
194
|
-
let reference3 = PropertyFactory.create(
|
|
195
|
-
let reference4 = PropertyFactory.create(
|
|
196
|
-
let reference5 = PropertyFactory.create(
|
|
197
|
-
let target = PropertyFactory.create(
|
|
198
|
-
root.insert(
|
|
199
|
-
root.insert(
|
|
200
|
-
root.insert(
|
|
201
|
-
root.insert(
|
|
202
|
-
root.insert(
|
|
203
|
-
root.insert(
|
|
173
|
+
it(".get should return a target deferenced by a chain of reference properties", function () {
|
|
174
|
+
let root = PropertyFactory.create("NodeProperty");
|
|
175
|
+
let reference = PropertyFactory.create("Reference");
|
|
176
|
+
let reference2 = PropertyFactory.create("Reference");
|
|
177
|
+
let reference3 = PropertyFactory.create("Reference");
|
|
178
|
+
let reference4 = PropertyFactory.create("Reference");
|
|
179
|
+
let reference5 = PropertyFactory.create("Reference");
|
|
180
|
+
let target = PropertyFactory.create("String");
|
|
181
|
+
root.insert("array", myProp);
|
|
182
|
+
root.insert("reference", reference);
|
|
183
|
+
root.insert("reference2", reference2);
|
|
184
|
+
root.insert("reference3", reference3);
|
|
185
|
+
root.insert("reference4", reference4);
|
|
186
|
+
root.insert("target", target);
|
|
204
187
|
reference.set(target);
|
|
205
|
-
reference2.set(
|
|
206
|
-
reference3.set(
|
|
207
|
-
reference4.set(
|
|
208
|
-
reference5.set(
|
|
188
|
+
reference2.set("/reference");
|
|
189
|
+
reference3.set("/reference2");
|
|
190
|
+
reference4.set("/reference3");
|
|
191
|
+
reference5.set("/reference4");
|
|
209
192
|
myArray.push(reference5);
|
|
210
193
|
expect(myArray.get(0)).to.deep.equal(target);
|
|
211
194
|
root.clear();
|
|
212
195
|
});
|
|
213
|
-
it(
|
|
214
|
-
let root = PropertyFactory.create(
|
|
215
|
-
let reference = PropertyFactory.create(
|
|
216
|
-
let reference2 = PropertyFactory.create(
|
|
217
|
-
let reference3 = PropertyFactory.create(
|
|
218
|
-
let reference4 = PropertyFactory.create(
|
|
219
|
-
let reference5 = PropertyFactory.create(
|
|
220
|
-
let target = PropertyFactory.create(
|
|
221
|
-
root.insert(
|
|
222
|
-
root.insert(
|
|
223
|
-
root.insert(
|
|
224
|
-
root.insert(
|
|
225
|
-
root.insert(
|
|
226
|
-
root.insert(
|
|
196
|
+
it(".get should return a target deferenced by a chain of reference properties with *", function () {
|
|
197
|
+
let root = PropertyFactory.create("NodeProperty");
|
|
198
|
+
let reference = PropertyFactory.create("Reference");
|
|
199
|
+
let reference2 = PropertyFactory.create("Reference");
|
|
200
|
+
let reference3 = PropertyFactory.create("Reference");
|
|
201
|
+
let reference4 = PropertyFactory.create("Reference");
|
|
202
|
+
let reference5 = PropertyFactory.create("Reference");
|
|
203
|
+
let target = PropertyFactory.create("String");
|
|
204
|
+
root.insert("array", myProp);
|
|
205
|
+
root.insert("reference", reference);
|
|
206
|
+
root.insert("reference2", reference2);
|
|
207
|
+
root.insert("reference3", reference3);
|
|
208
|
+
root.insert("reference4", reference4);
|
|
209
|
+
root.insert("target", target);
|
|
227
210
|
reference.set(target);
|
|
228
|
-
reference2.set(
|
|
229
|
-
reference3.set(
|
|
230
|
-
reference4.set(
|
|
231
|
-
reference5.set(
|
|
211
|
+
reference2.set("/reference");
|
|
212
|
+
reference3.set("/reference2*");
|
|
213
|
+
reference4.set("/reference3");
|
|
214
|
+
reference5.set("/reference4");
|
|
232
215
|
myArray.push(reference5);
|
|
233
216
|
expect(myArray.get(0)).to.deep.equal(reference2);
|
|
234
217
|
root.clear();
|
|
235
218
|
});
|
|
236
|
-
it(
|
|
237
|
-
var myComplexArray = PropertyFactory.create(
|
|
238
|
-
|
|
219
|
+
it(".get should work with an array to return nested values", function () {
|
|
220
|
+
var myComplexArray = PropertyFactory.create("autodesk.tests:ComplexArray-1.0.0")
|
|
221
|
+
._properties.myarray;
|
|
222
|
+
var myComplexProp = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
239
223
|
myComplexArray.push(myComplexProp);
|
|
240
|
-
expect(myComplexArray.get([0,
|
|
241
|
-
});
|
|
242
|
-
it(
|
|
243
|
-
var testProperty1 = PropertyFactory.create(
|
|
244
|
-
testProperty1.get(
|
|
245
|
-
var testProperty2 = PropertyFactory.create(
|
|
246
|
-
testProperty2.get(
|
|
247
|
-
var myArray1 = PropertyFactory.create(
|
|
224
|
+
expect(myComplexArray.get([0, "nest"])).to.deep.equal(myComplexArray.get(0).get("nest"));
|
|
225
|
+
});
|
|
226
|
+
it(".get should work with an array as input", function () {
|
|
227
|
+
var testProperty1 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
228
|
+
testProperty1.get("nest").get("data").setValue(1);
|
|
229
|
+
var testProperty2 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
230
|
+
testProperty2.get("nest").get("data").setValue(2);
|
|
231
|
+
var myArray1 = PropertyFactory.create("autodesk.tests:ComplexArray-1.0.0")._properties
|
|
232
|
+
.myarray;
|
|
248
233
|
myArray1.push(testProperty1);
|
|
249
234
|
myArray1.push(testProperty2);
|
|
250
|
-
expect(myArray1.get([0,
|
|
251
|
-
});
|
|
252
|
-
it(
|
|
253
|
-
var testProperty1 = PropertyFactory.create(
|
|
254
|
-
testProperty1.get(
|
|
255
|
-
var testProperty2 = PropertyFactory.create(
|
|
256
|
-
testProperty2.get(
|
|
257
|
-
var myArray1 = PropertyFactory.create(
|
|
235
|
+
expect(myArray1.get([0, "nest", "data"]).getValue()).to.equal(1);
|
|
236
|
+
});
|
|
237
|
+
it(".get should accept raise level tokens", function () {
|
|
238
|
+
var testProperty1 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
239
|
+
testProperty1.get("nest").get("data").setValue(7);
|
|
240
|
+
var testProperty2 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
241
|
+
testProperty2.get("nest").get("data").setValue(8);
|
|
242
|
+
var myArray1 = PropertyFactory.create("autodesk.tests:ComplexArray-1.0.0")._properties
|
|
243
|
+
.myarray;
|
|
258
244
|
myArray1.push(testProperty1);
|
|
259
245
|
myArray1.push(testProperty2);
|
|
260
|
-
expect(myArray1
|
|
261
|
-
|
|
246
|
+
expect(myArray1
|
|
247
|
+
.get([
|
|
248
|
+
PATH_TOKENS.UP,
|
|
249
|
+
"myarray",
|
|
250
|
+
0,
|
|
251
|
+
"nest",
|
|
252
|
+
PATH_TOKENS.UP,
|
|
253
|
+
PATH_TOKENS.UP,
|
|
254
|
+
1,
|
|
255
|
+
"nest",
|
|
256
|
+
"data",
|
|
257
|
+
])
|
|
262
258
|
.getValue()).to.equal(8);
|
|
263
259
|
});
|
|
264
|
-
it(
|
|
265
|
-
var testProperty1 = PropertyFactory.create(
|
|
266
|
-
testProperty1.get(
|
|
267
|
-
var testProperty2 = PropertyFactory.create(
|
|
268
|
-
testProperty2.get(
|
|
269
|
-
var testProperty3 = PropertyFactory.create(
|
|
270
|
-
testProperty3.get(
|
|
271
|
-
var myArrayProp = PropertyFactory.create(
|
|
260
|
+
it(".get should accept path root tokens", function () {
|
|
261
|
+
var testProperty1 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
262
|
+
testProperty1.get("nest").get("data").setValue(3);
|
|
263
|
+
var testProperty2 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
264
|
+
testProperty2.get("nest").get("data").setValue(6);
|
|
265
|
+
var testProperty3 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
266
|
+
testProperty3.get("nest").get("data").setValue(9);
|
|
267
|
+
var myArrayProp = PropertyFactory.create("autodesk.tests:ComplexArray-1.0.0");
|
|
272
268
|
var myArray1 = myArrayProp._properties.myarray;
|
|
273
269
|
myArray1.insertRange(0, [testProperty1, testProperty2, testProperty3]);
|
|
274
270
|
expect(myArray1.get([PATH_TOKENS.ROOT])).to.equal(myArrayProp);
|
|
275
|
-
expect(myArray1.get([PATH_TOKENS.ROOT,
|
|
271
|
+
expect(myArray1.get([PATH_TOKENS.ROOT, "myarray", 2])).to.equal(testProperty3);
|
|
276
272
|
});
|
|
277
|
-
it(
|
|
273
|
+
it(".getEntriesReadOnly should return an array", function () {
|
|
278
274
|
myArray.push(stringProp1);
|
|
279
275
|
myArray.push(stringProp2);
|
|
280
276
|
expect(myArray.getEntriesReadOnly()).to.deep.equal([stringProp1, stringProp2]);
|
|
281
277
|
});
|
|
282
|
-
it(
|
|
278
|
+
it(".getFullTypeid will return a string of the full type id with or without collection", function () {
|
|
283
279
|
// defaults to false
|
|
284
|
-
expect(myArray.getFullTypeid()).to.equal(
|
|
280
|
+
expect(myArray.getFullTypeid()).to.equal("array<autodesk.test:test.string-1.0.0>");
|
|
285
281
|
// in_hideCollection: true
|
|
286
|
-
expect(myArray.getFullTypeid(true)).to.equal(
|
|
282
|
+
expect(myArray.getFullTypeid(true)).to.equal("autodesk.test:test.string-1.0.0");
|
|
287
283
|
});
|
|
288
|
-
it(
|
|
284
|
+
it(".getIds should return an array of string indexes", function () {
|
|
289
285
|
myArray.push(stringProp1);
|
|
290
286
|
myArray.push(stringProp2);
|
|
291
|
-
expect(myArray.getIds()).to.deep.equal([
|
|
287
|
+
expect(myArray.getIds()).to.deep.equal(["0", "1"]);
|
|
292
288
|
});
|
|
293
|
-
it(
|
|
289
|
+
it(".getLength should return the length of the array", function () {
|
|
294
290
|
expect(myArray.getLength()).to.equal(0);
|
|
295
291
|
myArray.push(stringProp1);
|
|
296
292
|
myArray.push(stringProp2);
|
|
297
293
|
expect(myArray.getLength()).to.equal(2);
|
|
298
294
|
});
|
|
299
|
-
it(
|
|
295
|
+
it(".has should work", function () {
|
|
300
296
|
myArray.push(stringProp1);
|
|
301
297
|
myArray.push(stringProp2);
|
|
302
298
|
expect(myArray.has(1)).to.be.true;
|
|
303
299
|
expect(myArray.has(2)).to.be.false;
|
|
304
300
|
});
|
|
305
|
-
it(
|
|
306
|
-
var testProperty1 = PropertyFactory.create(
|
|
307
|
-
var testProperty2 = PropertyFactory.create(
|
|
308
|
-
var myArray1 = PropertyFactory.create(
|
|
301
|
+
it(".getRelativePath should return a valid path", function () {
|
|
302
|
+
var testProperty1 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
303
|
+
var testProperty2 = PropertyFactory.create("autodesk.tests:ComplexProp-1.0.0");
|
|
304
|
+
var myArray1 = PropertyFactory.create("autodesk.tests:ComplexArray-1.0.0")._properties
|
|
305
|
+
.myarray;
|
|
309
306
|
myArray1.push(testProperty1);
|
|
310
307
|
myArray1.push(testProperty2);
|
|
311
|
-
expect(myArray1.get([0,
|
|
312
|
-
expect(myArray1.getRelativePath(myArray1.get([0,
|
|
313
|
-
expect(myArray1.get([0,
|
|
314
|
-
.to.equal('../../../[0].nest');
|
|
308
|
+
expect(myArray1.get([0, "nest", "data"]).getRelativePath(myArray1)).to.equal("[0].nest.data");
|
|
309
|
+
expect(myArray1.getRelativePath(myArray1.get([0, "nest", "data"]))).to.equal("../../../");
|
|
310
|
+
expect(myArray1.get([0, "nest"]).getRelativePath(myArray1.get([1, "nest", "data"]))).to.equal("../../../[0].nest");
|
|
315
311
|
});
|
|
316
|
-
it(
|
|
312
|
+
it(".getValues should return an array of objects", function () {
|
|
317
313
|
myArray.push(stringProp1);
|
|
318
314
|
myArray.push(stringProp2);
|
|
319
315
|
myArray.setValues({
|
|
320
316
|
0: {
|
|
321
|
-
data:
|
|
317
|
+
data: "newTest",
|
|
322
318
|
},
|
|
323
319
|
});
|
|
324
320
|
expect(myArray.getValues()).to.deep.equal([
|
|
325
321
|
{
|
|
326
|
-
data:
|
|
322
|
+
data: "newTest",
|
|
327
323
|
},
|
|
328
324
|
{
|
|
329
|
-
data:
|
|
325
|
+
data: "",
|
|
330
326
|
},
|
|
331
327
|
]);
|
|
332
328
|
});
|
|
333
|
-
it(
|
|
329
|
+
it(".insert should insert a new property in a non primitive array", function () {
|
|
334
330
|
myArray.insert(0, stringProp1);
|
|
335
331
|
expect(myArray.getLength()).to.equal(1);
|
|
336
332
|
expect(myArray.get(0)).to.deep.equal(stringProp1);
|
|
337
333
|
myArray.insert(1, stringProp2);
|
|
338
334
|
expect(myArray.getLength()).to.equal(2);
|
|
339
335
|
});
|
|
340
|
-
it(
|
|
336
|
+
it(".insert should push existing values to the right if index already has a property", function () {
|
|
341
337
|
myArray.insert(0, stringProp1);
|
|
342
338
|
myArray.insert(0, stringProp2);
|
|
343
339
|
expect(myArray.getEntriesReadOnly()).to.deep.equal([stringProp2, stringProp1]);
|
|
344
340
|
});
|
|
345
|
-
it(
|
|
341
|
+
it(".insertRange should insert new properties", function () {
|
|
346
342
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
347
343
|
expect(myArray.getLength()).to.equal(2);
|
|
348
344
|
expect(myArray.get(1)).to.deep.equal(stringProp2);
|
|
349
345
|
});
|
|
350
|
-
it(
|
|
346
|
+
it(".insertRange should push existing values to the right if index already has a property", function () {
|
|
351
347
|
myArray.insert(0, stringProp1);
|
|
352
348
|
myArray.insertRange(0, [stringProp2, stringProp3]);
|
|
353
|
-
expect(myArray.getEntriesReadOnly()).to.deep.equal([
|
|
349
|
+
expect(myArray.getEntriesReadOnly()).to.deep.equal([
|
|
350
|
+
stringProp2,
|
|
351
|
+
stringProp3,
|
|
352
|
+
stringProp1,
|
|
353
|
+
]);
|
|
354
354
|
});
|
|
355
|
-
it(
|
|
356
|
-
var myDynamicArray = PropertyFactory.create(
|
|
355
|
+
it("pop should remove only last element of an array and return the removed element", function () {
|
|
356
|
+
var myDynamicArray = PropertyFactory.create("autodesk.test:test.nonPrimitiveArray-1.0.0")._properties.data;
|
|
357
357
|
expect(myDynamicArray.length).to.equal(0);
|
|
358
|
-
var firstString = PropertyFactory.create(
|
|
359
|
-
var secondString = PropertyFactory.create(
|
|
360
|
-
var thirdString = PropertyFactory.create(
|
|
361
|
-
var fourthString = PropertyFactory.create(
|
|
362
|
-
var fifthString = PropertyFactory.create(
|
|
358
|
+
var firstString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
359
|
+
var secondString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
360
|
+
var thirdString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
361
|
+
var fourthString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
362
|
+
var fifthString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
363
363
|
myDynamicArray.push(firstString);
|
|
364
364
|
myDynamicArray.push(secondString);
|
|
365
365
|
myDynamicArray.push(thirdString);
|
|
@@ -380,14 +380,16 @@ describe('ArrayProperty', function () {
|
|
|
380
380
|
myDynamicArray.pop();
|
|
381
381
|
myDynamicArray.pop();
|
|
382
382
|
expect(myDynamicArray.length).to.equal(0);
|
|
383
|
-
expect(function () {
|
|
383
|
+
expect(function () {
|
|
384
|
+
myDynamicArray.get(1);
|
|
385
|
+
}).to.throw(Error);
|
|
384
386
|
expect(myDynamicArray.pop()).to.equal(undefined);
|
|
385
387
|
});
|
|
386
|
-
it(
|
|
387
|
-
var myDynamicArray = PropertyFactory.create(
|
|
388
|
+
it("push should add the element to the last position and return the new length of the array", function () {
|
|
389
|
+
var myDynamicArray = PropertyFactory.create("autodesk.test:test.nonPrimitiveArray-1.0.0")._properties.data;
|
|
388
390
|
expect(myDynamicArray.length).to.equal(0);
|
|
389
|
-
var firstString = PropertyFactory.create(
|
|
390
|
-
var secondString = PropertyFactory.create(
|
|
391
|
+
var firstString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
392
|
+
var secondString = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
391
393
|
expect(myDynamicArray.push(firstString)).to.equal(1);
|
|
392
394
|
myDynamicArray.push(secondString);
|
|
393
395
|
expect(myDynamicArray.length).to.equal(2);
|
|
@@ -397,7 +399,7 @@ describe('ArrayProperty', function () {
|
|
|
397
399
|
myDynamicArray.get(2);
|
|
398
400
|
}).to.throw(Error);
|
|
399
401
|
});
|
|
400
|
-
it(
|
|
402
|
+
it(".remove should remove an element from an array, moving remaining elements to the left", function () {
|
|
401
403
|
myArray.push(stringProp1);
|
|
402
404
|
myArray.push(stringProp2);
|
|
403
405
|
myArray.remove(1);
|
|
@@ -406,7 +408,7 @@ describe('ArrayProperty', function () {
|
|
|
406
408
|
myArray.remove(0);
|
|
407
409
|
expect(myArray.getEntriesReadOnly()).to.deep.equal([stringProp3]);
|
|
408
410
|
});
|
|
409
|
-
it(
|
|
411
|
+
it(".removeRange should remove a range of elements from an array and move the remaining elements to the left", function () {
|
|
410
412
|
myArray.push(stringProp1);
|
|
411
413
|
myArray.push(stringProp2);
|
|
412
414
|
myArray.push(stringProp3);
|
|
@@ -414,75 +416,83 @@ describe('ArrayProperty', function () {
|
|
|
414
416
|
myArray.removeRange(0, 2);
|
|
415
417
|
expect(myArray.getEntriesReadOnly()).to.deep.equal([stringProp3]);
|
|
416
418
|
});
|
|
417
|
-
it(
|
|
419
|
+
it(".remove and .removeRange should return the items deleted", function () {
|
|
418
420
|
myArray.push(stringProp1);
|
|
419
421
|
myArray.push(stringProp2);
|
|
420
422
|
myArray.push(stringProp3);
|
|
421
423
|
expect(myArray.remove(0)).to.deep.equal(stringProp1);
|
|
422
424
|
expect(myArray.removeRange(0, 2)).to.deep.equal([stringProp2, stringProp3]);
|
|
423
425
|
});
|
|
424
|
-
it(
|
|
426
|
+
it(".set changes an existing element", function () {
|
|
425
427
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
426
428
|
myArray.set(1, stringProp3);
|
|
427
429
|
expect(myArray.getEntriesReadOnly()).to.deep.equal([stringProp1, stringProp3]);
|
|
428
430
|
});
|
|
429
|
-
it(
|
|
431
|
+
it(".setRange changes a range of existing elements", function () {
|
|
430
432
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
431
433
|
myArray.setRange(0, [stringProp3, stringProp4]);
|
|
432
434
|
expect(myArray.getEntriesReadOnly()).to.deep.equal([stringProp3, stringProp4]);
|
|
433
435
|
});
|
|
434
|
-
it(
|
|
436
|
+
it(".set and .setRange should throw if trying to set a non-existing element", function () {
|
|
435
437
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
436
438
|
var incorrectFn1 = function () {
|
|
437
439
|
myArray.set(3, stringProp3);
|
|
438
440
|
};
|
|
439
441
|
expect(incorrectFn1).to.throw(MSG.SET_OUT_OF_BOUNDS);
|
|
440
442
|
});
|
|
441
|
-
it(
|
|
443
|
+
it(".setRange should throw if the offset is not an integer", function () {
|
|
442
444
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
443
|
-
expect(() => {
|
|
445
|
+
expect(() => {
|
|
446
|
+
myArray.setRange("test", [stringProp3, stringProp4]);
|
|
447
|
+
}).to.throw(MSG.NOT_NUMBER);
|
|
444
448
|
});
|
|
445
|
-
it(
|
|
449
|
+
it(".setRange should throw if the in_array argument is not an array", function () {
|
|
446
450
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
447
|
-
expect(() => {
|
|
451
|
+
expect(() => {
|
|
452
|
+
myArray.setRange(1, stringProp3);
|
|
453
|
+
}).to.throw(MSG.IN_ARRAY_NOT_ARRAY + "ArrayProperty.setRange");
|
|
448
454
|
});
|
|
449
|
-
it(
|
|
455
|
+
it(".set should throw if the offset is not an integer", function () {
|
|
450
456
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
451
|
-
expect(() => {
|
|
457
|
+
expect(() => {
|
|
458
|
+
myArray.set("test", stringProp3);
|
|
459
|
+
}).to.throw(MSG.NOT_NUMBER);
|
|
452
460
|
});
|
|
453
|
-
it(
|
|
461
|
+
it(".set should throw if the in_value is an array", function () {
|
|
454
462
|
myArray.insertRange(0, [stringProp1, stringProp2]);
|
|
455
|
-
expect(() => {
|
|
463
|
+
expect(() => {
|
|
464
|
+
myArray.set(0, [stringProp3, stringProp4]);
|
|
465
|
+
}).to.throw(MSG.ARRAY_SET_ONE_ELEMENT);
|
|
456
466
|
});
|
|
457
|
-
it(
|
|
467
|
+
it(".setValues should work for custom type arrays", function () {
|
|
458
468
|
myArray.push(stringProp1);
|
|
459
469
|
myArray.push(stringProp2);
|
|
460
470
|
myArray.setValues({
|
|
461
471
|
0: {
|
|
462
|
-
data:
|
|
472
|
+
data: "newTest",
|
|
463
473
|
},
|
|
464
474
|
});
|
|
465
|
-
expect(myArray.getValues()).to.deep.equal([{ data:
|
|
466
|
-
stringProp3._properties.data.setValue(
|
|
475
|
+
expect(myArray.getValues()).to.deep.equal([{ data: "newTest" }, { data: "" }]);
|
|
476
|
+
stringProp3._properties.data.setValue("newNewTest");
|
|
467
477
|
myArray.setValues([stringProp3]);
|
|
468
478
|
expect(myArray.getLength()).to.equal(1);
|
|
469
|
-
expect(myArray.getValues()).to.deep.equal([{ data:
|
|
479
|
+
expect(myArray.getValues()).to.deep.equal([{ data: "newNewTest" }]);
|
|
470
480
|
});
|
|
471
|
-
it(
|
|
481
|
+
it(".setValues should work to overwrite the whole array", function () {
|
|
472
482
|
myArray.push(stringProp1);
|
|
473
483
|
myArray.push(stringProp2);
|
|
474
|
-
stringProp3._properties.data.setValue(
|
|
484
|
+
stringProp3._properties.data.setValue("testing 123");
|
|
475
485
|
myArray.setValues([stringProp3]);
|
|
476
|
-
expect(myArray.getValues()).to.deep.equal([{ data:
|
|
486
|
+
expect(myArray.getValues()).to.deep.equal([{ data: "testing 123" }]);
|
|
477
487
|
expect(myArray.length).to.equal(1);
|
|
478
488
|
});
|
|
479
|
-
it(
|
|
489
|
+
it(".setValues should work to overwrite part of the array", function () {
|
|
480
490
|
myArray.push(stringProp1);
|
|
481
491
|
myArray.push(stringProp2);
|
|
482
|
-
myArray.setValues({ 0: { data:
|
|
483
|
-
expect(myArray.getValues()).to.deep.equal([{ data:
|
|
492
|
+
myArray.setValues({ 0: { data: "test test test" } });
|
|
493
|
+
expect(myArray.getValues()).to.deep.equal([{ data: "test test test" }, { data: "" }]);
|
|
484
494
|
});
|
|
485
|
-
it(
|
|
495
|
+
it(".shift should remove the first element of an array and return the removed element", function () {
|
|
486
496
|
myArray.push(stringProp1);
|
|
487
497
|
myArray.push(stringProp2);
|
|
488
498
|
myArray.shift();
|
|
@@ -490,37 +500,42 @@ describe('ArrayProperty', function () {
|
|
|
490
500
|
expect(myArray.shift()).to.deep.equal(stringProp2);
|
|
491
501
|
expect(myArray.length).to.equal(0);
|
|
492
502
|
});
|
|
493
|
-
it(
|
|
503
|
+
it(".shift should return undefined if called on an empty array", function () {
|
|
494
504
|
expect(myArray.shift()).to.be.undefined;
|
|
495
505
|
});
|
|
496
|
-
it(
|
|
506
|
+
it(".unshift should add a property at the beginnig of an array and return the new length of the array", function () {
|
|
497
507
|
myArray.push(stringProp1);
|
|
498
508
|
myArray.push(stringProp2);
|
|
499
509
|
myArray.unshift(stringProp3);
|
|
500
|
-
expect(myArray.getEntriesReadOnly()).to.deep.equal([
|
|
510
|
+
expect(myArray.getEntriesReadOnly()).to.deep.equal([
|
|
511
|
+
stringProp3,
|
|
512
|
+
stringProp1,
|
|
513
|
+
stringProp2,
|
|
514
|
+
]);
|
|
501
515
|
expect(myArray.unshift(stringProp4)).to.equal(4);
|
|
502
516
|
});
|
|
503
517
|
afterEach(function () {
|
|
504
518
|
myArray.clear();
|
|
505
519
|
});
|
|
506
520
|
});
|
|
507
|
-
describe(
|
|
521
|
+
describe("API methods - primitive arrays", function () {
|
|
508
522
|
var myPrimitiveArray;
|
|
509
523
|
before(function () {
|
|
510
|
-
myPrimitiveArray = PropertyFactory.create(
|
|
524
|
+
myPrimitiveArray = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
525
|
+
._properties.data;
|
|
511
526
|
});
|
|
512
|
-
it(
|
|
527
|
+
it(".clear should remove all elements in the array", function () {
|
|
513
528
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
514
529
|
expect(myPrimitiveArray.length).to.equal(3);
|
|
515
530
|
myPrimitiveArray.clear();
|
|
516
531
|
expect(myPrimitiveArray.length).to.equal(0);
|
|
517
532
|
});
|
|
518
|
-
it(
|
|
533
|
+
it(".get should return a value", function () {
|
|
519
534
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
520
535
|
var result = myPrimitiveArray.get(0);
|
|
521
536
|
expect(result).to.equal(1);
|
|
522
537
|
});
|
|
523
|
-
it(
|
|
538
|
+
it(".getEntriesReadOnly should return an array", function () {
|
|
524
539
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
525
540
|
const result = myPrimitiveArray.getEntriesReadOnly();
|
|
526
541
|
assert.equal(result.length, 3);
|
|
@@ -528,30 +543,31 @@ describe('ArrayProperty', function () {
|
|
|
528
543
|
assert.equal(result[1], 2);
|
|
529
544
|
assert.equal(result[2], 3);
|
|
530
545
|
});
|
|
531
|
-
it(
|
|
532
|
-
expect(myPrimitiveArray.getFullTypeid()).to.equal(
|
|
533
|
-
expect(myPrimitiveArray.getFullTypeid(true)).to.equal(
|
|
546
|
+
it("getFullTypeid should return a string of the typeid with or without collection", function () {
|
|
547
|
+
expect(myPrimitiveArray.getFullTypeid()).to.equal("array<Int32>");
|
|
548
|
+
expect(myPrimitiveArray.getFullTypeid(true)).to.equal("Int32");
|
|
534
549
|
});
|
|
535
|
-
it(
|
|
550
|
+
it(".getIds should return an array of index strings", function () {
|
|
536
551
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
537
|
-
expect(myPrimitiveArray.getIds()).to.deep.equal([
|
|
552
|
+
expect(myPrimitiveArray.getIds()).to.deep.equal(["0", "1", "2"]);
|
|
538
553
|
});
|
|
539
|
-
it(
|
|
554
|
+
it(".getLength should return the length of the array", function () {
|
|
540
555
|
expect(myPrimitiveArray.getLength()).to.equal(0);
|
|
541
556
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
542
557
|
expect(myPrimitiveArray.getLength()).to.equal(3);
|
|
543
558
|
});
|
|
544
|
-
it(
|
|
559
|
+
it(".has should work", function () {
|
|
545
560
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
546
561
|
expect(myPrimitiveArray.has(1)).to.be.true;
|
|
547
562
|
expect(myPrimitiveArray.has(4)).to.be.false;
|
|
548
563
|
});
|
|
549
|
-
it(
|
|
564
|
+
it(".setValues and .getValues should work for primitive arrays", function () {
|
|
550
565
|
// tests for getValues on typed arrays fail but only on PhantomJS.
|
|
551
566
|
if (isBrowser && window.top.callPhantom) {
|
|
552
567
|
this.skip();
|
|
553
568
|
}
|
|
554
|
-
var MyArrayProp = PropertyFactory.create(
|
|
569
|
+
var MyArrayProp = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
570
|
+
._properties.data;
|
|
555
571
|
MyArrayProp.insertRange(0, [1, 2, 3]);
|
|
556
572
|
MyArrayProp.setValues({
|
|
557
573
|
0: 12,
|
|
@@ -560,22 +576,25 @@ describe('ArrayProperty', function () {
|
|
|
560
576
|
expect(MyArrayProp.getValues()).to.deep.equal([12, 2, 9]);
|
|
561
577
|
MyArrayProp.setValues([3, 4]);
|
|
562
578
|
expect(MyArrayProp.get(0)).to.equal(3);
|
|
563
|
-
expect(function () {
|
|
579
|
+
expect(function () {
|
|
580
|
+
MyArrayProp.get(2);
|
|
581
|
+
}).to.throw();
|
|
564
582
|
});
|
|
565
|
-
it(
|
|
583
|
+
it(".insert should insert a value in a primitive array and move other values to the right", function () {
|
|
566
584
|
myPrimitiveArray.insert(0, 1);
|
|
567
585
|
expect(myPrimitiveArray.length).to.equal(1);
|
|
568
586
|
myPrimitiveArray.insert(0, 2);
|
|
569
587
|
expect(myPrimitiveArray.getValues()).to.deep.equal([2, 1]);
|
|
570
588
|
});
|
|
571
|
-
it(
|
|
589
|
+
it(".insertRange should insert a range of values and move other values to the right", function () {
|
|
572
590
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
573
591
|
expect(myPrimitiveArray.length).to.equal(3);
|
|
574
592
|
myPrimitiveArray.insertRange(1, [4, 5]);
|
|
575
593
|
expect(myPrimitiveArray.getValues()).to.deep.equal([1, 4, 5, 2, 3]);
|
|
576
594
|
});
|
|
577
|
-
it(
|
|
578
|
-
var myArray = PropertyFactory.create(
|
|
595
|
+
it(".pop should remove the last item of a primitive array and return the removed value", function () {
|
|
596
|
+
var myArray = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
597
|
+
._properties.data;
|
|
579
598
|
myArray.push(1);
|
|
580
599
|
myArray.push(2);
|
|
581
600
|
myArray.push(3);
|
|
@@ -585,31 +604,32 @@ describe('ArrayProperty', function () {
|
|
|
585
604
|
expect(myArray.getValues()).to.deep.equal([1, 2]);
|
|
586
605
|
expect(myArray.pop()).to.equal(2);
|
|
587
606
|
});
|
|
588
|
-
it(
|
|
607
|
+
it(".pop should return undefined if called on an empty array", function () {
|
|
589
608
|
expect(myPrimitiveArray.pop()).to.be.undefined;
|
|
590
609
|
});
|
|
591
|
-
it(
|
|
610
|
+
it(".push should add a value at the end of the array and return the new length", function () {
|
|
592
611
|
myPrimitiveArray.push(1);
|
|
593
612
|
myPrimitiveArray.push(2);
|
|
594
613
|
expect(myPrimitiveArray.getValues()).to.deep.equal([1, 2]);
|
|
595
614
|
expect(myPrimitiveArray.push(4)).to.equal(3);
|
|
596
615
|
});
|
|
597
|
-
it(
|
|
616
|
+
it(".remove should remove an element from the array and return that element", function () {
|
|
598
617
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
599
618
|
expect(myPrimitiveArray.remove(0)).to.equal(1);
|
|
600
619
|
expect(myPrimitiveArray.getValues()).to.deep.equal([2, 3]);
|
|
601
620
|
});
|
|
602
|
-
it(
|
|
621
|
+
it(".removeRange should remove a range of elements from an array and return those elements", function () {
|
|
603
622
|
myPrimitiveArray.insertRange(0, [1, 2, 3, 4, 5]);
|
|
604
623
|
expect(myPrimitiveArray.removeRange(2, 2)).to.deep.equal([3, 4]);
|
|
605
624
|
expect(myPrimitiveArray.getValues()).to.deep.equal([1, 2, 5]);
|
|
606
625
|
});
|
|
607
|
-
it(
|
|
626
|
+
it(".resolvePath should work on primitive arrays", function () {
|
|
608
627
|
myPrimitiveArray.insertRange(0, [1, 2, 3]);
|
|
609
|
-
expect(myPrimitiveArray.resolvePath(
|
|
628
|
+
expect(myPrimitiveArray.resolvePath("1")).to.equal(2);
|
|
610
629
|
});
|
|
611
|
-
it(
|
|
612
|
-
var myArray = PropertyFactory.create(
|
|
630
|
+
it(".set should replace a value in a primitive array", function () {
|
|
631
|
+
var myArray = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
632
|
+
._properties.data;
|
|
613
633
|
myArray.push(1);
|
|
614
634
|
myArray.push(2);
|
|
615
635
|
myArray.push(3);
|
|
@@ -617,8 +637,9 @@ describe('ArrayProperty', function () {
|
|
|
617
637
|
expect(myArray.get(2)).to.equal(8);
|
|
618
638
|
expect(myArray.getValues()).to.deep.equal([1, 2, 8]);
|
|
619
639
|
});
|
|
620
|
-
it(
|
|
621
|
-
var myArray = PropertyFactory.create(
|
|
640
|
+
it(".setRange should replace values in a primitive array", function () {
|
|
641
|
+
var myArray = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
642
|
+
._properties.data;
|
|
622
643
|
myArray.push(1);
|
|
623
644
|
myArray.push(2);
|
|
624
645
|
myArray.push(3);
|
|
@@ -627,14 +648,16 @@ describe('ArrayProperty', function () {
|
|
|
627
648
|
expect(myArray.get(2)).to.equal(5);
|
|
628
649
|
expect(myArray.getValues()).to.deep.equal([1, 4, 5]);
|
|
629
650
|
});
|
|
630
|
-
it(
|
|
631
|
-
var myArray = PropertyFactory.create(
|
|
651
|
+
it(".setRange should replace last value in a primitive array", function () {
|
|
652
|
+
var myArray = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
653
|
+
._properties.data;
|
|
632
654
|
myArray.insertRange(0, [1, 2, 3, 4, 5]);
|
|
633
655
|
myArray.setRange(0, [1, 2, 3, 10, 11]);
|
|
634
656
|
expect(myArray.getValues()).to.deep.equal([1, 2, 3, 10, 11]);
|
|
635
657
|
});
|
|
636
|
-
it(
|
|
637
|
-
arrayProp = PropertyFactory.create(
|
|
658
|
+
it(".setValues should work to overwrite a whole array", function () {
|
|
659
|
+
arrayProp = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")._properties
|
|
660
|
+
.data;
|
|
638
661
|
arrayProp.insertRange(0, [1, 2, 3]);
|
|
639
662
|
expect(arrayProp.get(2)).to.equal(3);
|
|
640
663
|
arrayProp.setValues([13, 14]);
|
|
@@ -644,8 +667,9 @@ describe('ArrayProperty', function () {
|
|
|
644
667
|
};
|
|
645
668
|
expect(incorrectFn).to.throw();
|
|
646
669
|
});
|
|
647
|
-
it(
|
|
648
|
-
var myArrayProp = PropertyFactory.create(
|
|
670
|
+
it("setValues should work to overwrite part of the array", function () {
|
|
671
|
+
var myArrayProp = PropertyFactory.create("autodesk.test:test.dynamicArray-1.0.0")
|
|
672
|
+
._properties.data;
|
|
649
673
|
myArrayProp.insertRange(0, [1, 2, 3]);
|
|
650
674
|
expect(myArrayProp.get(2)).to.equal(3);
|
|
651
675
|
myArrayProp.setValues({
|
|
@@ -659,12 +683,12 @@ describe('ArrayProperty', function () {
|
|
|
659
683
|
expect(correctFn).to.not.throw();
|
|
660
684
|
expect(myArrayProp.get(2)).to.equal(3);
|
|
661
685
|
});
|
|
662
|
-
it(
|
|
686
|
+
it(".shift should remove the first element of the array and return that element", function () {
|
|
663
687
|
myPrimitiveArray.insertRange(0, [1, 2, 3, 4]);
|
|
664
688
|
expect(myPrimitiveArray.shift()).to.equal(1);
|
|
665
689
|
expect(myPrimitiveArray.getValues()).to.deep.equal([2, 3, 4]);
|
|
666
690
|
});
|
|
667
|
-
it(
|
|
691
|
+
it(".unshift should add a value to the beginning of the array and return the new length", function () {
|
|
668
692
|
myPrimitiveArray.insertRange(0, [1, 2, 3, 4]);
|
|
669
693
|
myPrimitiveArray.unshift(5);
|
|
670
694
|
expect(myPrimitiveArray.unshift(13)).to.equal(6);
|
|
@@ -674,14 +698,17 @@ describe('ArrayProperty', function () {
|
|
|
674
698
|
myPrimitiveArray.clear();
|
|
675
699
|
});
|
|
676
700
|
});
|
|
677
|
-
describe(
|
|
678
|
-
it(
|
|
679
|
-
var myBoolArray = PropertyFactory.create(
|
|
701
|
+
describe("testing specific types of arrays", function () {
|
|
702
|
+
it("should support boolean arrays", function () {
|
|
703
|
+
var myBoolArray = PropertyFactory.create("autodesk.test:test.arraybool-1.0.0")
|
|
704
|
+
._properties.data;
|
|
680
705
|
expect(myBoolArray.length).to.equal(3);
|
|
681
706
|
expect(myBoolArray.get(0)).to.equal(false);
|
|
682
707
|
expect(myBoolArray.get(1)).to.equal(false);
|
|
683
708
|
expect(myBoolArray.get(2)).to.equal(false);
|
|
684
|
-
expect(function () {
|
|
709
|
+
expect(function () {
|
|
710
|
+
myBoolArray.get(3);
|
|
711
|
+
}).to.throw(Error);
|
|
685
712
|
myBoolArray.push(true);
|
|
686
713
|
myBoolArray.push(0);
|
|
687
714
|
expect(myBoolArray.getLength().should.equal(5));
|
|
@@ -692,54 +719,53 @@ describe('ArrayProperty', function () {
|
|
|
692
719
|
myBoolArray.insert(0, 1);
|
|
693
720
|
expect(myBoolArray.get(0)).to.equal(true);
|
|
694
721
|
});
|
|
695
|
-
it(
|
|
696
|
-
var myArray = PropertyFactory.create(
|
|
697
|
-
myArray.set(1.2,
|
|
722
|
+
it(".set and .get should convert float index to int", function () {
|
|
723
|
+
var myArray = PropertyFactory.create("String", "array", ["item 0", "item 1", "item 2"]);
|
|
724
|
+
myArray.set(1.2, "item 1.2");
|
|
698
725
|
expect(myArray.getLength()).to.equal(3);
|
|
699
|
-
expect(myArray.get(1.6)).to.equal(
|
|
726
|
+
expect(myArray.get(1.6)).to.equal("item 1.2");
|
|
700
727
|
});
|
|
701
|
-
it(
|
|
702
|
-
var myArray = PropertyFactory.create(
|
|
703
|
-
myArray.set(
|
|
728
|
+
it(".set and .get should convert string index to int", function () {
|
|
729
|
+
var myArray = PropertyFactory.create("String", "array", ["item 0", "item 1", "item 2"]);
|
|
730
|
+
myArray.set("0.3", "item 0.3");
|
|
704
731
|
expect(myArray.getLength()).to.equal(3);
|
|
705
|
-
expect(myArray.get(
|
|
732
|
+
expect(myArray.get("0.6")).to.equal("item 0.3");
|
|
706
733
|
});
|
|
707
|
-
it(
|
|
708
|
-
var myArray = PropertyFactory.create(
|
|
709
|
-
expect(() => myArray.set(Infinity,
|
|
710
|
-
'in_offset, method: ArrayProperty.setRange or .set');
|
|
734
|
+
it(".set and .get should reject float index that cannot be converted to int", function () {
|
|
735
|
+
var myArray = PropertyFactory.create("String", "array", ["item 0", "item 1", "item 2"]);
|
|
736
|
+
expect(() => myArray.set(Infinity, "item infinity")).to.throw(MSG.NOT_NUMBER + "in_offset, method: ArrayProperty.setRange or .set");
|
|
711
737
|
expect(() => myArray.get(NaN)).to.throw(MSG.IN_POSITION_MUST_BE_NUMBER);
|
|
712
738
|
});
|
|
713
|
-
it(
|
|
714
|
-
var myArray = PropertyFactory.create(
|
|
715
|
-
expect(() => myArray.set(
|
|
716
|
-
|
|
717
|
-
expect(() => myArray.get('2abc')).to.throw(MSG.IN_POSITION_MUST_BE_NUMBER);
|
|
739
|
+
it(".set and .get should reject string index that can not be converted to int", function () {
|
|
740
|
+
var myArray = PropertyFactory.create("String", "array", ["item 0", "item 1", "item 2"]);
|
|
741
|
+
expect(() => myArray.set("2abc", "item 2abc")).to.throw(MSG.NOT_NUMBER + "in_offset, method: ArrayProperty.setRange or .set");
|
|
742
|
+
expect(() => myArray.get("2abc")).to.throw(MSG.IN_POSITION_MUST_BE_NUMBER);
|
|
718
743
|
});
|
|
719
744
|
});
|
|
720
|
-
describe(
|
|
721
|
-
it(
|
|
745
|
+
describe("Checking the generalized squash function of ArrayProperty", function () {
|
|
746
|
+
it("should be squashed to the expected changeset", function (done) {
|
|
722
747
|
var error;
|
|
723
748
|
try {
|
|
724
|
-
arrayProp = PropertyFactory.create(
|
|
749
|
+
arrayProp = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0")._properties
|
|
750
|
+
.MyArray;
|
|
725
751
|
arrayProp.applyChangeSet({
|
|
726
|
-
|
|
752
|
+
insert: [[0, [0, 0]]],
|
|
727
753
|
});
|
|
728
754
|
arrayProp.cleanDirty();
|
|
729
755
|
arrayProp.applyChangeSet({
|
|
730
|
-
|
|
756
|
+
insert: [[0, [2, 3]]],
|
|
731
757
|
});
|
|
732
758
|
arrayProp.applyChangeSet({
|
|
733
|
-
|
|
759
|
+
modify: [[1, [9, 44]]],
|
|
734
760
|
});
|
|
735
761
|
arrayProp.applyChangeSet({
|
|
736
|
-
|
|
762
|
+
insert: [[3, [6, 7, 8]]],
|
|
737
763
|
});
|
|
738
764
|
arrayProp.applyChangeSet({
|
|
739
|
-
|
|
765
|
+
remove: [[4, 1]],
|
|
740
766
|
});
|
|
741
767
|
arrayProp.applyChangeSet({
|
|
742
|
-
|
|
768
|
+
modify: [[5, [9]]],
|
|
743
769
|
});
|
|
744
770
|
}
|
|
745
771
|
catch (e) {
|
|
@@ -748,103 +774,94 @@ describe('ArrayProperty', function () {
|
|
|
748
774
|
finally {
|
|
749
775
|
expect(arrayProp).to.not.equal(null);
|
|
750
776
|
expect(arrayProp._getDirtyChanges()).to.deep.equal({
|
|
751
|
-
|
|
752
|
-
|
|
777
|
+
insert: [
|
|
778
|
+
[0, [2, 9]],
|
|
779
|
+
[1, [6, 8]],
|
|
780
|
+
],
|
|
781
|
+
modify: [[0, [44, 9]]],
|
|
753
782
|
});
|
|
754
783
|
expect(error).to.equal(undefined);
|
|
755
784
|
done();
|
|
756
785
|
}
|
|
757
786
|
});
|
|
758
|
-
it(
|
|
787
|
+
it("Merging of reversible modifications", function () {
|
|
759
788
|
var base = {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
[
|
|
764
|
-
0,
|
|
765
|
-
[
|
|
766
|
-
2,
|
|
767
|
-
],
|
|
768
|
-
[
|
|
769
|
-
1,
|
|
770
|
-
],
|
|
771
|
-
],
|
|
772
|
-
],
|
|
789
|
+
"array<Float32>": {
|
|
790
|
+
value: {
|
|
791
|
+
modify: [[0, [2], [1]]],
|
|
773
792
|
},
|
|
774
793
|
},
|
|
775
794
|
};
|
|
776
795
|
var mod = {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
[
|
|
781
|
-
0,
|
|
782
|
-
[
|
|
783
|
-
3,
|
|
784
|
-
],
|
|
785
|
-
[
|
|
786
|
-
2,
|
|
787
|
-
],
|
|
788
|
-
],
|
|
789
|
-
],
|
|
796
|
+
"array<Float32>": {
|
|
797
|
+
value: {
|
|
798
|
+
modify: [[0, [3], [2]]],
|
|
790
799
|
},
|
|
791
800
|
},
|
|
792
801
|
};
|
|
793
802
|
var testChangeSet = new ChangeSet(base);
|
|
794
803
|
testChangeSet.applyChangeSet(mod);
|
|
795
804
|
var CS = testChangeSet.getSerializedChangeSet();
|
|
796
|
-
expect(CS[
|
|
797
|
-
expect(CS[
|
|
798
|
-
expect(CS[
|
|
805
|
+
expect(CS["array<Float32>"].value.modify[0].length).to.equal(3);
|
|
806
|
+
expect(CS["array<Float32>"].value.modify[0][1][0]).to.equal(3); // Value after modification
|
|
807
|
+
expect(CS["array<Float32>"].value.modify[0][2][0]).to.equal(1); // Value before modification
|
|
799
808
|
});
|
|
800
|
-
it(
|
|
809
|
+
it("[random numbers test] - the resulting insert should be equal to the data array", function (done) {
|
|
801
810
|
var error;
|
|
802
811
|
this.timeout(120000); // When the code is instrumented for coverage analysis, it takes a lot of time.
|
|
803
812
|
for (let j = 0; j < 10; j++) {
|
|
804
813
|
const random = new DeterministicRandomGenerator(j);
|
|
805
814
|
try {
|
|
806
|
-
arrayProp = PropertyFactory.create(
|
|
807
|
-
|
|
815
|
+
arrayProp = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0")
|
|
816
|
+
._properties.MyArray;
|
|
817
|
+
arrayProp.applyChangeSet({ insert: [[0, [1, 2, 3, 4, 5, 6, 7, 8, 9]]] });
|
|
808
818
|
arrayProp.cleanDirty();
|
|
809
819
|
var currentArrayLength;
|
|
810
820
|
for (var i = 0; i < 1000; ++i) {
|
|
811
821
|
currentArrayLength = arrayProp.length;
|
|
812
|
-
var nextOpType =
|
|
822
|
+
var nextOpType = "insert";
|
|
813
823
|
var opOffset = 0;
|
|
814
824
|
if (currentArrayLength > 0) {
|
|
815
825
|
nextOpType = possibleChanges[Math.floor(random.random() * 2.999999)];
|
|
816
826
|
opOffset = Math.min(Math.floor(random.random() * currentArrayLength), currentArrayLength - 1);
|
|
817
827
|
}
|
|
818
|
-
var opLength = 1 +
|
|
828
|
+
var opLength = 1 +
|
|
829
|
+
Math.min(Math.floor(random.random() * (currentArrayLength - opOffset)), currentArrayLength - opOffset - 1);
|
|
819
830
|
var nextChangeset = {};
|
|
820
831
|
switch (nextOpType) {
|
|
821
|
-
case
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
832
|
+
case "remove": {
|
|
833
|
+
nextChangeset[nextOpType] = [[opOffset, opLength]];
|
|
834
|
+
break;
|
|
835
|
+
}
|
|
836
|
+
case "insert": {
|
|
837
|
+
nextChangeset[nextOpType] = [];
|
|
838
|
+
nextChangeset[nextOpType].push([
|
|
839
|
+
opOffset,
|
|
840
|
+
getRandomNumbersArray(Math.floor(random.random() * 4 + 1), random),
|
|
841
|
+
]);
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
case "modify": {
|
|
845
|
+
nextChangeset[nextOpType] = [
|
|
846
|
+
[
|
|
847
|
+
opOffset,
|
|
848
|
+
getRandomNumbersArray(Math.min(random.random() * 2 + 1, opLength), random),
|
|
849
|
+
],
|
|
850
|
+
];
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
838
853
|
// no default
|
|
839
854
|
}
|
|
840
855
|
arrayProp.applyChangeSet(nextChangeset);
|
|
841
|
-
var arrayPropTest = PropertyFactory.create(
|
|
842
|
-
arrayPropTest.applyChangeSet({
|
|
856
|
+
var arrayPropTest = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0")._properties.MyArray;
|
|
857
|
+
arrayPropTest.applyChangeSet({
|
|
858
|
+
insert: [[0, [1, 2, 3, 4, 5, 6, 7, 8, 9]]],
|
|
859
|
+
});
|
|
843
860
|
arrayPropTest.cleanDirty();
|
|
844
861
|
arrayPropTest.applyChangeSet(arrayProp._getDirtyChanges());
|
|
845
862
|
if (!compareArrays(arrayProp, arrayPropTest)) {
|
|
846
|
-
console.warn(
|
|
847
|
-
console.log(
|
|
863
|
+
console.warn("Bug found in iteration ", j, i);
|
|
864
|
+
console.log("Testresults: ");
|
|
848
865
|
console.log(JSON.stringify(nextChangeset));
|
|
849
866
|
console.log(arrayProp.getEntriesReadOnly());
|
|
850
867
|
console.log(arrayPropTest.getEntriesReadOnly());
|
|
@@ -866,47 +883,56 @@ describe('ArrayProperty', function () {
|
|
|
866
883
|
done();
|
|
867
884
|
});
|
|
868
885
|
});
|
|
869
|
-
describe(
|
|
886
|
+
describe("Fixed Size arrays", function () {
|
|
870
887
|
// Should throw an exception when you create a primitive type and try to add it to an array
|
|
871
888
|
// that takes values of that primitive type
|
|
872
|
-
it(
|
|
873
|
-
var myFloatArray = PropertyFactory.create(
|
|
889
|
+
it("should support fixed size arrays for a primitive type", function () {
|
|
890
|
+
var myFloatArray = PropertyFactory.create("autodesk.test:test.arrayfloat32-1.0.0")
|
|
891
|
+
._properties.data;
|
|
874
892
|
expect(myFloatArray.length).to.equal(3);
|
|
875
893
|
expect(myFloatArray.get(0)).to.equal(0);
|
|
876
894
|
expect(myFloatArray.get(1)).to.equal(0);
|
|
877
895
|
expect(myFloatArray.get(2)).to.equal(0);
|
|
878
|
-
expect(function () {
|
|
896
|
+
expect(function () {
|
|
897
|
+
myFloatArray.get(3);
|
|
898
|
+
}).to.throw(Error);
|
|
879
899
|
// Array should be clean after creation and but full serialization should return an insert
|
|
880
900
|
expect(myFloatArray._serialize(true)).to.be.empty; // Waiting for fix from OT
|
|
881
|
-
expect(myFloatArray._serialize(false)).to.have.keys(
|
|
901
|
+
expect(myFloatArray._serialize(false)).to.have.keys("insert");
|
|
882
902
|
// This should throw
|
|
883
903
|
// expect(function() { myFloatArray.push(10);}).to.throw(Error);
|
|
884
904
|
// expect(function() { myFloatArray.removeRange(0,1);}).to.throw(Error);
|
|
885
905
|
});
|
|
886
|
-
it(
|
|
887
|
-
var myStringArray = PropertyFactory.create(
|
|
906
|
+
it("should support fixed size arrays for a primitive type", function () {
|
|
907
|
+
var myStringArray = PropertyFactory.create("autodesk.test:test.arraystring-1.0.0")
|
|
908
|
+
._properties.data;
|
|
888
909
|
expect(myStringArray.length).to.equal(3);
|
|
889
|
-
expect(myStringArray.get(0)).to.equal(
|
|
890
|
-
expect(myStringArray.get(1)).to.equal(
|
|
891
|
-
expect(myStringArray.get(2)).to.equal(
|
|
892
|
-
expect(function () {
|
|
910
|
+
expect(myStringArray.get(0)).to.equal("");
|
|
911
|
+
expect(myStringArray.get(1)).to.equal("");
|
|
912
|
+
expect(myStringArray.get(2)).to.equal("");
|
|
913
|
+
expect(function () {
|
|
914
|
+
myStringArray.get(3);
|
|
915
|
+
}).to.throw(Error);
|
|
893
916
|
// Array should be clean after creation and but full serialization should return an insert
|
|
894
917
|
expect(myStringArray._serialize(true)).to.be.empty;
|
|
895
|
-
expect(myStringArray._serialize(false)).to.have.keys(
|
|
918
|
+
expect(myStringArray._serialize(false)).to.have.keys("insert");
|
|
896
919
|
// This should throw
|
|
897
920
|
// expect(function() { myFloatArray.push('');}).to.throw(Error); // TODO: add all functions
|
|
898
921
|
// expect(function() { myFloatArray.removeRange(0,1);}).to.throw(Error);
|
|
899
922
|
});
|
|
900
|
-
it(
|
|
901
|
-
var myCustomArray = PropertyFactory.create(
|
|
923
|
+
it("should support fixed size arrays for a complex type", function () {
|
|
924
|
+
var myCustomArray = PropertyFactory.create("autodesk.test:test.customarray-1.0.0")
|
|
925
|
+
._properties.data;
|
|
902
926
|
expect(myCustomArray.length).to.equal(3);
|
|
903
927
|
expect(myCustomArray.get(0)).to.be.instanceof(BaseProperty);
|
|
904
928
|
expect(myCustomArray.get(1)).to.be.instanceof(BaseProperty);
|
|
905
929
|
expect(myCustomArray.get(2)).to.be.instanceof(BaseProperty);
|
|
906
|
-
expect(function () {
|
|
930
|
+
expect(function () {
|
|
931
|
+
myCustomArray.get(3);
|
|
932
|
+
}).to.throw(Error);
|
|
907
933
|
// Array should be clean after creation and but full serialization should return an insert
|
|
908
934
|
expect(myCustomArray._serialize(true)).to.be.empty;
|
|
909
|
-
expect(myCustomArray._serialize(false)).to.have.keys(
|
|
935
|
+
expect(myCustomArray._serialize(false)).to.have.keys("insert");
|
|
910
936
|
// This should throw
|
|
911
937
|
// expect(function() {
|
|
912
938
|
// myCustomArray.push(PropertyFactory.create('autodesk.test:test.string-1.0.0'));
|
|
@@ -914,18 +940,19 @@ describe('ArrayProperty', function () {
|
|
|
914
940
|
// expect(function() { myFloatArray.removeRange(0,1);}).to.throw(Error);
|
|
915
941
|
});
|
|
916
942
|
});
|
|
917
|
-
describe(
|
|
918
|
-
it(
|
|
943
|
+
describe("Checking normalized changeset ability of ArrayProperty", function () {
|
|
944
|
+
it("should be equal to the expected value", function (done) {
|
|
919
945
|
var error;
|
|
920
946
|
try {
|
|
921
|
-
arrayProp = PropertyFactory.create(
|
|
922
|
-
|
|
923
|
-
arrayProp.applyChangeSet({
|
|
924
|
-
arrayProp.applyChangeSet({
|
|
925
|
-
arrayProp.applyChangeSet({
|
|
926
|
-
arrayProp.applyChangeSet({
|
|
927
|
-
arrayProp.applyChangeSet({
|
|
928
|
-
arrayProp.applyChangeSet({
|
|
947
|
+
arrayProp = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0")._properties
|
|
948
|
+
.MyArray;
|
|
949
|
+
arrayProp.applyChangeSet({ insert: [[0, [0, 0]]] });
|
|
950
|
+
arrayProp.applyChangeSet({ insert: [[1, [2, 3, 4, 5, 6, 7, 8, 9]]] });
|
|
951
|
+
arrayProp.applyChangeSet({ insert: [[4, [222, 333]]] });
|
|
952
|
+
arrayProp.applyChangeSet({ remove: [[2, 3]] });
|
|
953
|
+
arrayProp.applyChangeSet({ modify: [[3, [33]]] });
|
|
954
|
+
arrayProp.applyChangeSet({ remove: [[0, 2]] });
|
|
955
|
+
arrayProp.applyChangeSet({ insert: [[0, [123, 456]]] });
|
|
929
956
|
}
|
|
930
957
|
catch (e) {
|
|
931
958
|
error = e;
|
|
@@ -933,21 +960,22 @@ describe('ArrayProperty', function () {
|
|
|
933
960
|
finally {
|
|
934
961
|
expect(arrayProp).to.not.equal(null);
|
|
935
962
|
expect(arrayProp._getDirtyChanges()).to.deep.equal({
|
|
936
|
-
|
|
963
|
+
insert: [[0, [123, 456, 333, 33, 6, 7, 8, 9, 0]]],
|
|
937
964
|
});
|
|
938
965
|
expect(error).to.equal(undefined);
|
|
939
966
|
done();
|
|
940
967
|
}
|
|
941
968
|
});
|
|
942
|
-
it(
|
|
969
|
+
it("[random numbers test] - the resulting insert should be equal to the data array", function (done) {
|
|
943
970
|
var error;
|
|
944
971
|
try {
|
|
945
|
-
arrayProp = PropertyFactory.create(
|
|
972
|
+
arrayProp = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0")._properties
|
|
973
|
+
.MyArray;
|
|
946
974
|
var currentArrayLength = 0;
|
|
947
975
|
const random = new DeterministicRandomGenerator(0);
|
|
948
976
|
for (var i = 0; i < 1000; ++i) {
|
|
949
977
|
currentArrayLength = arrayProp.length;
|
|
950
|
-
var nextOpType =
|
|
978
|
+
var nextOpType = "insert";
|
|
951
979
|
var opOffset = 0;
|
|
952
980
|
if (currentArrayLength > 0) {
|
|
953
981
|
nextOpType = possibleChanges[Math.floor(Math.random() * 2.999999)];
|
|
@@ -959,22 +987,24 @@ describe('ArrayProperty', function () {
|
|
|
959
987
|
}
|
|
960
988
|
var nextChangeset = {};
|
|
961
989
|
switch (nextOpType) {
|
|
962
|
-
case
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
990
|
+
case "remove": {
|
|
991
|
+
nextChangeset[nextOpType] = [[opOffset, opLength]];
|
|
992
|
+
break;
|
|
993
|
+
}
|
|
994
|
+
case "insert": {
|
|
995
|
+
nextChangeset[nextOpType] = [];
|
|
996
|
+
nextChangeset[nextOpType].push([
|
|
997
|
+
opOffset,
|
|
998
|
+
getRandomNumbersArray(Math.floor(Math.random() * 4 + 1), random),
|
|
999
|
+
]);
|
|
1000
|
+
break;
|
|
1001
|
+
}
|
|
1002
|
+
case "modify": {
|
|
1003
|
+
nextChangeset[nextOpType] = [
|
|
1004
|
+
[opOffset, getRandomNumbersArray(opLength, random)],
|
|
1005
|
+
];
|
|
1006
|
+
break;
|
|
1007
|
+
}
|
|
978
1008
|
// no default
|
|
979
1009
|
}
|
|
980
1010
|
arrayProp.applyChangeSet(nextChangeset);
|
|
@@ -987,8 +1017,7 @@ describe('ArrayProperty', function () {
|
|
|
987
1017
|
expect(arrayProp).to.not.equal(null);
|
|
988
1018
|
expect(error).to.equal(undefined);
|
|
989
1019
|
if (arrayProp.getEntriesReadOnly().length > 0) {
|
|
990
|
-
expect(arrayProp._getDirtyChanges().insert[0][1])
|
|
991
|
-
.to.deep.equal(Array.prototype.slice.call(arrayProp.getEntriesReadOnly()));
|
|
1020
|
+
expect(arrayProp._getDirtyChanges().insert[0][1]).to.deep.equal(Array.prototype.slice.call(arrayProp.getEntriesReadOnly()));
|
|
992
1021
|
}
|
|
993
1022
|
else {
|
|
994
1023
|
expect(arrayProp._getDirtyChanges().insert).to.equal(undefined);
|
|
@@ -997,24 +1026,24 @@ describe('ArrayProperty', function () {
|
|
|
997
1026
|
}
|
|
998
1027
|
});
|
|
999
1028
|
});
|
|
1000
|
-
describe(
|
|
1029
|
+
describe("Checking deserialization", function () {
|
|
1001
1030
|
var runDeserializationTests = function (testArrayOperation, testArray, primitiveProperty) {
|
|
1002
1031
|
// Serialization into an empty array
|
|
1003
|
-
var values = [
|
|
1032
|
+
var values = ["test1", "test2"];
|
|
1004
1033
|
testArrayOperation(values, { insert: [[0, values]] });
|
|
1005
1034
|
// Overwriting with a different array
|
|
1006
|
-
var values = [
|
|
1035
|
+
var values = ["test3"];
|
|
1007
1036
|
testArrayOperation(values, { insert: [[0, values]] });
|
|
1008
1037
|
// A second deserialization to the same array should preserve the changeset
|
|
1009
|
-
var values = [
|
|
1038
|
+
var values = ["test3"];
|
|
1010
1039
|
testArrayOperation(values, { insert: [[0, values]] });
|
|
1011
1040
|
// Now we clean the array and overwrite
|
|
1012
1041
|
testArray.cleanDirty();
|
|
1013
|
-
var values = [
|
|
1042
|
+
var values = ["test1", "test2"];
|
|
1014
1043
|
testArrayOperation(values, { insert: [[0, values]], remove: [[0, 1]] });
|
|
1015
1044
|
// A second deserialization to the same array
|
|
1016
1045
|
testArray.cleanDirty();
|
|
1017
|
-
var values = [
|
|
1046
|
+
var values = ["test1", "test2"];
|
|
1018
1047
|
if (primitiveProperty) {
|
|
1019
1048
|
// should report no change for primitive properties
|
|
1020
1049
|
testArrayOperation(values, {});
|
|
@@ -1032,8 +1061,8 @@ describe('ArrayProperty', function () {
|
|
|
1032
1061
|
var values = [];
|
|
1033
1062
|
testArrayOperation(values, {});
|
|
1034
1063
|
};
|
|
1035
|
-
it(
|
|
1036
|
-
var stringArray = PropertyFactory.create(
|
|
1064
|
+
it("of a primitive array property", function () {
|
|
1065
|
+
var stringArray = PropertyFactory.create("String", "array");
|
|
1037
1066
|
var testArrayOperation = function (values, expectedChangeSet) {
|
|
1038
1067
|
stringArray.deserialize(values.length !== 0 ? { insert: [[0, values]] } : {});
|
|
1039
1068
|
expect(stringArray.getEntriesReadOnly()).to.deep.equal(values);
|
|
@@ -1048,26 +1077,26 @@ describe('ArrayProperty', function () {
|
|
|
1048
1077
|
};
|
|
1049
1078
|
runDeserializationTests(testArrayOperation, stringArray, true);
|
|
1050
1079
|
});
|
|
1051
|
-
it(
|
|
1052
|
-
var testArray = PropertyFactory.create(
|
|
1080
|
+
it("of a custom type array", function () {
|
|
1081
|
+
var testArray = PropertyFactory.create("autodesk.test:test.string-1.0.0", "array");
|
|
1053
1082
|
var mapStringsToCustomType = function (strings) {
|
|
1054
1083
|
return strings.map(function (x) {
|
|
1055
1084
|
return {
|
|
1056
1085
|
String: {
|
|
1057
1086
|
data: x,
|
|
1058
1087
|
},
|
|
1059
|
-
typeid:
|
|
1088
|
+
typeid: "autodesk.test:test.string-1.0.0",
|
|
1060
1089
|
};
|
|
1061
1090
|
});
|
|
1062
1091
|
};
|
|
1063
1092
|
var testArrayOperation = function (values, expectedChangeSet) {
|
|
1064
|
-
testArray.deserialize(values.length !== 0
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1093
|
+
testArray.deserialize(values.length !== 0
|
|
1094
|
+
? {
|
|
1095
|
+
insert: [[0, mapStringsToCustomType(values)]],
|
|
1096
|
+
}
|
|
1097
|
+
: {});
|
|
1069
1098
|
expect(testArray.getEntriesReadOnly().map(function (x) {
|
|
1070
|
-
return x.get(
|
|
1099
|
+
return x.get("data").getValue();
|
|
1071
1100
|
})).to.deep.equal(values);
|
|
1072
1101
|
if (expectedChangeSet.insert) {
|
|
1073
1102
|
expectedChangeSet.insert[0][1] = mapStringsToCustomType(expectedChangeSet.insert[0][1]);
|
|
@@ -1084,16 +1113,19 @@ describe('ArrayProperty', function () {
|
|
|
1084
1113
|
runDeserializationTests(testArrayOperation, testArray, false);
|
|
1085
1114
|
});
|
|
1086
1115
|
});
|
|
1087
|
-
describe(
|
|
1088
|
-
it(
|
|
1116
|
+
describe("Checking rebasing of an ArrayProperty", function () {
|
|
1117
|
+
it("a remove-modify should be correctly rebased to the given changeset and cause conflicts", function (done) {
|
|
1089
1118
|
var error;
|
|
1090
1119
|
try {
|
|
1091
|
-
arrayProp = PropertyFactory.create(
|
|
1092
|
-
|
|
1120
|
+
arrayProp = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0")._properties
|
|
1121
|
+
.MyArray;
|
|
1122
|
+
var arrayProp1 = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0");
|
|
1093
1123
|
// prepare initial state
|
|
1094
|
-
arrayProp1._properties.MyArray.applyChangeSet({
|
|
1124
|
+
arrayProp1._properties.MyArray.applyChangeSet({
|
|
1125
|
+
insert: [[0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]],
|
|
1126
|
+
});
|
|
1095
1127
|
// create a copy of this state
|
|
1096
|
-
var arrayProp2 = PropertyFactory.create(
|
|
1128
|
+
var arrayProp2 = PropertyFactory.create("autodesk.tests:ArrayTestID-1.0.0");
|
|
1097
1129
|
arrayProp2.deserialize(arrayProp1._serialize(false));
|
|
1098
1130
|
// make sure the states are clear
|
|
1099
1131
|
arrayProp1.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY |
|
|
@@ -1101,8 +1133,19 @@ describe('ArrayProperty', function () {
|
|
|
1101
1133
|
arrayProp2.cleanDirty(BaseProperty.MODIFIED_STATE_FLAGS.DIRTY |
|
|
1102
1134
|
BaseProperty.MODIFIED_STATE_FLAGS.PENDING_CHANGE);
|
|
1103
1135
|
// apply different operations to the two properties in parallel
|
|
1104
|
-
arrayProp1._properties.MyArray.applyChangeSet({
|
|
1105
|
-
|
|
1136
|
+
arrayProp1._properties.MyArray.applyChangeSet({
|
|
1137
|
+
remove: [
|
|
1138
|
+
[2, 1],
|
|
1139
|
+
[4, 1],
|
|
1140
|
+
[6, 1],
|
|
1141
|
+
],
|
|
1142
|
+
});
|
|
1143
|
+
arrayProp2._properties.MyArray.applyChangeSet({
|
|
1144
|
+
modify: [
|
|
1145
|
+
[2, [23, 24]],
|
|
1146
|
+
[5, [33, 34, 35]],
|
|
1147
|
+
],
|
|
1148
|
+
});
|
|
1106
1149
|
// Get the ChangeSets
|
|
1107
1150
|
var changeSet1 = new ChangeSet(arrayProp1._serialize(true));
|
|
1108
1151
|
changeSet2 = arrayProp2._serialize(true);
|
|
@@ -1117,8 +1160,9 @@ describe('ArrayProperty', function () {
|
|
|
1117
1160
|
expect(error).to.equal(undefined);
|
|
1118
1161
|
expect(changeSet2).to.not.equal(null);
|
|
1119
1162
|
expect(conflicts.length).to.equal(2);
|
|
1120
|
-
expect(conflicts).to.deep.equal([
|
|
1121
|
-
|
|
1163
|
+
expect(conflicts).to.deep.equal([
|
|
1164
|
+
{
|
|
1165
|
+
path: "MyArray",
|
|
1122
1166
|
type: ChangeSet.ConflictType.ENTRY_MODIFIED_AFTER_REMOVE,
|
|
1123
1167
|
conflictingChange: {
|
|
1124
1168
|
type: ChangeSet.ConflictType.COLLIDING_SET,
|
|
@@ -1126,24 +1170,25 @@ describe('ArrayProperty', function () {
|
|
|
1126
1170
|
},
|
|
1127
1171
|
},
|
|
1128
1172
|
{
|
|
1129
|
-
path:
|
|
1173
|
+
path: "MyArray",
|
|
1130
1174
|
type: ChangeSet.ConflictType.ENTRY_MODIFIED_AFTER_REMOVE,
|
|
1131
1175
|
conflictingChange: {
|
|
1132
1176
|
type: ChangeSet.ConflictType.COLLIDING_SET,
|
|
1133
1177
|
operation: [6, [34]],
|
|
1134
1178
|
},
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1179
|
+
},
|
|
1180
|
+
]);
|
|
1181
|
+
expect(changeSet2["array<Float32>"].MyArray).to.deep.equal({
|
|
1182
|
+
modify: [[2, [24, 33, 35]]],
|
|
1138
1183
|
});
|
|
1139
1184
|
done();
|
|
1140
1185
|
}
|
|
1141
1186
|
});
|
|
1142
|
-
it(
|
|
1187
|
+
it("@bugfix ensure existing properties are unparented during deserialization", function () {
|
|
1143
1188
|
// Bug caused by deserialization during rebase
|
|
1144
1189
|
arrayProp = PropertyFactory.create(TestDynamicLengthNonPrimitiveArray.typeid);
|
|
1145
|
-
const customProp = PropertyFactory.create(
|
|
1146
|
-
arrayProp.get(
|
|
1190
|
+
const customProp = PropertyFactory.create("autodesk.test:test.string-1.0.0");
|
|
1191
|
+
arrayProp.get("data").push(customProp);
|
|
1147
1192
|
const state = arrayProp._serialize(false);
|
|
1148
1193
|
arrayProp.deserialize(state);
|
|
1149
1194
|
// Currently, with custom types, the system makes no attempt to detect if the data
|
|
@@ -1154,17 +1199,17 @@ describe('ArrayProperty', function () {
|
|
|
1154
1199
|
expect(arrayProp.isDirty()).to.equal(true); // If this fires then you've optimized this?
|
|
1155
1200
|
expect(customProp.getParent()).to.equal(undefined);
|
|
1156
1201
|
});
|
|
1157
|
-
it(
|
|
1158
|
-
var arrayObj = PropertyFactory.create(
|
|
1159
|
-
var arrayProperty = arrayObj.get(
|
|
1160
|
-
arrayProperty.insert(0, PropertyFactory.create(
|
|
1202
|
+
it("rebase of independent modifies in array", function () {
|
|
1203
|
+
var arrayObj = PropertyFactory.create("autodesk.tests:Complex3Array-1.0.0");
|
|
1204
|
+
var arrayProperty = arrayObj.get("myarray");
|
|
1205
|
+
arrayProperty.insert(0, PropertyFactory.create("autodesk.tests:ComplexProp3-1.0.0"));
|
|
1161
1206
|
arrayObj.cleanDirty();
|
|
1162
1207
|
// Create the first change
|
|
1163
|
-
arrayProperty.get(0).get([
|
|
1208
|
+
arrayProperty.get(0).get(["complex1", "nest", "data"]).setValue(123);
|
|
1164
1209
|
var changeSet1 = new ChangeSet(arrayObj.serialize({ dirtyOnly: true }));
|
|
1165
1210
|
arrayObj.cleanDirty();
|
|
1166
1211
|
// Create the second change
|
|
1167
|
-
arrayProperty.get(0).get([
|
|
1212
|
+
arrayProperty.get(0).get(["complex2", "nest", "data2"]).setValue(123);
|
|
1168
1213
|
var secondChangeSet = arrayObj.serialize({ dirtyOnly: true });
|
|
1169
1214
|
var changeSet2Copy = deepCopy(secondChangeSet);
|
|
1170
1215
|
var conflictsArray = [];
|
|
@@ -1174,65 +1219,65 @@ describe('ArrayProperty', function () {
|
|
|
1174
1219
|
});
|
|
1175
1220
|
// TODO: add more rebase tests here!
|
|
1176
1221
|
});
|
|
1177
|
-
describe(
|
|
1178
|
-
it(
|
|
1179
|
-
var property = PropertyFactory.create(
|
|
1180
|
-
property.resolvePath(
|
|
1181
|
-
property.resolvePath(
|
|
1182
|
-
property.resolvePath(
|
|
1183
|
-
var expectedPrettyStr =
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
var prettyStr =
|
|
1222
|
+
describe("Using prettyPrint()", function () {
|
|
1223
|
+
it("should output a pretty string with number items", function () {
|
|
1224
|
+
var property = PropertyFactory.create("autodesk.test:test.arrayfloat32-1.0.0");
|
|
1225
|
+
property.resolvePath("data").set(0, 4);
|
|
1226
|
+
property.resolvePath("data").set(1, 5);
|
|
1227
|
+
property.resolvePath("data").set(2, 6);
|
|
1228
|
+
var expectedPrettyStr = "undefined (autodesk.test:test.arrayfloat32-1.0.0):\n" +
|
|
1229
|
+
" data (Array of Float32): [\n" +
|
|
1230
|
+
" 0: 4\n" +
|
|
1231
|
+
" 1: 5\n" +
|
|
1232
|
+
" 2: 6\n" +
|
|
1233
|
+
" ]\n";
|
|
1234
|
+
var prettyStr = "";
|
|
1190
1235
|
property.prettyPrint(function (str) {
|
|
1191
|
-
prettyStr += str +
|
|
1236
|
+
prettyStr += str + "\n";
|
|
1192
1237
|
});
|
|
1193
1238
|
expect(prettyStr).to.equal(expectedPrettyStr);
|
|
1194
1239
|
});
|
|
1195
|
-
it(
|
|
1196
|
-
var property = PropertyFactory.create(
|
|
1197
|
-
var expectedPrettyStr =
|
|
1198
|
-
|
|
1240
|
+
it("should output a pretty string with string items", function () {
|
|
1241
|
+
var property = PropertyFactory.create("autodesk.test:test.arraystring-1.0.0");
|
|
1242
|
+
var expectedPrettyStr = "undefined (autodesk.test:test.arraystring-1.0.0):\n" +
|
|
1243
|
+
" data (Array of String): [\n" +
|
|
1199
1244
|
' 0: ""\n' +
|
|
1200
1245
|
' 1: ""\n' +
|
|
1201
1246
|
' 2: ""\n' +
|
|
1202
|
-
|
|
1203
|
-
var prettyStr =
|
|
1247
|
+
" ]\n";
|
|
1248
|
+
var prettyStr = "";
|
|
1204
1249
|
property.prettyPrint(function (str) {
|
|
1205
|
-
prettyStr += str +
|
|
1250
|
+
prettyStr += str + "\n";
|
|
1206
1251
|
});
|
|
1207
1252
|
expect(prettyStr).to.equal(expectedPrettyStr);
|
|
1208
1253
|
});
|
|
1209
|
-
it(
|
|
1210
|
-
var property = PropertyFactory.create(
|
|
1211
|
-
var expectedPrettyStr =
|
|
1212
|
-
|
|
1213
|
-
|
|
1254
|
+
it("should output a pretty string with custom items", function () {
|
|
1255
|
+
var property = PropertyFactory.create("autodesk.test:test.customarray-1.0.0");
|
|
1256
|
+
var expectedPrettyStr = "undefined (autodesk.test:test.customarray-1.0.0):\n" +
|
|
1257
|
+
" data (Array of autodesk.test:test.string-1.0.0): [\n" +
|
|
1258
|
+
" 0: undefined (autodesk.test:test.string-1.0.0):\n" +
|
|
1214
1259
|
' data (String): ""\n' +
|
|
1215
|
-
|
|
1260
|
+
" 1: undefined (autodesk.test:test.string-1.0.0):\n" +
|
|
1216
1261
|
' data (String): ""\n' +
|
|
1217
|
-
|
|
1262
|
+
" 2: undefined (autodesk.test:test.string-1.0.0):\n" +
|
|
1218
1263
|
' data (String): ""\n' +
|
|
1219
|
-
|
|
1220
|
-
var prettyStr =
|
|
1264
|
+
" ]\n";
|
|
1265
|
+
var prettyStr = "";
|
|
1221
1266
|
property.prettyPrint(function (str) {
|
|
1222
|
-
prettyStr += str +
|
|
1267
|
+
prettyStr += str + "\n";
|
|
1223
1268
|
});
|
|
1224
1269
|
expect(prettyStr).to.equal(expectedPrettyStr);
|
|
1225
1270
|
});
|
|
1226
1271
|
});
|
|
1227
|
-
it(
|
|
1228
|
-
var array = PropertyFactory.create(
|
|
1272
|
+
it("should push", function () {
|
|
1273
|
+
var array = PropertyFactory.create("String", "array", [0, 1, 2]);
|
|
1229
1274
|
array.push(3);
|
|
1230
1275
|
array.getLength().should.equal(4);
|
|
1231
1276
|
array.push([4, 5]);
|
|
1232
1277
|
array.getLength().should.equal(6);
|
|
1233
1278
|
});
|
|
1234
|
-
it(
|
|
1235
|
-
var array = PropertyFactory.create(
|
|
1279
|
+
it("should pop", function () {
|
|
1280
|
+
var array = PropertyFactory.create("String", "array", [0, 1, 2]);
|
|
1236
1281
|
var element = array.pop();
|
|
1237
1282
|
element.should.equal(2);
|
|
1238
1283
|
array.pop();
|
|
@@ -1240,8 +1285,8 @@ describe('ArrayProperty', function () {
|
|
|
1240
1285
|
});
|
|
1241
1286
|
// there is no .shiftValue
|
|
1242
1287
|
// should replace the value with a property
|
|
1243
|
-
it.skip(
|
|
1244
|
-
var array = PropertyFactory.create(
|
|
1288
|
+
it.skip("should shift", function () {
|
|
1289
|
+
var array = PropertyFactory.create("String", "array", [0, 1, 2]);
|
|
1245
1290
|
var element = array.shift();
|
|
1246
1291
|
element.should.equal(0);
|
|
1247
1292
|
var elements = array.shift(2);
|
|
@@ -1250,20 +1295,23 @@ describe('ArrayProperty', function () {
|
|
|
1250
1295
|
});
|
|
1251
1296
|
// there is no .unshiftValue
|
|
1252
1297
|
// should replace the value with a property
|
|
1253
|
-
it.skip(
|
|
1254
|
-
var array = PropertyFactory.create(
|
|
1298
|
+
it.skip("should unshift", function () {
|
|
1299
|
+
var array = PropertyFactory.create("String", "array", [0, 1, 2]);
|
|
1255
1300
|
array.unshift(3);
|
|
1256
1301
|
array.getLength().should.equal(4);
|
|
1257
1302
|
array.unshift([4, 5]);
|
|
1258
1303
|
array.getLength().should.equal(6);
|
|
1259
1304
|
});
|
|
1260
|
-
it(
|
|
1261
|
-
var myBoolArray = PropertyFactory.create(
|
|
1305
|
+
it("should support boolean arrays", function () {
|
|
1306
|
+
var myBoolArray = PropertyFactory.create("autodesk.test:test.arraybool-1.0.0")._properties
|
|
1307
|
+
.data;
|
|
1262
1308
|
expect(myBoolArray.length).to.equal(3);
|
|
1263
1309
|
expect(myBoolArray.get(0)).to.equal(false);
|
|
1264
1310
|
expect(myBoolArray.get(1)).to.equal(false);
|
|
1265
1311
|
expect(myBoolArray.get(2)).to.equal(false);
|
|
1266
|
-
expect(function () {
|
|
1312
|
+
expect(function () {
|
|
1313
|
+
myBoolArray.get(3);
|
|
1314
|
+
}).to.throw(Error);
|
|
1267
1315
|
myBoolArray.push(true);
|
|
1268
1316
|
myBoolArray.push(0);
|
|
1269
1317
|
expect(myBoolArray.getLength().should.equal(5));
|
|
@@ -1274,45 +1322,73 @@ describe('ArrayProperty', function () {
|
|
|
1274
1322
|
myBoolArray.insert(0, 1);
|
|
1275
1323
|
expect(myBoolArray.get(0)).to.equal(true);
|
|
1276
1324
|
});
|
|
1277
|
-
it(
|
|
1278
|
-
var myArray = PropertyFactory.create(
|
|
1279
|
-
var prop0 = PropertyFactory.create(
|
|
1280
|
-
|
|
1281
|
-
|
|
1325
|
+
it(".set and .get should convert float index to int", function () {
|
|
1326
|
+
var myArray = PropertyFactory.create("autodesk.test:test.string-1.0.0", "array");
|
|
1327
|
+
var prop0 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1328
|
+
data: "item 0",
|
|
1329
|
+
});
|
|
1330
|
+
var prop1 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1331
|
+
data: "item 1",
|
|
1332
|
+
});
|
|
1333
|
+
var prop2 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1334
|
+
data: "item 2",
|
|
1335
|
+
});
|
|
1282
1336
|
myArray.insertRange(0, [prop0, prop1, prop2]);
|
|
1283
|
-
var prop1_2 = PropertyFactory.create(
|
|
1337
|
+
var prop1_2 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1338
|
+
data: "item 1.2",
|
|
1339
|
+
});
|
|
1284
1340
|
myArray.set(1.2, prop1_2);
|
|
1285
1341
|
expect(myArray.getLength()).to.equal(3);
|
|
1286
1342
|
expect(myArray.get(1.6)).to.equal(prop1_2);
|
|
1287
1343
|
});
|
|
1288
|
-
it(
|
|
1289
|
-
var myArray = PropertyFactory.create(
|
|
1290
|
-
var prop0 = PropertyFactory.create(
|
|
1291
|
-
|
|
1292
|
-
|
|
1344
|
+
it(".set and .get should convert string index to int", function () {
|
|
1345
|
+
var myArray = PropertyFactory.create("autodesk.test:test.string-1.0.0", "array");
|
|
1346
|
+
var prop0 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1347
|
+
data: "item 0",
|
|
1348
|
+
});
|
|
1349
|
+
var prop1 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1350
|
+
data: "item 1",
|
|
1351
|
+
});
|
|
1352
|
+
var prop2 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1353
|
+
data: "item 2",
|
|
1354
|
+
});
|
|
1293
1355
|
myArray.insertRange(0, [prop0, prop1, prop2]);
|
|
1294
|
-
var prop0_3 = PropertyFactory.create(
|
|
1295
|
-
|
|
1356
|
+
var prop0_3 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1357
|
+
data: "item 0.3",
|
|
1358
|
+
});
|
|
1359
|
+
myArray.set("0.3", prop0_3);
|
|
1296
1360
|
expect(myArray.getLength()).to.equal(3);
|
|
1297
|
-
expect(myArray.get(
|
|
1361
|
+
expect(myArray.get("0.6")).to.equal(prop0_3);
|
|
1298
1362
|
});
|
|
1299
|
-
it(
|
|
1300
|
-
var myArray = PropertyFactory.create(
|
|
1301
|
-
var prop0 = PropertyFactory.create(
|
|
1302
|
-
|
|
1303
|
-
|
|
1363
|
+
it(".set and .get should reject float index that cannot be converted to int", function () {
|
|
1364
|
+
var myArray = PropertyFactory.create("autodesk.test:test.string-1.0.0", "array");
|
|
1365
|
+
var prop0 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1366
|
+
data: "item 0",
|
|
1367
|
+
});
|
|
1368
|
+
var prop1 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1369
|
+
data: "item 1",
|
|
1370
|
+
});
|
|
1371
|
+
var prop2 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1372
|
+
data: "item 2",
|
|
1373
|
+
});
|
|
1304
1374
|
myArray.insertRange(0, [prop0, prop1, prop2]);
|
|
1305
|
-
expect(() => myArray.set(Infinity, prop0)).to.throw(MSG.NOT_NUMBER +
|
|
1375
|
+
expect(() => myArray.set(Infinity, prop0)).to.throw(MSG.NOT_NUMBER + "in_offset");
|
|
1306
1376
|
expect(() => myArray.get(NaN)).to.throw(MSG.IN_POSITION_MUST_BE_NUMBER);
|
|
1307
1377
|
});
|
|
1308
|
-
it(
|
|
1309
|
-
var myArray = PropertyFactory.create(
|
|
1310
|
-
var prop0 = PropertyFactory.create(
|
|
1311
|
-
|
|
1312
|
-
|
|
1378
|
+
it(".setValue and .getValue should reject string index that can not be converted to int", function () {
|
|
1379
|
+
var myArray = PropertyFactory.create("autodesk.test:test.string-1.0.0", "array");
|
|
1380
|
+
var prop0 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1381
|
+
data: "item 0",
|
|
1382
|
+
});
|
|
1383
|
+
var prop1 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1384
|
+
data: "item 1",
|
|
1385
|
+
});
|
|
1386
|
+
var prop2 = PropertyFactory.create("autodesk.test:test.string-1.0.0", "single", {
|
|
1387
|
+
data: "item 2",
|
|
1388
|
+
});
|
|
1313
1389
|
myArray.insertRange(0, [prop0, prop1, prop2]);
|
|
1314
|
-
expect(() => myArray.set(
|
|
1315
|
-
expect(() => myArray.get(
|
|
1390
|
+
expect(() => myArray.set("2abc", prop0)).to.throw(MSG.NOT_NUMBER + "in_offset");
|
|
1391
|
+
expect(() => myArray.get("2abc")).to.throw(MSG.IN_POSITION_MUST_BE_NUMBER);
|
|
1316
1392
|
});
|
|
1317
1393
|
});
|
|
1318
1394
|
//# sourceMappingURL=arrayProperty.spec.js.map
|