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:
committed by
Facebook GitHub Bot
parent
ef9ae63268
commit
820a4d5bf6
25
gentest/fixtures/YGAutoTest.html
Normal file
25
gentest/fixtures/YGAutoTest.html
Normal 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>
|
@@ -12,7 +12,7 @@ function toValueCpp(value) {
|
|||||||
return n + (Number(n) == n && n % 1 !== 0 ? 'f' : '');
|
return n + (Number(n) == n && n % 1 !== 0 ? 'f' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function toFunctionName(value) {
|
function toFunctionNameCpp(value) {
|
||||||
if (value.indexOf('%') >= 0) {
|
if (value.indexOf('%') >= 0) {
|
||||||
return 'Percent';
|
return 'Percent';
|
||||||
} else if (value.indexOf('Auto') >= 0) {
|
} else if (value.indexOf('Auto') >= 0) {
|
||||||
@@ -21,6 +21,23 @@ function toFunctionName(value) {
|
|||||||
return '';
|
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 () {
|
const CPPEmitter = function () {
|
||||||
Emitter.call(this, 'cpp', ' ');
|
Emitter.call(this, 'cpp', ' ');
|
||||||
};
|
};
|
||||||
@@ -231,7 +248,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetAspectRatio' +
|
'YGNodeStyleSetAspectRatio' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
@@ -273,15 +290,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
|
|
||||||
YGNodeStyleSetFlexBasis: {
|
YGNodeStyleSetFlexBasis: {
|
||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(keywordFunctionCpp('YGNodeStyleSetFlexBasis', nodeName, value));
|
||||||
'YGNodeStyleSetFlexBasis' +
|
|
||||||
toFunctionName(value) +
|
|
||||||
'(' +
|
|
||||||
nodeName +
|
|
||||||
', ' +
|
|
||||||
toValueCpp(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: {
|
YGNodeStyleSetJustifyContent: {
|
||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(
|
||||||
@@ -361,7 +356,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
}
|
}
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetMargin' +
|
'YGNodeStyleSetMargin' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
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: {
|
YGNodeStyleSetMaxHeight: {
|
||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetMaxHeight' +
|
'YGNodeStyleSetMaxHeight' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
@@ -390,7 +397,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetMaxWidth' +
|
'YGNodeStyleSetMaxWidth' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
@@ -404,7 +411,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetMinHeight' +
|
'YGNodeStyleSetMinHeight' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
@@ -418,7 +425,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetMinWidth' +
|
'YGNodeStyleSetMinWidth' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
@@ -440,7 +447,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
value: function (nodeName, edge, value) {
|
value: function (nodeName, edge, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetPadding' +
|
'YGNodeStyleSetPadding' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
@@ -462,7 +469,7 @@ CPPEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
}
|
}
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetPosition' +
|
'YGNodeStyleSetPosition' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
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: {
|
YGNodeStyleSetGap: {
|
||||||
value: function (nodeName, gap, value) {
|
value: function (nodeName, gap, value) {
|
||||||
this.push(
|
this.push(
|
||||||
'YGNodeStyleSetGap' +
|
'YGNodeStyleSetGap' +
|
||||||
toFunctionName(value) +
|
toFunctionNameCpp(value) +
|
||||||
'(' +
|
'(' +
|
||||||
nodeName +
|
nodeName +
|
||||||
', ' +
|
', ' +
|
||||||
|
@@ -21,6 +21,23 @@ function toMethodName(value) {
|
|||||||
return '';
|
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 () {
|
const JavaEmitter = function () {
|
||||||
Emitter.call(this, 'java', ' ');
|
Emitter.call(this, 'java', ' ');
|
||||||
};
|
};
|
||||||
@@ -273,14 +290,7 @@ JavaEmitter.prototype = Object.create(Emitter.prototype, {
|
|||||||
|
|
||||||
YGNodeStyleSetFlexBasis: {
|
YGNodeStyleSetFlexBasis: {
|
||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
this.push(keywordMethod('setFlexBasis', nodeName, value));
|
||||||
nodeName +
|
|
||||||
'.setFlexBasis' +
|
|
||||||
toMethodName(value) +
|
|
||||||
'(' +
|
|
||||||
toValueJava(value) +
|
|
||||||
'f);',
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -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: {
|
YGNodeStyleSetJustifyContent: {
|
||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(nodeName + '.setJustifyContent(' + toValueJava(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: {
|
YGNodeStyleSetMaxHeight: {
|
||||||
value: function (nodeName, value) {
|
value: function (nodeName, value) {
|
||||||
this.push(
|
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: {
|
YGNodeStyleSetGap: {
|
||||||
value: function (nodeName, gap, value) {
|
value: function (nodeName, gap, value) {
|
||||||
this.push(
|
this.push(
|
||||||
|
325
java/tests/generated/com/facebook/yoga/YGAutoTest.java
Normal file
325
java/tests/generated/com/facebook/yoga/YGAutoTest.java
Normal file
@@ -0,0 +1,325 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @generated SignedSource<<30103b31d09984d8443cf1ba544adeb7>>
|
||||||
|
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.facebook.yoga;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
import com.facebook.yoga.utils.TestUtils;
|
||||||
|
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
public class YGAutoTest {
|
||||||
|
@Parameterized.Parameters(name = "{0}")
|
||||||
|
public static Iterable<TestParametrization.NodeFactory> nodeFactories() {
|
||||||
|
return TestParametrization.nodeFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parameterized.Parameter public TestParametrization.NodeFactory mNodeFactory;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_auto_width() {
|
||||||
|
YogaConfig config = YogaConfigFactory.create();
|
||||||
|
|
||||||
|
final YogaNode root = createNode(config);
|
||||||
|
root.setFlexDirection(YogaFlexDirection.ROW);
|
||||||
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||||
|
root.setWidthAuto();
|
||||||
|
root.setHeight(50f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = createNode(config);
|
||||||
|
root_child0.setWidth(50f);
|
||||||
|
root_child0.setHeight(50f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = createNode(config);
|
||||||
|
root_child1.setWidth(50f);
|
||||||
|
root_child1.setHeight(50f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
|
||||||
|
final YogaNode root_child2 = createNode(config);
|
||||||
|
root_child2.setWidth(50f);
|
||||||
|
root_child2.setHeight(50f);
|
||||||
|
root.addChildAt(root_child2, 2);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(150f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(100f, root_child2.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(150f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(100f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(50f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child2.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_auto_height() {
|
||||||
|
YogaConfig config = YogaConfigFactory.create();
|
||||||
|
|
||||||
|
final YogaNode root = createNode(config);
|
||||||
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||||
|
root.setWidth(50f);
|
||||||
|
root.setHeightAuto();
|
||||||
|
|
||||||
|
final YogaNode root_child0 = createNode(config);
|
||||||
|
root_child0.setWidth(50f);
|
||||||
|
root_child0.setHeight(50f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = createNode(config);
|
||||||
|
root_child1.setWidth(50f);
|
||||||
|
root_child1.setHeight(50f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
|
||||||
|
final YogaNode root_child2 = createNode(config);
|
||||||
|
root_child2.setWidth(50f);
|
||||||
|
root_child2.setHeight(50f);
|
||||||
|
root.addChildAt(root_child2, 2);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(150f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(150f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_auto_flex_basis() {
|
||||||
|
YogaConfig config = YogaConfigFactory.create();
|
||||||
|
|
||||||
|
final YogaNode root = createNode(config);
|
||||||
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||||
|
root.setWidth(50f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = createNode(config);
|
||||||
|
root_child0.setWidth(50f);
|
||||||
|
root_child0.setHeight(50f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
|
||||||
|
final YogaNode root_child1 = createNode(config);
|
||||||
|
root_child1.setWidth(50f);
|
||||||
|
root_child1.setHeight(50f);
|
||||||
|
root.addChildAt(root_child1, 1);
|
||||||
|
|
||||||
|
final YogaNode root_child2 = createNode(config);
|
||||||
|
root_child2.setWidth(50f);
|
||||||
|
root_child2.setHeight(50f);
|
||||||
|
root.addChildAt(root_child2, 2);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(150f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(150f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child1.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child2.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(100f, root_child2.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root_child2.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_auto_position() {
|
||||||
|
YogaConfig config = YogaConfigFactory.create();
|
||||||
|
|
||||||
|
final YogaNode root = createNode(config);
|
||||||
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||||
|
root.setWidth(50f);
|
||||||
|
root.setHeight(50f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = createNode(config);
|
||||||
|
root_child0.setPositionAuto(YogaEdge.RIGHT);
|
||||||
|
root_child0.setWidth(25f);
|
||||||
|
root_child0.setHeight(25f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test_auto_margin() {
|
||||||
|
YogaConfig config = YogaConfigFactory.create();
|
||||||
|
|
||||||
|
final YogaNode root = createNode(config);
|
||||||
|
root.setPositionType(YogaPositionType.ABSOLUTE);
|
||||||
|
root.setWidth(50f);
|
||||||
|
root.setHeight(50f);
|
||||||
|
|
||||||
|
final YogaNode root_child0 = createNode(config);
|
||||||
|
root_child0.setMarginAuto(YogaEdge.LEFT);
|
||||||
|
root_child0.setWidth(25f);
|
||||||
|
root_child0.setHeight(25f);
|
||||||
|
root.addChildAt(root_child0, 0);
|
||||||
|
root.setDirection(YogaDirection.LTR);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
root.setDirection(YogaDirection.RTL);
|
||||||
|
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
|
||||||
|
|
||||||
|
assertEquals(0f, root.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(50f, root.getLayoutHeight(), 0.0f);
|
||||||
|
|
||||||
|
assertEquals(25f, root_child0.getLayoutX(), 0.0f);
|
||||||
|
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutWidth(), 0.0f);
|
||||||
|
assertEquals(25f, root_child0.getLayoutHeight(), 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
private YogaNode createNode(YogaConfig config) {
|
||||||
|
return mNodeFactory.create(config);
|
||||||
|
}
|
||||||
|
}
|
347
javascript/tests/generated/YGAutoTest.test.ts
Normal file
347
javascript/tests/generated/YGAutoTest.test.ts
Normal file
@@ -0,0 +1,347 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @generated SignedSource<<234cdb7f76ac586e034a5b6ca2033fa4>>
|
||||||
|
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
|
||||||
|
import Yoga from 'yoga-layout';
|
||||||
|
import {
|
||||||
|
Align,
|
||||||
|
BoxSizing,
|
||||||
|
Direction,
|
||||||
|
Display,
|
||||||
|
Edge,
|
||||||
|
Errata,
|
||||||
|
ExperimentalFeature,
|
||||||
|
FlexDirection,
|
||||||
|
Gutter,
|
||||||
|
Justify,
|
||||||
|
MeasureMode,
|
||||||
|
Overflow,
|
||||||
|
PositionType,
|
||||||
|
Unit,
|
||||||
|
Wrap,
|
||||||
|
} from 'yoga-layout';
|
||||||
|
|
||||||
|
test('auto_width', () => {
|
||||||
|
const config = Yoga.Config.create();
|
||||||
|
let root;
|
||||||
|
|
||||||
|
try {
|
||||||
|
root = Yoga.Node.create(config);
|
||||||
|
root.setFlexDirection(FlexDirection.Row);
|
||||||
|
root.setPositionType(PositionType.Absolute);
|
||||||
|
root.setWidth('auto');
|
||||||
|
root.setHeight(50);
|
||||||
|
|
||||||
|
const root_child0 = Yoga.Node.create(config);
|
||||||
|
root_child0.setWidth(50);
|
||||||
|
root_child0.setHeight(50);
|
||||||
|
root.insertChild(root_child0, 0);
|
||||||
|
|
||||||
|
const root_child1 = Yoga.Node.create(config);
|
||||||
|
root_child1.setWidth(50);
|
||||||
|
root_child1.setHeight(50);
|
||||||
|
root.insertChild(root_child1, 1);
|
||||||
|
|
||||||
|
const root_child2 = Yoga.Node.create(config);
|
||||||
|
root_child2.setWidth(50);
|
||||||
|
root_child2.setHeight(50);
|
||||||
|
root.insertChild(root_child2, 2);
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(150);
|
||||||
|
expect(root.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child1.getComputedLeft()).toBe(50);
|
||||||
|
expect(root_child1.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child2.getComputedLeft()).toBe(100);
|
||||||
|
expect(root_child2.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(150);
|
||||||
|
expect(root.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(100);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child1.getComputedLeft()).toBe(50);
|
||||||
|
expect(root_child1.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child2.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||||||
|
} finally {
|
||||||
|
if (typeof root !== 'undefined') {
|
||||||
|
root.freeRecursive();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.free();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
test('auto_height', () => {
|
||||||
|
const config = Yoga.Config.create();
|
||||||
|
let root;
|
||||||
|
|
||||||
|
try {
|
||||||
|
root = Yoga.Node.create(config);
|
||||||
|
root.setPositionType(PositionType.Absolute);
|
||||||
|
root.setWidth(50);
|
||||||
|
root.setHeight('auto');
|
||||||
|
|
||||||
|
const root_child0 = Yoga.Node.create(config);
|
||||||
|
root_child0.setWidth(50);
|
||||||
|
root_child0.setHeight(50);
|
||||||
|
root.insertChild(root_child0, 0);
|
||||||
|
|
||||||
|
const root_child1 = Yoga.Node.create(config);
|
||||||
|
root_child1.setWidth(50);
|
||||||
|
root_child1.setHeight(50);
|
||||||
|
root.insertChild(root_child1, 1);
|
||||||
|
|
||||||
|
const root_child2 = Yoga.Node.create(config);
|
||||||
|
root_child2.setWidth(50);
|
||||||
|
root_child2.setHeight(50);
|
||||||
|
root.insertChild(root_child2, 2);
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(150);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||||||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||||||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(150);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||||||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||||||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||||||
|
} finally {
|
||||||
|
if (typeof root !== 'undefined') {
|
||||||
|
root.freeRecursive();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.free();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
test('auto_flex_basis', () => {
|
||||||
|
const config = Yoga.Config.create();
|
||||||
|
let root;
|
||||||
|
|
||||||
|
try {
|
||||||
|
root = Yoga.Node.create(config);
|
||||||
|
root.setPositionType(PositionType.Absolute);
|
||||||
|
root.setWidth(50);
|
||||||
|
|
||||||
|
const root_child0 = Yoga.Node.create(config);
|
||||||
|
root_child0.setWidth(50);
|
||||||
|
root_child0.setHeight(50);
|
||||||
|
root.insertChild(root_child0, 0);
|
||||||
|
|
||||||
|
const root_child1 = Yoga.Node.create(config);
|
||||||
|
root_child1.setWidth(50);
|
||||||
|
root_child1.setHeight(50);
|
||||||
|
root.insertChild(root_child1, 1);
|
||||||
|
|
||||||
|
const root_child2 = Yoga.Node.create(config);
|
||||||
|
root_child2.setWidth(50);
|
||||||
|
root_child2.setHeight(50);
|
||||||
|
root.insertChild(root_child2, 2);
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(150);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||||||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||||||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(150);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||||||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||||||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||||||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||||||
|
} finally {
|
||||||
|
if (typeof root !== 'undefined') {
|
||||||
|
root.freeRecursive();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.free();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
test('auto_position', () => {
|
||||||
|
const config = Yoga.Config.create();
|
||||||
|
let root;
|
||||||
|
|
||||||
|
try {
|
||||||
|
root = Yoga.Node.create(config);
|
||||||
|
root.setPositionType(PositionType.Absolute);
|
||||||
|
root.setWidth(50);
|
||||||
|
root.setHeight(50);
|
||||||
|
|
||||||
|
const root_child0 = Yoga.Node.create(config);
|
||||||
|
root_child0.setPositionAuto(Edge.Right);
|
||||||
|
root_child0.setWidth(25);
|
||||||
|
root_child0.setHeight(25);
|
||||||
|
root.insertChild(root_child0, 0);
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||||||
|
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(25);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||||||
|
} finally {
|
||||||
|
if (typeof root !== 'undefined') {
|
||||||
|
root.freeRecursive();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.free();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
test('auto_margin', () => {
|
||||||
|
const config = Yoga.Config.create();
|
||||||
|
let root;
|
||||||
|
|
||||||
|
try {
|
||||||
|
root = Yoga.Node.create(config);
|
||||||
|
root.setPositionType(PositionType.Absolute);
|
||||||
|
root.setWidth(50);
|
||||||
|
root.setHeight(50);
|
||||||
|
|
||||||
|
const root_child0 = Yoga.Node.create(config);
|
||||||
|
root_child0.setMargin(Edge.Left, 'auto');
|
||||||
|
root_child0.setWidth(25);
|
||||||
|
root_child0.setHeight(25);
|
||||||
|
root.insertChild(root_child0, 0);
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(25);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||||||
|
|
||||||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||||||
|
|
||||||
|
expect(root.getComputedLeft()).toBe(0);
|
||||||
|
expect(root.getComputedTop()).toBe(0);
|
||||||
|
expect(root.getComputedWidth()).toBe(50);
|
||||||
|
expect(root.getComputedHeight()).toBe(50);
|
||||||
|
|
||||||
|
expect(root_child0.getComputedLeft()).toBe(25);
|
||||||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||||||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||||||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||||||
|
} finally {
|
||||||
|
if (typeof root !== 'undefined') {
|
||||||
|
root.freeRecursive();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.free();
|
||||||
|
}
|
||||||
|
});
|
311
tests/generated/YGAutoTest.cpp
Normal file
311
tests/generated/YGAutoTest.cpp
Normal file
@@ -0,0 +1,311 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* clang-format off
|
||||||
|
* @generated SignedSource<<00e4ee58a2a66a3fcd064d3c517d8330>>
|
||||||
|
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <yoga/Yoga.h>
|
||||||
|
#include "../util/TestUtil.h"
|
||||||
|
|
||||||
|
TEST(YogaTest, auto_width) {
|
||||||
|
YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
|
||||||
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||||
|
YGNodeStyleSetWidthAuto(root);
|
||||||
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 50);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 50);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
|
YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child2, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child2, 50);
|
||||||
|
YGNodeInsertChild(root, root_child2, 2);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
|
YGConfigFree(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, auto_height) {
|
||||||
|
YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||||
|
YGNodeStyleSetWidth(root, 50);
|
||||||
|
YGNodeStyleSetHeightAuto(root);
|
||||||
|
|
||||||
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 50);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 50);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
|
YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child2, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child2, 50);
|
||||||
|
YGNodeInsertChild(root, root_child2, 2);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
|
YGConfigFree(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, auto_flex_basis) {
|
||||||
|
YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||||
|
YGNodeStyleSetWidth(root, 50);
|
||||||
|
|
||||||
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child0, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 50);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
|
||||||
|
YGNodeRef root_child1 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child1, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child1, 50);
|
||||||
|
YGNodeInsertChild(root, root_child1, 1);
|
||||||
|
|
||||||
|
YGNodeRef root_child2 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetWidth(root_child2, 50);
|
||||||
|
YGNodeStyleSetHeight(root_child2, 50);
|
||||||
|
YGNodeInsertChild(root, root_child2, 2);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(150, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetTop(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child1));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child1));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(100, YGNodeLayoutGetTop(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root_child2));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root_child2));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
|
YGConfigFree(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, auto_position) {
|
||||||
|
YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||||
|
YGNodeStyleSetWidth(root, 50);
|
||||||
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetPositionAuto(root_child0, YGEdgeRight);
|
||||||
|
YGNodeStyleSetWidth(root_child0, 25);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 25);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
|
YGConfigFree(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YogaTest, auto_margin) {
|
||||||
|
YGConfigRef config = YGConfigNew();
|
||||||
|
|
||||||
|
YGNodeRef root = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
|
||||||
|
YGNodeStyleSetWidth(root, 50);
|
||||||
|
YGNodeStyleSetHeight(root, 50);
|
||||||
|
|
||||||
|
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
|
||||||
|
YGNodeStyleSetMarginAuto(root_child0, YGEdgeLeft);
|
||||||
|
YGNodeStyleSetWidth(root_child0, 25);
|
||||||
|
YGNodeStyleSetHeight(root_child0, 25);
|
||||||
|
YGNodeInsertChild(root, root_child0, 0);
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetWidth(root));
|
||||||
|
ASSERT_FLOAT_EQ(50, YGNodeLayoutGetHeight(root));
|
||||||
|
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetLeft(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetWidth(root_child0));
|
||||||
|
ASSERT_FLOAT_EQ(25, YGNodeLayoutGetHeight(root_child0));
|
||||||
|
|
||||||
|
YGNodeFreeRecursive(root);
|
||||||
|
|
||||||
|
YGConfigFree(config);
|
||||||
|
}
|
Reference in New Issue
Block a user