Files
yoga/csharp/tests/Facebook.Yoga/YGAlignBaselineTest.cs
Nick Gerleman c96564d23d Fix License Headers and Whitespace
Summary: This change applies all Arcanist recommended lint changes, which amounts to changing copyright headers and some cases of whitespace changes.

Reviewed By: yungsters

Differential Revision: D40060899

fbshipit-source-id: b62f9472e6ef58a3fc3d22eed661578a2635cb1f
2022-10-04 13:59:32 -07:00

105 lines
3.7 KiB
C#

/*
* 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.
*/
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;
}
}
}