diff --git a/gentest/fixtures/YGAutoTest.html b/gentest/fixtures/YGAutoTest.html
new file mode 100644
index 00000000..9a812ed1
--- /dev/null
+++ b/gentest/fixtures/YGAutoTest.html
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
diff --git a/gentest/gentest-cpp.js b/gentest/gentest-cpp.js
index 4dde8177..cbae4a2d 100644
--- a/gentest/gentest-cpp.js
+++ b/gentest/gentest-cpp.js
@@ -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 +
', ' +
diff --git a/gentest/gentest-driver.ts b/gentest/gentest-driver.ts
index d31c783c..a0acd6e6 100644
--- a/gentest/gentest-driver.ts
+++ b/gentest/gentest-driver.ts
@@ -100,15 +100,21 @@ for (const fileName of fixtures) {
await driver.get('file://' + process.cwd() + '/test.html');
const logs = await driver.manage().logs().get(logging.Type.BROWSER);
+ const testLogs = logs.filter(
+ log => !log.message.replace(/^[^"]*/, '').startsWith('"gentest-log:'),
+ );
+
await fs.writeFile(
`${yogaDir}/tests/generated/${fileNameNoExtension}.cpp`,
- addSignatureToSourceCode(JSON.parse(logs[0].message.replace(/^[^"]*/, ''))),
+ addSignatureToSourceCode(
+ JSON.parse(testLogs[0].message.replace(/^[^"]*/, '')),
+ ),
);
await fs.writeFile(
`${yogaDir}/java/tests/generated/com/facebook/yoga/${fileNameNoExtension}.java`,
addSignatureToSourceCode(
- JSON.parse(logs[1].message.replace(/^[^"]*/, '')).replace(
+ JSON.parse(testLogs[1].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
),
@@ -118,7 +124,7 @@ for (const fileName of fixtures) {
await fs.writeFile(
`${yogaDir}/javascript/tests/generated/${fileNameNoExtension}.test.ts`,
addSignatureToSourceCode(
- JSON.parse(logs[2].message.replace(/^[^"]*/, '')).replace(
+ JSON.parse(testLogs[2].message.replace(/^[^"]*/, '')).replace(
'YogaTest',
fileNameNoExtension,
),
diff --git a/gentest/gentest-java.js b/gentest/gentest-java.js
index 020d98e3..f7b39c3a 100644
--- a/gentest/gentest-java.js
+++ b/gentest/gentest-java.js
@@ -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(
diff --git a/gentest/gentest-log.js b/gentest/gentest-log.js
new file mode 100644
index 00000000..7f235218
--- /dev/null
+++ b/gentest/gentest-log.js
@@ -0,0 +1,11 @@
+/**
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+// eslint-disable-next-line no-unused-vars
+function gentestLog(message) {
+ console.log('gentest-log: ', message);
+}
diff --git a/gentest/test-template.html b/gentest/test-template.html
index 079eb4df..9638961b 100644
--- a/gentest/test-template.html
+++ b/gentest/test-template.html
@@ -8,6 +8,7 @@
+