aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/shedlang/compiler/config/ProfileConfigTests.java
blob: b43d7b3473efa66005caeeb348dab4c7e41cc9c9 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.shedlang.compiler.config;

import org.junit.jupiter.api.Test;
import org.shedlang.compiler.config.json.Json5ObjectWithSource;
import org.shedlang.compiler.sources.SourceTexts;

import static org.zwobble.precisely.AssertThat.assertThat;
import static org.zwobble.precisely.Matchers.*;

public class ProfileConfigTests {
    @Test
    public void canParseProfileConfigWithName() {
        var source = """
            {
                name: "one",
            }
            """;

        var config = parseProfileConfig(source);

        assertThat(config, has("name", x -> x.name(), equalTo("one")));
    }

    @Test
    public void canParseProfileConfigWithoutGc() {
        var source = """
            {
                name: "one",
            }
            """;

        var config = parseProfileConfig(source);

        assertThat(config, has("name", x -> x.gc(), isOptionalEmpty()));
    }

    @Test
    public void canParseProfileConfigWithGc() {
        var source = """
            {
                name: "one",
                gc: {
                    "name": "bump",
                },
            }
            """;

        var config = parseProfileConfig(source);

        assertThat(config, has(
            "gc",
            x -> x.gc(),
            isOptionalOf(equalTo(GcConfig.BUMP))
        ));
    }

    private ProfileConfig parseProfileConfig(String text) {
        var sourceText = SourceTexts.string(text);
        return ProfileConfig.fromJson5(Json5ObjectWithSource.parse(sourceText));
    }
}