summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/hobgoblin/compiler/ExampleSet.java
blob: 59517ad14a4fad9d17fa0f34cc4ace8b67f78f03 (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
package org.zwobble.hobgoblin.compiler;

import org.zwobble.hobgoblin.compiler.filesystem.HobgoblinCompilerFiles;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.stream.Stream;

public class ExampleSet {
    public static Stream<ExampleSet> exampleSets() {
        return exampleSetDirectories()
            .map(exampleDirectory -> new ExampleSet(exampleDirectory.toPath()));
    }

    /// The directory of each example set.
    private static Stream<File> exampleSetDirectories() {
        var examplesRoot = HobgoblinCompilerFiles.getRoot().resolve("examples");

        return Arrays.stream(examplesRoot.toFile()
            .listFiles(file -> file.isDirectory() && file.toPath().resolve("hobgoblin.json5").toFile().exists()));
    }

    private final Path path;

    private ExampleSet(Path path) {
        this.path = path;
    }

    public String name() {
        return this.path.getFileName().toString();
    }

    public Path path() {
        return this.path;
    }
}