• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

leeonky / test-charm-java / 212

14 Apr 2025 05:15AM UTC coverage: 74.088% (-0.1%) from 74.209%
212

push

circleci

leeonky
Update version

7957 of 10740 relevant lines covered (74.09%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.62
/DAL-java/src/main/java/com/github/leeonky/dal/ast/node/ObjectScopeNode.java
1
package com.github.leeonky.dal.ast.node;
2

3
import com.github.leeonky.dal.runtime.AssertionFailure;
4
import com.github.leeonky.dal.runtime.CurryingMethod;
5
import com.github.leeonky.dal.runtime.Data;
6
import com.github.leeonky.dal.runtime.ExpectationFactory;
7
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
8
import com.github.leeonky.interpreter.SyntaxException;
9

10
import java.util.ArrayList;
11
import java.util.LinkedHashSet;
12
import java.util.List;
13
import java.util.Set;
14
import java.util.stream.Stream;
15

16
import static com.github.leeonky.dal.runtime.ExpressionException.exception;
17
import static com.github.leeonky.dal.runtime.ExpressionException.opt1;
18
import static java.lang.String.format;
19
import static java.util.stream.Collectors.joining;
20

21
public class ObjectScopeNode extends DALNode {
22
    private final List<DALNode> verificationExpressions = new ArrayList<>();
1✔
23
    private final boolean isObjectWildcard;
24

25
    public ObjectScopeNode(List<DALNode> expressions) {
1✔
26
        verificationExpressions.addAll(expressions);
1✔
27
        isObjectWildcard = false;
1✔
28
    }
1✔
29

30
    public ObjectScopeNode(DALNode ignore) {
1✔
31
        isObjectWildcard = true;
1✔
32
    }
1✔
33

34
    @Override
35
    public String inspect() {
36
        return format("{%s}", isObjectWildcard ? "..." : verificationExpressions.stream().map(DALNode::inspect)
1✔
37
                .collect(joining(", ")));
1✔
38
    }
39

40
    @Override
41
    protected ExpectationFactory toVerify(DALRuntimeContext context) {
42
        return (operator, actual) -> new ExpectationFactory.Expectation() {
1✔
43
            @Override
44
            public Data matches() {
45
                if (verificationExpressions.isEmpty() && !isObjectWildcard)
1✔
46
                    throw new SyntaxException("Should use `{...}` to verify any non null object", getPositionBegin());
1✔
47
                if (opt1(actual::isNull))
1✔
48
                    throw new AssertionFailure("The input value is null", getOperandPosition());
1✔
49
                return actual.execute(() -> {
1✔
50
                    Data result = context.data(null);
1✔
51
                    for (DALNode expression : verificationExpressions)
1✔
52
                        result = expression.evaluateData(context);
1✔
53
                    return result;
1✔
54
                });
55
            }
56

57
            @Override
58
            public Data equalTo() {
59
                if (opt1(actual::isNull))
1✔
60
                    throw new AssertionFailure("The input value is null", getOperandPosition());
1✔
61
                Data execute = actual.execute(() -> {
1✔
62
                    Data result = context.data(null);
1✔
63
                    for (DALNode expression : verificationExpressions)
1✔
64
                        result = expression.evaluateData(context);
1✔
65
                    return result;
1✔
66
                });
67
                Set<Object> dataFields = collectUnexpectedFields(actual, context);
1✔
68
                if (!dataFields.isEmpty())
1✔
69
                    throw exception(expression -> {
1✔
70
                        String element = expression.left().inspect();
1✔
71
                        return new AssertionFailure(format("Unexpected fields %s%s",
1✔
72
                                dataFields.stream().map(s -> s instanceof String ? format("`%s`", s) : s.toString())
1✔
73
                                        .collect(joining(", ")), element.isEmpty() ? "" : " in " + element), expression.operator().getPosition());
1✔
74
                    });
75
                return execute;
1✔
76
            }
77

78
            @Override
79
            public ExpectationFactory.Type type() {
80
                return ExpectationFactory.Type.OBJECT;
×
81
            }
82
        };
83
    }
84

85
    private Set<Object> collectUnexpectedFields(Data data, DALRuntimeContext context) {
86
        return new LinkedHashSet<Object>(data.fieldNames()) {{
1✔
87
            Stream.concat(collectFields(data), context.collectPartialProperties(data).stream())
1✔
88
                    .map(obj -> convertFiled(data, obj)).forEach(this::remove);
1✔
89
        }};
1✔
90
    }
91

92
    private Object convertFiled(Data data, Object obj) {
93
        return data.cast(CurryingMethod.class).map(curryingMethod -> curryingMethod.convertToArgType(obj)).orElse(obj);
1✔
94
    }
95

96
    @Override
97
    public Stream<Object> collectFields(Data data) {
98
        return verificationExpressions.stream().flatMap(expression -> expression.collectFields(data));
1✔
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc