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

leeonky / test-charm-java / 114

09 Feb 2025 05:45PM UTC coverage: 73.251% (-0.1%) from 73.358%
114

push

circleci

leeonky
Refactor

0 of 70 new or added lines in 3 files covered. (0.0%)

15 existing lines in 7 files now uncovered.

7665 of 10464 relevant lines covered (73.25%)

0.73 hits per line

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

95.83
/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;
1✔
27
    private Class<?> schema;
28

29
    public static void setDalFactory(Supplier<DAL> dalFactory) {
30
        Assertions.dalFactory = dalFactory;
1✔
31
    }
1✔
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
        dal = dalFactory.get();
1✔
40
    }
1✔
41

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

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

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

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

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

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

82
    public void exact(String verification) {
83
        should("=", verification);
1✔
84
    }
1✔
85

86
    public void match(String verification) {
87
        should(":", verification);
1✔
88
    }
1✔
89

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

104
    public Assertions is(String schema) {
105
        if (schema.startsWith("[") && schema.endsWith("]"))
1✔
106
            return is(Array.newInstance(dal.getRuntimeContextBuilder().schemaType(
1✔
107
                    schema.replace('[', ' ').replace(']', ' ').trim()).getType(), 0).getClass());
1✔
108
        return is(dal.getRuntimeContextBuilder().schemaType(schema).getType());
1✔
109
    }
110

111
    public Assertions isEqualTo(Object expect) {
UNCOV
112
        return execute(() -> expression(InputNode.INPUT_NODE, Factory.equal(), new ConstValueNode(expect))
×
UNCOV
113
                .evaluate(dal.getRuntimeContextBuilder().build(inputCode)));
×
114
    }
115
}
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