Add test support for intrinsic sized nodes

Summary: This diff adds support for intrinsic sizing in generated tests. This is done by importing a testing font called "Ahem" which, as used, has an exact width and height of 10px for each character. Support has been added for C++, Java, and Javascript generated tests.

Differential Revision: D58307002
This commit is contained in:
Maddie Lord
2024-06-24 22:34:58 -07:00
committed by Facebook GitHub Bot
parent cedac5edf4
commit c24adff88e
77 changed files with 2284 additions and 119 deletions

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<9c27293180ef7ffd5b683046588f9dd7>>
* @generated SignedSource<<133e2d77cd6267d4bfb0fe992d437fd1>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAbsolutePositionTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a74026bab03aecc7776f5dbb34f233a1>>
* @generated SignedSource<<c86a05976d95ea610aa45e71ab6d82c6>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignContentTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<74d05d33189c5b8e301d7bb50e219a07>>
* @generated SignedSource<<f032c889819df729aaf72a9618b542c0>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<353dcfc198766f52fa7a84b1f47fab23>>
* @generated SignedSource<<e6a84121fe6588e91897e67a86016382>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignSelfTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f3c61c97032ebe1518e40730efe8a392>>
* @generated SignedSource<<8f3c045b0df6a23f1d2fa54a255cb6f3>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAndroidNewsFeed.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f2cef5ee14439a52c41c7aa6a29d176a>>
* @generated SignedSource<<acd05459fdaeace7681295ee1812c3cb>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAspectRatioTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<27363e405aac02603d06d5f06fa107ba>>
* @generated SignedSource<<675d8bdccff33c46128330c9bd6c9b87>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGBorderTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<557b8f6c7b3abd35d4f10cc83c650caf>>
* @generated SignedSource<<51018ace00a5b85422b92cec7acc9f4d>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGDimensionTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f84185922c678ddf892c13ccbd3b79f2>>
* @generated SignedSource<<cf656f8ee5e2d761eaa30bbd4982532c>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGDisplayTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<5aa80de7d8424e35b5b1b205ff44f4cc>>
* @generated SignedSource<<5cc8e03bdba27ff2003afbde3b5ed0b7>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGFlexDirectionTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fabda3f9a1c5266bab041546630406ab>>
* @generated SignedSource<<0b2282a5a0b35e95e7e27417e6b25ff6>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGFlexTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a465733b5a79e26c64aeeb431b822fee>>
* @generated SignedSource<<11f5ca827ba97151a67ab3f05cf48f53>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGFlexWrapTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<d7267afda72d6ed64f8a74487c3952d0>>
* @generated SignedSource<<ee51d064149d73715837a457daf382e3>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGGapTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -0,0 +1,545 @@
/**
* 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<<63249d156daefb8d7d536b57c7d8cb70>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGIntrinsicSizeTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,
Direction,
Display,
Edge,
Errata,
ExperimentalFeature,
FlexDirection,
Gutter,
Justify,
MeasureMode,
Overflow,
PositionType,
Unit,
Wrap,
} from 'yoga-layout';
test('contains_inner_text_long_word', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("LoremipsumdolorsitametconsecteturadipiscingelitSedeleifasdfettortoracauctorFuscerhoncusipsumtemporerosaliquamconsequatPraesentsoda"));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(1300);
expect(root_child0.getComputedHeight()).toBe(10);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(700);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(1300);
expect(root_child0.getComputedHeight()).toBe(10);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_no_width_no_height', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(70);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(70);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_no_width_no_height_long_word_in_paragraph', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus loremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumloremipsumlorem Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(70);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(70);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_fixed_width', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setWidth(100);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(100);
expect(root_child0.getComputedHeight()).toBe(1290);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(1900);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(100);
expect(root_child0.getComputedHeight()).toBe(1290);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_no_width_fixed_height', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setHeight(20);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(20);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(20);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_fixed_width_fixed_height', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setWidth(50);
root_child0.setHeight(20);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(20);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(1950);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(20);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_max_width_max_height', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setMaxWidth(50);
root_child0.setMaxHeight(20);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(20);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(1950);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(50);
expect(root_child0.getComputedHeight()).toBe(20);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_max_width', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setMaxWidth(100);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(100);
expect(root_child0.getComputedHeight()).toBe(1290);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(1900);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(100);
expect(root_child0.getComputedHeight()).toBe(1290);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_fixed_width_shorter_text', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setWidth(100);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum"));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(100);
expect(root_child0.getComputedHeight()).toBe(20);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(1900);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(100);
expect(root_child0.getComputedHeight()).toBe(20);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_fixed_height_shorter_text', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setHeight(100);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum"));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(110);
expect(root_child0.getComputedHeight()).toBe(100);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(1890);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(110);
expect(root_child0.getComputedHeight()).toBe(100);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});
test('contains_inner_text_max_height', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setAlignItems(Align.FlexStart);
root.setPositionType(PositionType.Absolute);
root.setWidth(2000);
root.setHeight(2000);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root_child0.setMaxHeight(20);
root.insertChild(root_child0, 0);
root_child0.setMeasureFunc(instrinsicSizeMeasureFunc.bind("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifasd et tortor ac auctor. Integer at volutpat libero, sed elementum dui interdum id. Aliquam consectetur massa vel neque aliquet, quis consequat risus fringilla. Fusce rhoncus ipsum tempor eros aliquam, vel tempus metus ullamcorper. Nam at nulla sed tellus vestibulum fringilla vel sit amet ligula. Proin velit lectus, euismod sit amet quam vel ultricies dolor, vitae finibus lorem ipsum. Pellentesque molestie at mi sit amet dictum. Donec vehicula lacinia felis sit amet consectetur. Praesent sodales enim sapien, sed varius ipsum pellentesque vel. Aenean eu mi eu justo tincidunt finibus vel sit amet ipsum. Sed bibasdum purus vel ipsum sagittis, quis fermentum dolor lobortis. Etiam vulputate eleifasd lectus vel varius. Phasellus imperdiet lectus sit amet ipsum egestas, ut bibasdum ipsum malesuada. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis eros sit amet elit porttitor, vel venenatis turpis venenatis. Nulla tempus tortor at eros efficitur, sit amet dapibus ipsum malesuada. Ut at mauris sed nunc malesuada convallis. Duis id sem vel magna varius eleifasd vel at est. Donec eget orci a ipsum tempor lobortis. Sed at consectetur ipsum."));
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(20);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(2000);
expect(root.getComputedHeight()).toBe(2000);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(2000);
expect(root_child0.getComputedHeight()).toBe(20);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<acccc0a7a2ba5a312dae041805512503>>
* @generated SignedSource<<c5ddc0e827650e4ccb406f574e24db8b>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGJustifyContentTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<71cadc40efa1ab29b1f7613c79c27d9e>>
* @generated SignedSource<<910ea7258ef002557289f475dc74f3dc>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGMarginTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e29102ce03bdffe4b3394db2becc4973>>
* @generated SignedSource<<f85cf0ba85e1e2af955d3515a2901a46>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGMinMaxDimensionTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<688d750852e836fc6403042d89d5ab51>>
* @generated SignedSource<<2e4b35c2408710c0aabaa82e43e157cb>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGPaddingTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<830099a8328eae16955128bfb531ccb2>>
* @generated SignedSource<<6af8e434b1131c83b7feb6ff04a2dffd>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGPercentageTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2814c9e579a5d6a4367bf35d92bd1cc9>>
* @generated SignedSource<<203f3aa8922cb3fa03e7946f91a6ed2d>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGRoundingTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<01de372ba12d9bd521148401d69bca0f>>
* @generated SignedSource<<e2a7f645b8572a1420ca470bdda2d60c>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGSizeOverflowTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -4,10 +4,11 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2f8b96b22567d9b50c880b375cf7de15>>
* @generated SignedSource<<fd288594fce8fa8e2399df5f5d303440>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGStaticPositionTest.html
*/
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
import Yoga from 'yoga-layout';
import {
Align,

View File

@@ -0,0 +1,81 @@
/**
* 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.
*/
import {MeasureMode} from 'yoga-layout';
export function instrinsicSizeMeasureFunc(
this: string,
width: number,
widthMode: MeasureMode,
height: number,
heightMode: MeasureMode,
): {width: number; height: number} {
const textLength = this.length;
const words = this.split(' ');
const widthPerChar = 10;
const heightPerChar = 10;
let measuredWidth: number;
let measuredHeight: number;
switch (widthMode) {
case MeasureMode.Exactly:
measuredWidth = width;
break;
case MeasureMode.AtMost:
measuredWidth = Math.min(width, textLength * widthPerChar);
break;
default:
measuredWidth = textLength * widthPerChar;
}
switch (heightMode) {
case MeasureMode.Exactly:
measuredHeight = height;
break;
case MeasureMode.AtMost:
measuredHeight = Math.min(height, calculateHeight());
break;
default:
measuredHeight = calculateHeight();
}
function longestWordWidth() {
return Math.max(...words.map(word => word.length)) * widthPerChar;
}
function calculateHeight() {
if (textLength * widthPerChar <= measuredWidth) {
return heightPerChar;
}
const maxLineWidth = Math.max(longestWordWidth(), measuredWidth);
//if fixed width < width of widest word, take width of widest word
let lines = 1;
let currentLineLength = 0;
for (const word of words) {
const wordWidth = word.length * widthPerChar;
if (wordWidth > maxLineWidth) {
if (currentLineLength > 0) {
lines++;
}
lines++;
currentLineLength = 0;
} else if (currentLineLength + wordWidth <= maxLineWidth) {
currentLineLength += widthPerChar + wordWidth;
} else {
lines++;
currentLineLength = widthPerChar + wordWidth;
}
}
return (currentLineLength === 0 ? lines - 1 : lines) * heightPerChar;
}
return {width: measuredWidth, height: measuredHeight};
}