From d950cf3d106d50e02d9385818f412c3e6c9a6cb6 Mon Sep 17 00:00:00 2001 From: Lukas Woehrl Date: Sun, 11 Dec 2016 16:39:27 +0100 Subject: [PATCH] adjusted gentests --- gentest/gentest-cpp.js | 59 ++++++++++++++++++++++++----------------- gentest/gentest-cs.js | 49 +++++++++++++++++++--------------- gentest/gentest-java.js | 49 +++++++++++++++++++--------------- gentest/gentest.js | 2 +- 4 files changed, 90 insertions(+), 69 deletions(-) diff --git a/gentest/gentest-cpp.js b/gentest/gentest-cpp.js index 0333dd7c..45700a06 100644 --- a/gentest/gentest-cpp.js +++ b/gentest/gentest-cpp.js @@ -7,9 +7,20 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -function toFloatString(n) { +function toValueCpp(value) { + var n = value.toString().replace('px','').replace('%',''); return n + (Number(n) == n && n % 1 !== 0 ? 'f' : ''); } + +function toValueCppWithUnitCpp(value) { + var methodName = ''; + if(value.indexOf('px') >= 0){ + methodName = 'YGPx'; + }else if (value.indexOf('%') >= 0){ + methodName = 'YGPercent'; + } + return methodName + '(' + toValueCpp(value) + ')'; +} var CPPEmitter = function() { Emitter.call(this, 'cpp', ' '); @@ -66,7 +77,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, { }}, AssertEQ:{value:function(v0, v1) { - this.push('ASSERT_FLOAT_EQ(' + toFloatString(v0) + ', ' + v1 + ');'); + this.push('ASSERT_FLOAT_EQ(' + toValueCpp(v0) + ', ' + v1 + ');'); }}, YGAlignAuto:{value:'YGAlignAuto'}, @@ -133,90 +144,90 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, { }}, YGNodeStyleSetAlignContent:{value:function(nodeName, value) { - this.push('YGNodeStyleSetAlignContent(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetAlignContent(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetAlignItems:{value:function(nodeName, value) { - this.push('YGNodeStyleSetAlignItems(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetAlignItems(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetAlignSelf:{value:function(nodeName, value) { - this.push('YGNodeStyleSetAlignSelf(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetAlignSelf(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetBorder:{value:function(nodeName, edge, value) { - this.push('YGNodeStyleSetBorder(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetBorderWithUnit(' + nodeName + ', ' + edge + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetDirection:{value:function(nodeName, value) { - this.push('YGNodeStyleSetDirection(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetDirection(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetFlexBasis:{value:function(nodeName, value) { - this.push('YGNodeStyleSetFlexBasis(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetFlexBasisWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetFlexDirection:{value:function(nodeName, value) { - this.push('YGNodeStyleSetFlexDirection(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetFlexDirection(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetFlexGrow:{value:function(nodeName, value) { - this.push('YGNodeStyleSetFlexGrow(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetFlexGrow(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetFlexShrink:{value:function(nodeName, value) { - this.push('YGNodeStyleSetFlexShrink(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetFlexShrink(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetFlexWrap:{value:function(nodeName, value) { - this.push('YGNodeStyleSetFlexWrap(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetFlexWrap(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetHeight:{value:function(nodeName, value) { - this.push('YGNodeStyleSetHeight(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetHeightWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetJustifyContent:{value:function(nodeName, value) { - this.push('YGNodeStyleSetJustifyContent(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetJustifyContent(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetMargin:{value:function(nodeName, edge, value) { - this.push('YGNodeStyleSetMargin(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetMarginWithUnit(' + nodeName + ', ' + edge + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetMaxHeight:{value:function(nodeName, value) { - this.push('YGNodeStyleSetMaxHeight(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetMaxHeightWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetMaxWidth:{value:function(nodeName, value) { - this.push('YGNodeStyleSetMaxWidth(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetMaxWidthWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetMinHeight:{value:function(nodeName, value) { - this.push('YGNodeStyleSetMinHeight(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetMinHeightWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetMinWidth:{value:function(nodeName, value) { - this.push('YGNodeStyleSetMinWidth(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetMinWidthWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetOverflow:{value:function(nodeName, value) { - this.push('YGNodeStyleSetOverflow(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetOverflow(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetPadding:{value:function(nodeName, edge, value) { - this.push('YGNodeStyleSetPadding(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetPaddingWithUnit(' + nodeName + ', ' + edge + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetPosition:{value:function(nodeName, edge, value) { - this.push('YGNodeStyleSetPosition(' + nodeName + ', ' + edge + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetPositionWithUnit(' + nodeName + ', ' + edge + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, YGNodeStyleSetPositionType:{value:function(nodeName, value) { - this.push('YGNodeStyleSetPositionType(' + nodeName + ', ' + value + ');'); + this.push('YGNodeStyleSetPositionType(' + nodeName + ', ' + toValueCpp(value) + ');'); }}, YGNodeStyleSetWidth:{value:function(nodeName, value) { - this.push('YGNodeStyleSetWidth(' + nodeName + ', ' + toFloatString(value) + ');'); + this.push('YGNodeStyleSetWidthWithUnit(' + nodeName + ', ' + toValueCppWithUnitCpp(value) + ');'); }}, }); diff --git a/gentest/gentest-cs.js b/gentest/gentest-cs.js index 0dbbb498..293b188c 100644 --- a/gentest/gentest-cs.js +++ b/gentest/gentest-cs.js @@ -7,6 +7,11 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +function toValueCs(value) { + var n = value.toString().replace('px','').replace('%',''); + return n + (Number(n) == n && n % 1 !== 0 ? '' : ''); +} + var CSEmitter = function() { Emitter.call(this, 'cs', ' '); }; @@ -143,90 +148,90 @@ CSEmitter.prototype = Object.create(Emitter.prototype, { }}, YGNodeStyleSetAlignContent:{value:function(nodeName, value) { - this.push(nodeName + '.AlignContent = ' + value + ';'); + this.push(nodeName + '.AlignContent = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetAlignItems:{value:function(nodeName, value) { - this.push(nodeName + '.AlignItems = ' + value + ';'); + this.push(nodeName + '.AlignItems = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetAlignSelf:{value:function(nodeName, value) { - this.push(nodeName + '.AlignSelf = ' + value + ';'); + this.push(nodeName + '.AlignSelf = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetBorder:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetBorder(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.SetBorder(' + edge + ', ' + toValueCs(value) + 'f);'); }}, YGNodeStyleSetDirection:{value:function(nodeName, value) { - this.push(nodeName + '.StyleDirection = ' + value + ';'); + this.push(nodeName + '.StyleDirection = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetFlexBasis:{value:function(nodeName, value) { - this.push(nodeName + '.FlexBasis = ' + value + 'f;'); + this.push(nodeName + '.FlexBasis = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetFlexDirection:{value:function(nodeName, value) { - this.push(nodeName + '.FlexDirection = ' + value + ';'); + this.push(nodeName + '.FlexDirection = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetFlexGrow:{value:function(nodeName, value) { - this.push(nodeName + '.FlexGrow = ' + value + 'f;'); + this.push(nodeName + '.FlexGrow = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetFlexShrink:{value:function(nodeName, value) { - this.push(nodeName + '.FlexShrink = ' + value + 'f;'); + this.push(nodeName + '.FlexShrink = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetFlexWrap:{value:function(nodeName, value) { - this.push(nodeName + '.Wrap = ' + value + ';'); + this.push(nodeName + '.Wrap = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetHeight:{value:function(nodeName, value) { - this.push(nodeName + '.Height = ' + value + 'f;'); + this.push(nodeName + '.Height = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetJustifyContent:{value:function(nodeName, value) { - this.push(nodeName + '.JustifyContent = ' + value + ';'); + this.push(nodeName + '.JustifyContent = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetMargin:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetMargin(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.SetMargin(' + edge + ', ' + toValueCs(value) + 'f);'); }}, YGNodeStyleSetMaxHeight:{value:function(nodeName, value) { - this.push(nodeName + '.MaxHeight = ' + value + 'f;'); + this.push(nodeName + '.MaxHeight = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetMaxWidth:{value:function(nodeName, value) { - this.push(nodeName + '.MaxWidth = ' + value + 'f;'); + this.push(nodeName + '.MaxWidth = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetMinHeight:{value:function(nodeName, value) { - this.push(nodeName + '.MinHeight = ' + value + 'f;'); + this.push(nodeName + '.MinHeight = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetMinWidth:{value:function(nodeName, value) { - this.push(nodeName + '.MinWidth = ' + value + 'f;'); + this.push(nodeName + '.MinWidth = ' + toValueCs(value) + 'f;'); }}, YGNodeStyleSetOverflow:{value:function(nodeName, value) { - this.push(nodeName + '.Overflow = ' + value + ';'); + this.push(nodeName + '.Overflow = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetPadding:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetPadding(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.SetPadding(' + edge + ', ' + toValueCs(value) + 'f);'); }}, YGNodeStyleSetPosition:{value:function(nodeName, edge, value) { - this.push(nodeName + '.SetPosition(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.SetPosition(' + edge + ', ' + toValueCs(value) + 'f);'); }}, YGNodeStyleSetPositionType:{value:function(nodeName, value) { - this.push(nodeName + '.PositionType = ' + value + ';'); + this.push(nodeName + '.PositionType = ' + toValueCs(value) + ';'); }}, YGNodeStyleSetWidth:{value:function(nodeName, value) { - this.push(nodeName + '.Width = ' + value + 'f;'); + this.push(nodeName + '.Width = ' + toValueCs(value) + 'f;'); }}, }); diff --git a/gentest/gentest-java.js b/gentest/gentest-java.js index 7034c617..1d876d4f 100644 --- a/gentest/gentest-java.js +++ b/gentest/gentest-java.js @@ -7,6 +7,11 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +function toValueJava(value) { + var n = value.toString().replace('px','').replace('%',''); + return n + (Number(n) == n && n % 1 !== 0 ? '' : ''); +} + var JavaEmitter = function() { Emitter.call(this, 'java', ' '); }; @@ -148,90 +153,90 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, { }}, YGNodeStyleSetAlignContent:{value:function(nodeName, value) { - this.push(nodeName + '.setAlignContent(' + value + ');'); + this.push(nodeName + '.setAlignContent(' + toValueJava(value) + ');'); }}, YGNodeStyleSetAlignItems:{value:function(nodeName, value) { - this.push(nodeName + '.setAlignItems(' + value + ');'); + this.push(nodeName + '.setAlignItems(' + toValueJava(value) + ');'); }}, YGNodeStyleSetAlignSelf:{value:function(nodeName, value) { - this.push(nodeName + '.setAlignSelf(' + value + ');'); + this.push(nodeName + '.setAlignSelf(' + toValueJava(value) + ');'); }}, YGNodeStyleSetBorder:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setBorder(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.setBorder(' + edge + ', ' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetDirection:{value:function(nodeName, value) { - this.push(nodeName + '.setDirection(' + value + ');'); + this.push(nodeName + '.setDirection(' + toValueJava(value) + ');'); }}, YGNodeStyleSetFlexBasis:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexBasis(' + value + 'f);'); + this.push(nodeName + '.setFlexBasis(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetFlexDirection:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexDirection(' + value + ');'); + this.push(nodeName + '.setFlexDirection(' + toValueJava(value) + ');'); }}, YGNodeStyleSetFlexGrow:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexGrow(' + value + 'f);'); + this.push(nodeName + '.setFlexGrow(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetFlexShrink:{value:function(nodeName, value) { - this.push(nodeName + '.setFlexShrink(' + value + 'f);'); + this.push(nodeName + '.setFlexShrink(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetFlexWrap:{value:function(nodeName, value) { - this.push(nodeName + '.setWrap(' + value + ');'); + this.push(nodeName + '.setWrap(' + toValueJava(value) + ');'); }}, YGNodeStyleSetHeight:{value:function(nodeName, value) { - this.push(nodeName + '.setHeight(' + value + 'f);'); + this.push(nodeName + '.setHeight(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetJustifyContent:{value:function(nodeName, value) { - this.push(nodeName + '.setJustifyContent(' + value + ');'); + this.push(nodeName + '.setJustifyContent(' + toValueJava(value) + ');'); }}, YGNodeStyleSetMargin:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setMargin(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.setMargin(' + edge + ', ' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetMaxHeight:{value:function(nodeName, value) { - this.push(nodeName + '.setMaxHeight(' + value + 'f);'); + this.push(nodeName + '.setMaxHeight(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetMaxWidth:{value:function(nodeName, value) { - this.push(nodeName + '.setMaxWidth(' + value + 'f);'); + this.push(nodeName + '.setMaxWidth(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetMinHeight:{value:function(nodeName, value) { - this.push(nodeName + '.setMinHeight(' + value + 'f);'); + this.push(nodeName + '.setMinHeight(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetMinWidth:{value:function(nodeName, value) { - this.push(nodeName + '.setMinWidth(' + value + 'f);'); + this.push(nodeName + '.setMinWidth(' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetOverflow:{value:function(nodeName, value) { - this.push(nodeName + '.setOverflow(' + value + ');'); + this.push(nodeName + '.setOverflow(' + toValueJava(value) + ');'); }}, YGNodeStyleSetPadding:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setPadding(' + edge + ', ' + value + ');'); + this.push(nodeName + '.setPadding(' + edge + ', ' + toValueJava(value) + ');'); }}, YGNodeStyleSetPosition:{value:function(nodeName, edge, value) { - this.push(nodeName + '.setPosition(' + edge + ', ' + value + 'f);'); + this.push(nodeName + '.setPosition(' + edge + ', ' + toValueJava(value) + 'f);'); }}, YGNodeStyleSetPositionType:{value:function(nodeName, value) { - this.push(nodeName + '.setPositionType(' + value + ');'); + this.push(nodeName + '.setPositionType(' + toValueJava(value) + ');'); }}, YGNodeStyleSetWidth:{value:function(nodeName, value) { - this.push(nodeName + '.setWidth(' + value + 'f);'); + this.push(nodeName + '.setWidth(' + toValueJava(value) + 'f);'); }}, }); diff --git a/gentest/gentest.js b/gentest/gentest.js index 196a8c1e..552104a2 100755 --- a/gentest/gentest.js +++ b/gentest/gentest.js @@ -378,7 +378,7 @@ function pixelValue(e, value) { switch (value) { case 'auto': return e.YGUndefined; case 'undefined': return e.YGUndefined; - default: return value.replace('px', ''); + default: return value; } }