adjusted gentests

This commit is contained in:
Lukas Woehrl
2016-12-11 16:39:27 +01:00
parent 435f1f6a12
commit d950cf3d10
4 changed files with 90 additions and 69 deletions

View File

@@ -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) + ');');
}},
});

View File

@@ -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;');
}},
});

View File

@@ -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);');
}},
});

View File

@@ -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;
}
}