aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/backends/ExampleConfig.java
blob: ef46fb60fefa4e1f878d203560a6165fe6a55bc7 (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
package org.shedlang.compiler.backends;

import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.zwobble.json5.values.Json5String;

import java.nio.file.Path;
import java.util.Optional;
import java.util.OptionalLong;

public record ExampleConfig(
    Path projectPath,
    String bin,
    OptionalLong expectedExitCode,
    Optional<String> expectedOutput,
    Optional<String> expectedError
) {
    public static ExampleConfig fromJson5(
        Path root,
        Json5ObjectWithSource object
    ) {
        return new ExampleConfig(
            root.resolve(object.getString("project").value()),
            object.getString("bin").value(),
            object.getLongOrNone("expectedExitCode"),
            object.getStringOrNone("expectedOutput").map(Json5String::value),
            object.getStringOrNone("expectedError").map(Json5String::value)
        );
    }
}