Let gentest properly create *Auto methods for sizes (#1719)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1719

Right now there is no way to test fixtures with `auto` widths, heights, or flex basis - even though we expose those functions. I updated gentest to generate those functions. Notably, position and margin (the other auto-able props) already account for this.

 I also created `YGAutoTest.html` to test this. Not really testing the capabilities of `auto` here, just if we can create a test about it.

Reviewed By: NickGerleman

Differential Revision: D64125522

fbshipit-source-id: 291ec82003cf53f99c21943142a63e2ef30402a5
This commit is contained in:
Joe Vilches
2024-10-09 19:20:15 -07:00
committed by Facebook GitHub Bot
parent ef9ae63268
commit 820a4d5bf6
6 changed files with 1078 additions and 81 deletions

View File

@@ -0,0 +1,25 @@
<div id="auto_width" style="width: auto; height: 50px; flex-direction: row;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>
<div id="auto_height" style="width: 50px; height: auto;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>
<div id="auto_flex_basis" style="width: 50px; flex-basis: auto;">
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
<div style="width: 50px; height: 50px"></div>
</div>
<div id="auto_position" style="width: 50px; height: 50px;">
<div style="width: 25px; height: 25px; right: auto"></div>
</div>
<div id="auto_margin" style="width: 50px; height: 50px;">
<div style="width: 25px; height: 25px; margin-left: auto"></div>
</div>

View File

@@ -12,7 +12,7 @@ function toValueCpp(value) {
return n + (Number(n) == n && n % 1 !== 0 ? 'f' : '');
}
function toFunctionName(value) {
function toFunctionNameCpp(value) {
if (value.indexOf('%') >= 0) {
return 'Percent';
} else if (value.indexOf('Auto') >= 0) {
@@ -21,6 +21,23 @@ function toFunctionName(value) {
return '';
}
function keywordFunctionCpp(functionPrefix, nodeName, value) {
const functionSuffix = toFunctionNameCpp(value);
if (functionSuffix == 'Auto') {
return functionPrefix + functionSuffix + '(' + nodeName + ');';
} else {
return (
functionPrefix +
functionSuffix +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');'
);
}
}
const CPPEmitter = function () {
Emitter.call(this, 'cpp', ' ');
};
@@ -231,7 +248,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetAspectRatio' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -273,15 +290,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetFlexBasis' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
this.push(keywordFunctionCpp('YGNodeStyleSetFlexBasis', nodeName, value));
},
},
@@ -325,20 +334,6 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
},
},
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetHeight' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) {
this.push(
@@ -361,7 +356,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}
this.push(
'YGNodeStyleSetMargin' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -372,11 +367,23 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
},
},
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(keywordFunctionCpp('YGNodeStyleSetHeight', nodeName, value));
},
},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(keywordFunctionCpp('YGNodeStyleSetWidth', nodeName, value));
},
},
YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMaxHeight' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -390,7 +397,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMaxWidth' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -404,7 +411,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMinHeight' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -418,7 +425,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetMinWidth' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -440,7 +447,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
value: function (nodeName, edge, value) {
this.push(
'YGNodeStyleSetPadding' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -462,7 +469,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
}
this.push(
'YGNodeStyleSetPosition' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +
@@ -485,25 +492,11 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
},
},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
'YGNodeStyleSetWidth' +
toFunctionName(value) +
'(' +
nodeName +
', ' +
toValueCpp(value) +
');',
);
},
},
YGNodeStyleSetGap: {
value: function (nodeName, gap, value) {
this.push(
'YGNodeStyleSetGap' +
toFunctionName(value) +
toFunctionNameCpp(value) +
'(' +
nodeName +
', ' +

View File

@@ -21,6 +21,23 @@ function toMethodName(value) {
return '';
}
function keywordMethod(methodPrefix, nodeName, value) {
const methodSuffix = toMethodName(value);
if (methodSuffix == 'Auto') {
return nodeName + '.' + methodPrefix + methodSuffix + '();';
} else {
return (
nodeName +
'.' +
methodPrefix +
methodSuffix +
'(' +
toValueJava(value) +
'f);'
);
}
}
const JavaEmitter = function () {
Emitter.call(this, 'java', ' ');
};
@@ -273,14 +290,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
YGNodeStyleSetFlexBasis: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setFlexBasis' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
this.push(keywordMethod('setFlexBasis', nodeName, value));
},
},
@@ -308,19 +318,6 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
},
},
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setHeight' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
},
},
YGNodeStyleSetJustifyContent: {
value: function (nodeName, value) {
this.push(nodeName + '.setJustifyContent(' + toValueJava(value) + ');');
@@ -348,6 +345,18 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
},
},
YGNodeStyleSetHeight: {
value: function (nodeName, value) {
this.push(keywordMethod('setHeight', nodeName, value));
},
},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(keywordMethod('setWidth', nodeName, value));
},
},
YGNodeStyleSetMaxHeight: {
value: function (nodeName, value) {
this.push(
@@ -448,19 +457,6 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
},
},
YGNodeStyleSetWidth: {
value: function (nodeName, value) {
this.push(
nodeName +
'.setWidth' +
toMethodName(value) +
'(' +
toValueJava(value) +
'f);',
);
},
},
YGNodeStyleSetGap: {
value: function (nodeName, gap, value) {
this.push(