[go: nahoru, domu]

blob: 6303e1fda97a46f4cfab551b3f11f8bae2e903ec [file] [log] [blame]
Adam Powell211f48212019-11-04 13:33:35 -08001/*
2 * Copyright 2019 The Android Open Source Project
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
17package androidx.ui.core
18
19import org.junit.Assert.assertEquals
20import org.junit.Test
21
22class ModifierTest {
23 /**
Adam Powelldd723062019-12-04 13:52:59 -080024 * Verifies that the [Modifier.plus] operation results in [Modifier] instances that
Adam Powell211f48212019-11-04 13:33:35 -080025 * [Modifier.foldIn] and [Modifier.foldOut] in the expected order.
26 */
27 @Test
28 fun wrapElementChain() {
Adam Powelldd723062019-12-04 13:52:59 -080029 val chain = SampleModifier(1) + SampleModifier(2) + SampleModifier(3)
Adam Powell211f48212019-11-04 13:33:35 -080030 val forwards = chain.foldIn(emptyList<Int>()) { acc, e ->
31 acc + (e as SampleModifier).value
32 }
33 val backwards = chain.foldOut(emptyList<Int>()) { e, acc ->
34 acc + (e as SampleModifier).value
35 }
36 assertEquals("1-3 folded in (forwards)", listOf(1, 2, 3), forwards)
37 assertEquals("1-3 folded out (backwards)", listOf(3, 2, 1), backwards)
38 }
39}
40
41private class SampleModifier(val value: Int) : Modifier.Element