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

leeonky / test-charm-java / 150

07 Mar 2025 12:58AM UTC coverage: 74.287% (-0.08%) from 74.367%
150

push

circleci

leeonky
Try to fix ci

7919 of 10660 relevant lines covered (74.29%)

0.74 hits per line

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

92.0
/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.InputException;
8
import com.github.leeonky.dal.runtime.RuntimeContextBuilder;
9
import com.github.leeonky.dal.runtime.schema.Expect;
10
import com.github.leeonky.dal.runtime.schema.Verification;
11
import com.github.leeonky.dal.type.InputCode;
12
import com.github.leeonky.dal.type.InputValue;
13
import com.github.leeonky.interpreter.InterpreterException;
14

15
import java.lang.reflect.Array;
16
import java.util.function.Supplier;
17

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

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

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

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

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

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

46
    public static Assertions expect(Object input) {
47
        return new Assertions((InputValue<Object>) () -> input);
1✔
48
    }
49

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

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

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

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

76
    private Assertions execute(Runnable runnable) {
77
        try {
78
            runnable.run();
1✔
79
        } catch (InputException e) {
1✔
80
            String detailMessage = "\n" + e.getMessage();
1✔
81
            detailMessage += "\n\nInput code got exception: " + getDal().getRuntimeContextBuilder().build(null).wrap(e.getInputClause()).dumpAll();
1✔
82
            throw new AssertionError(detailMessage);
1✔
83
        }
1✔
84
        return this;
1✔
85
    }
86

87
    public void exact(String verification) {
88
        should("=", verification);
1✔
89
    }
1✔
90

91
    public void match(String verification) {
92
        should(":", verification);
1✔
93
    }
1✔
94

95
    public Assertions is(Class<?> schema) {
96
        RuntimeContextBuilder.DALRuntimeContext context = getDal().getRuntimeContextBuilder().build(inputCode, schema);
1✔
97
        try {
98
            this.schema = schema;
1✔
99
            return execute(() -> Verification.expect(new Expect(create((Class) schema), null))
1✔
100
                    .verify(context, actual(context.getThis())));
1✔
101
        } catch (IllegalTypeException e) {
1✔
102
            String detailMessage = "\n" + e.getMessage();
1✔
103
            if (dumpInput)
1✔
104
                detailMessage += "\n\nThe root value was: " + getDal().getRuntimeContextBuilder().build(null).wrap(inputCode).dumpAll();
1✔
105
            throw new AssertionError(detailMessage);
1✔
106
        }
107
    }
108

109
    public Assertions is(String schema) {
110
        if (schema.startsWith("[") && schema.endsWith("]"))
1✔
111
            return is(Array.newInstance(getDal().getRuntimeContextBuilder().schemaType(
1✔
112
                    schema.replace('[', ' ').replace(']', ' ').trim()).getType(), 0).getClass());
1✔
113
        return is(getDal().getRuntimeContextBuilder().schemaType(schema).getType());
1✔
114
    }
115

116
    public Assertions isEqualTo(Object expect) {
117
        return execute(() -> expression(InputNode.INPUT_NODE, Factory.equal(), new ConstValueNode(expect))
×
118
                .evaluate(getDal().getRuntimeContextBuilder().build(inputCode)));
×
119
    }
120
}
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