aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/couscous/tests/backends/python/PythonNodeMatchers.java
blob: a8a9188ffa9d2be56bcf19db5e54696c88106654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.zwobble.couscous.tests.backends.python;

import org.hamcrest.Matcher;
import org.zwobble.couscous.backends.python.ast.PythonExpressionNode;
import org.zwobble.couscous.backends.python.ast.PythonListNode;
import org.zwobble.couscous.backends.python.ast.PythonStringLiteralNode;

import java.util.List;

import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.zwobble.couscous.tests.util.ExtraMatchers.hasFeature;
import static org.zwobble.couscous.tests.util.ExtraMatchers.isInstance;

public class PythonNodeMatchers {
    public static Matcher<PythonExpressionNode> isPythonLiteral(String value) {
        return isInstance(PythonStringLiteralNode.class, hasFeature(
            "value",
            node -> node.getValue(),
            equalTo(value)));
    }

    public static Matcher<PythonExpressionNode> isPythonList(
        List<Matcher<? super PythonExpressionNode>> expectedElements)
    {
        return isInstance(PythonListNode.class, hasFeature(
            "elements",
            list -> list.getElements(),
            contains(expectedElements)));
    }
}