ExecutionPathTest.java revision bb4a033fcd5cd20e5be46ef8ead442dc7db2454d
1/*
2 * Copyright (C) 2016 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 */
16package android.databinding.tool.expr;
17
18
19import android.databinding.tool.MockLayoutBinder;
20import android.databinding.tool.reflection.java.JavaAnalyzer;
21import android.databinding.tool.solver.ExecutionPath;
22
23import org.junit.Before;
24import org.junit.Test;
25import org.junit.runner.RunWith;
26import org.junit.runners.Parameterized;
27
28import java.util.ArrayList;
29import java.util.Arrays;
30import java.util.List;
31
32@RunWith(Parameterized.class)
33public class ExecutionPathTest {
34
35    private final String mExpression;
36
37    public ExecutionPathTest(String expression) {
38        mExpression = expression;
39    }
40
41
42    @Parameterized.Parameters
43    public static List<String> expressions() {
44        return Arrays.asList("a.b(3/2)",
45                "a ? (a ? b : c) : d",
46                "a ? (b ? d : f) : g",
47                "5 + 4 / 3 + 2 + 7 * 8",
48                "a ? b : c");
49    }
50
51    @Before
52    public void setUp() throws Exception {
53        JavaAnalyzer.initForTests();
54    }
55
56    @Test
57    public void simpleExpr() {
58        MockLayoutBinder lb = new MockLayoutBinder();
59        ExprModel model = lb.getModel();
60        Expr parsed = lb.parse(mExpression, null);
61        List<ExecutionPath> paths = new ArrayList<ExecutionPath>();
62        ExecutionPath root = ExecutionPath.createRoot();
63        paths.add(root);
64        List<ExecutionPath> result = parsed.toExecutionPath(paths);
65        StringBuilder sb = new StringBuilder();
66        root.debug(sb, 0);
67        sb.toString();
68    }
69}
70