diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-08-26 00:32:37 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-08-26 22:27:55 -0700 |
commit | 35a1c01166f997deaa386bf30247e7cb1ed33e07 (patch) | |
tree | 7efb47d4f882c184c9f06574d64d5c5917a8897e /platform/darwin/scripts/generate-style-code.js | |
parent | b1cc89fc9c83784c30afcf67e40130ddc69d989c (diff) | |
download | qtlocation-mapboxgl-35a1c01166f997deaa386bf30247e7cb1ed33e07.tar.gz |
[ios, macos] Test roundtripping property functions
Diffstat (limited to 'platform/darwin/scripts/generate-style-code.js')
-rw-r--r-- | platform/darwin/scripts/generate-style-code.js | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index 8980a3b01c..cd4ab94e36 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -25,45 +25,49 @@ global.arrayType = function (property) { return property.type === 'array' ? property.name.split('-').pop() : false; }; -global.testImplementation = function (property, layerType) { - let helperMsg = testHelperMessage(property, layerType); +global.testImplementation = function (property, layerType, isFunction) { + let helperMsg = testHelperMessage(property, layerType, isFunction); return `layer.${objCName(property)} = [MGLRuntimeStylingHelper ${helperMsg}];`; } -global.testGetterImplementation = function (property, layerType) { - let helperMsg = testHelperMessage(property, layerType); +global.testGetterImplementation = function (property, layerType, isFunction) { + let helperMsg = testHelperMessage(property, layerType, isFunction); let value = `[MGLRuntimeStylingHelper ${helperMsg}]`; if (property.type === 'enum') { - return `XCTAssert([(NSValue *)gLayer.${objCName(property)} isEqualToValue:${value}]);`; + if (isFunction) { + return `XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`; + } + return `XCTAssert([(NSValue *)gLayer.${objCName(property)} isEqualToValue:${value}], @"%@ is not equal to %@", gLayer.${objCName(property)}, ${value});`; } return `XCTAssertEqualObjects(gLayer.${objCName(property)}, ${value});`; } -global.testHelperMessage = function (property, layerType) { +global.testHelperMessage = function (property, layerType, isFunction) { + let fnSuffix = isFunction ? 'Function' : ''; switch (property.type) { case 'boolean': - return 'testBool'; + return 'testBool' + fnSuffix; case 'number': - return 'testNumber'; + return 'testNumber' + fnSuffix; case 'string': - return 'testString'; + return 'testString' + fnSuffix; case 'enum': let objCType = `${prefix}${camelize(layerType)}${suffix}${camelize(property.name)}`; let objCEnum = `${objCType}${camelize(property.values[property.values.length-1])}`; - return `testEnum:${objCEnum} type:@encode(${objCType})`; + return `testEnum${fnSuffix}:${objCEnum} type:@encode(${objCType})`; case 'color': - return 'testColor'; + return 'testColor' + fnSuffix; case 'array': switch (arrayType(property)) { case 'dasharray': - return `testDashArray`; + return 'testDashArray' + fnSuffix; case 'font': - return `testFont`; + return 'testFont' + fnSuffix; case 'padding': - return `testPadding`; + return 'testPadding' + fnSuffix; case 'offset': case 'translate': - return `testOffset`; + return 'testOffset' + fnSuffix; default: throw new Error(`unknown array type for ${property.name}`); } |