added basic java, csharp and javascript tests for reference baseline feature
Summary: @public We added a functionality using which child node can tell parent node to use it as a reference baseline. Added some tests for java, csharp, javascript language bindings. Reviewed By: davidaurelio Differential Revision: D12997442 fbshipit-source-id: 4717167d2b3862bf2af87b663bda82f9c1eae33e
This commit is contained in:
committed by
Facebook Github Bot
parent
4e2011c381
commit
63570613d3
104
csharp/tests/Facebook.Yoga/YGAlignBaselineTest.cs
Normal file
104
csharp/tests/Facebook.Yoga/YGAlignBaselineTest.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Facebook.Yoga
|
||||
{
|
||||
[TestFixture]
|
||||
public class YGAlignBaselineTest
|
||||
{
|
||||
[Test]
|
||||
public void Test_align_baseline_parent_using_child_in_column_as_reference()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
YogaNode root = createYGNode(config, YogaFlexDirection.Row, 1000, 1000, true);
|
||||
|
||||
YogaNode root_child0 = createYGNode(config, YogaFlexDirection.Column, 500, 600, false);
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = createYGNode(config, YogaFlexDirection.Column, 500, 800, false);
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child1_child0 = createYGNode(config, YogaFlexDirection.Column, 500, 300, false);
|
||||
root_child1.Insert(0, root_child1_child0);
|
||||
|
||||
YogaNode root_child1_child1 = createYGNode(config, YogaFlexDirection.Column, 500, 400, false);
|
||||
root_child1_child1.SetBaselineFunction((_, width, height) => {
|
||||
return height / 2;
|
||||
});
|
||||
root_child1_child1.IsReferenceBaseline = true;
|
||||
root_child1.Insert(1, root_child1_child1);
|
||||
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
|
||||
Assert.AreEqual(500f, root_child1.LayoutX);
|
||||
Assert.AreEqual(100f, root_child1.LayoutY);
|
||||
|
||||
Assert.AreEqual(0f, root_child1_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child1_child0.LayoutY);
|
||||
|
||||
Assert.AreEqual(0f, root_child1_child1.LayoutX);
|
||||
Assert.AreEqual(300f, root_child1_child1.LayoutY);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_align_baseline_parent_using_child_in_row_as_reference()
|
||||
{
|
||||
YogaConfig config = new YogaConfig();
|
||||
|
||||
YogaNode root = createYGNode(config, YogaFlexDirection.Row, 1000, 1000, true);
|
||||
|
||||
YogaNode root_child0 = createYGNode(config, YogaFlexDirection.Column, 500, 600, false);
|
||||
root.Insert(0, root_child0);
|
||||
|
||||
YogaNode root_child1 = createYGNode(config, YogaFlexDirection.Row, 500, 800, true);
|
||||
root.Insert(1, root_child1);
|
||||
|
||||
YogaNode root_child1_child0 = createYGNode(config, YogaFlexDirection.Row, 500, 500, false);
|
||||
root_child1.Insert(0, root_child1_child0);
|
||||
|
||||
YogaNode root_child1_child1 = createYGNode(config, YogaFlexDirection.Row, 500, 400, false);
|
||||
root_child1_child1.SetBaselineFunction((_, width, height) => {
|
||||
return height / 2;
|
||||
});
|
||||
root_child1_child1.IsReferenceBaseline = true;
|
||||
root_child1.Insert(1, root_child1_child1);
|
||||
|
||||
root.StyleDirection = YogaDirection.LTR;
|
||||
|
||||
root.CalculateLayout();
|
||||
|
||||
Assert.AreEqual(0f, root_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child0.LayoutY);
|
||||
|
||||
Assert.AreEqual(500f, root_child1.LayoutX);
|
||||
Assert.AreEqual(100f, root_child1.LayoutY);
|
||||
|
||||
Assert.AreEqual(0f, root_child1_child0.LayoutX);
|
||||
Assert.AreEqual(0f, root_child1_child0.LayoutY);
|
||||
|
||||
Assert.AreEqual(500f, root_child1_child1.LayoutX);
|
||||
Assert.AreEqual(300f, root_child1_child1.LayoutY);
|
||||
}
|
||||
|
||||
private YogaNode createYGNode(YogaConfig config, YogaFlexDirection flexDirection, int width, int height, bool alignBaseline) {
|
||||
YogaNode node = new YogaNode(config);
|
||||
node.FlexDirection = flexDirection;
|
||||
node.Width = width;
|
||||
node.Height = height;
|
||||
if (alignBaseline) {
|
||||
node.AlignItems = YogaAlign.Baseline;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user