Skip to content

Commit 1f1cb45

Browse files
Anthony Liumeta-codesync[bot]
authored andcommitted
- Kotlin Adoption - textlayoutbuilder/util
Summary: Kotlin Adoption generated and fixed by editus and devmate - fbandroid/libraries/textlayoutbuilder/library/src/test/java/com/facebook/fbui/textlayoutbuilder/util Converted all Java files to Kotlin: - LayoutMeasureUtilTest.java → LayoutMeasureUtilTest.kt Changes: - Removed Hungarian notation (mLayout → layout) - Converted to idiomatic Kotlin with proper null safety using safe call operator (?.) instead of explicit null checks - Converted static nested classes to Kotlin companion object and object declaration - Converted test methods to Kotlin function syntax - Updated BUCK file (removed language = "JAVA" as Kotlin is now default) - Files properly marked as moved to preserve history Reviewed By: coreywu Differential Revision: D85901861 fbshipit-source-id: b05404f7239fa3029830f06843a46fdb657ad2b3
1 parent 1c4b6a6 commit 1f1cb45

File tree

2 files changed

+106
-107
lines changed

2 files changed

+106
-107
lines changed

library/src/test/java/com/facebook/fbui/textlayoutbuilder/util/LayoutMeasureUtilTest.java

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.facebook.fbui.textlayoutbuilder.util
18+
19+
import android.text.Layout
20+
import android.text.StaticLayout
21+
import android.text.TextPaint
22+
import org.assertj.core.api.Assertions.assertThat
23+
import org.junit.Test
24+
import org.junit.runner.RunWith
25+
import org.robolectric.RobolectricTestRunner
26+
import org.robolectric.annotation.Config
27+
28+
@Config(sdk = [23])
29+
@RunWith(RobolectricTestRunner::class)
30+
class LayoutMeasureUtilTest {
31+
32+
private lateinit var layout: Layout
33+
34+
@Test
35+
fun testOneLineWithAdd() {
36+
layout = StaticLayoutHelper.makeStaticLayout(ONE_LINE_TEXT, 1.0f, 5.0f)
37+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(15)
38+
}
39+
40+
@Test
41+
fun testTwoLinesWithAdd() {
42+
layout = StaticLayoutHelper.makeStaticLayout(TWO_LINE_TEXT, 1.0f, 5.0f)
43+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(30)
44+
}
45+
46+
@Test
47+
fun testOneLineWithMulti() {
48+
layout = StaticLayoutHelper.makeStaticLayout(ONE_LINE_TEXT, 1.5f, 0.0f)
49+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(15)
50+
}
51+
52+
@Test
53+
fun testTwoLinesWithMulti() {
54+
layout = StaticLayoutHelper.makeStaticLayout(TWO_LINE_TEXT, 1.5f, 0.0f)
55+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(30)
56+
}
57+
58+
@Test
59+
fun testOneLineWithAddAndMulti() {
60+
layout = StaticLayoutHelper.makeStaticLayout(ONE_LINE_TEXT, 1.5f, 2.0f)
61+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(17)
62+
}
63+
64+
@Test
65+
fun testTwoLinesWithAddAndMulti() {
66+
layout = StaticLayoutHelper.makeStaticLayout(TWO_LINE_TEXT, 1.5f, 2.0f)
67+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(34)
68+
}
69+
70+
@Test
71+
fun testEmptyTextWithAddAndMulti() {
72+
layout = StaticLayoutHelper.makeStaticLayout("", 1.5f, 2.0f)
73+
assertThat(LayoutMeasureUtil.getHeight(layout)).isEqualTo(10)
74+
}
75+
76+
private class DummyTextPaint : TextPaint() {
77+
override fun getFontMetricsInt(fmi: FontMetricsInt?): Int {
78+
fmi?.let { metrics ->
79+
metrics.ascent = 0
80+
metrics.top = 0
81+
metrics.descent = 10
82+
metrics.bottom = 10
83+
}
84+
return 0
85+
}
86+
}
87+
88+
private object StaticLayoutHelper {
89+
fun makeStaticLayout(text: CharSequence, spacingMult: Float, spacingAdd: Float): Layout {
90+
return StaticLayout(
91+
text,
92+
DummyTextPaint(),
93+
1000,
94+
Layout.Alignment.ALIGN_NORMAL,
95+
spacingMult,
96+
spacingAdd,
97+
true,
98+
)
99+
}
100+
}
101+
102+
companion object {
103+
private const val ONE_LINE_TEXT = "test"
104+
private const val TWO_LINE_TEXT = "test\ntest"
105+
}
106+
}

0 commit comments

Comments
 (0)