• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 156

20 Mar 2025 01:53PM UTC coverage: 74.243% (-0.2%) from 74.475%
156

push

circleci

leeonky
Refactor

14 of 15 new or added lines in 12 files covered. (93.33%)

126 existing lines in 29 files now uncovered.

7947 of 10704 relevant lines covered (74.24%)

0.74 hits per line

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

89.13
/DAL-java/src/main/java/com/github/leeonky/dal/Assertions.java
1
package com.github.leeonky.dal;
2

3
import com.github.leeonky.dal.ast.node.ConstValueNode;
4
import com.github.leeonky.dal.ast.node.InputNode;
5
import com.github.leeonky.dal.ast.opt.Factory;
6
import com.github.leeonky.dal.runtime.IllegalTypeException;
7
import com.github.leeonky.dal.runtime.RuntimeContextBuilder;
8
import com.github.leeonky.dal.runtime.schema.Expect;
9
import com.github.leeonky.dal.runtime.schema.Verification;
10
import com.github.leeonky.dal.type.InputCode;
11
import com.github.leeonky.interpreter.InterpreterException;
12

13
import java.lang.reflect.Array;
14
import java.util.function.Supplier;
15

16
import static com.github.leeonky.dal.ast.node.DALExpression.expression;
17
import static com.github.leeonky.dal.runtime.schema.Actual.actual;
18
import static com.github.leeonky.util.BeanClass.create;
19

20
public class Assertions {
21
    private final InputCode<Object> inputCode;
22
    public static boolean dumpInput = true;
1✔
23
    private DAL dal;
24
    private static Supplier<DAL> dalFactory = () -> DAL.getInstance("AssertD");
1✔
25
    private Class<?> schema;
26

27
    public static void setDalFactory(Supplier<DAL> dalFactory) {
UNCOV
28
        Assertions.dalFactory = dalFactory;
×
UNCOV
29
    }
×
30

31
    public static void dumpInput(boolean enable) {
32
        dumpInput = enable;
1✔
33
    }
1✔
34

35
    private Assertions(InputCode<Object> input) {
1✔
36
        inputCode = input;
1✔
37
    }
1✔
38

39
    public Assertions use(DAL dal) {
40
        this.dal = dal;
1✔
41
        return this;
1✔
42
    }
43

44
    public static Assertions expect(Object input) {
45
        return new Assertions(() -> input);
1✔
46
    }
47

48
    public static Assertions expectRun(InputCode<Object> supplier) {
49
        return new Assertions(supplier);
1✔
50
    }
51

52
    public Assertions should(String dalExpression) {
53
        return should("", dalExpression);
1✔
54
    }
55

56
    public Assertions should(String prefix, String verification) {
57
        String fullCode = prefix + verification;
1✔
58
        try {
59
            getDal().evaluate(inputCode, fullCode, schema);
1✔
60
            return this;
1✔
61
        } catch (InterpreterException e) {
1✔
62
            String detailMessage = "\n" + e.show(fullCode, prefix.length()) + "\n\n" + e.getMessage();
1✔
63
            if (dumpInput)
1✔
64
                detailMessage += "\n\nThe root value was: " + getDal().getRuntimeContextBuilder().build(null).wrap(inputCode).dump();
1✔
65
            throw new AssertionError(detailMessage);
1✔
66
        }
67
    }
68

69
    private DAL getDal() {
70
        if (dal == null)
1✔
71
            dal = dalFactory.get();
1✔
72
        return dal;
1✔
73
    }
74

75
    public void exact(String verification) {
76
        should("=", verification);
1✔
77
    }
1✔
78

79
    public void match(String verification) {
80
        should(":", verification);
1✔
81
    }
1✔
82

83
    @SuppressWarnings("unchecked")
84
    public Assertions is(Class<?> schema) {
85
        RuntimeContextBuilder.DALRuntimeContext context = getDal().getRuntimeContextBuilder().build(inputCode, schema);
1✔
86
        try {
87
            this.schema = schema;
1✔
88
            Verification.expect(new Expect(create((Class) schema), null))
1✔
89
                    .verify(context, actual(context.getThis()));
1✔
90
            return this;
1✔
91
        } catch (IllegalTypeException e) {
1✔
92
            String detailMessage = "\n" + e.getMessage();
1✔
93
            if (dumpInput)
1✔
94
                detailMessage += "\n\nThe root value was: " + getDal().getRuntimeContextBuilder().build(null).wrap(inputCode).dump();
1✔
95
            throw new AssertionError(detailMessage);
1✔
96
        }
97
    }
98

99
    public Assertions is(String schema) {
100
        if (schema.startsWith("[") && schema.endsWith("]"))
1✔
101
            return is(Array.newInstance(getDal().getRuntimeContextBuilder().schemaType(
1✔
102
                    schema.replace('[', ' ').replace(']', ' ').trim()).getType(), 0).getClass());
1✔
103
        return is(getDal().getRuntimeContextBuilder().schemaType(schema).getType());
1✔
104
    }
105

106
    public Assertions isEqualTo(Object expect) {
UNCOV
107
        expression(InputNode.INPUT_NODE, Factory.equal(), new ConstValueNode(expect))
×
UNCOV
108
                .evaluate(getDal().getRuntimeContextBuilder().build(inputCode));
×
UNCOV
109
        return this;
×
110
    }
111
}
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