diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/config/BinConfigTests.java | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/config/BinConfigTests.java b/src/test/java/org/shedlang/compiler/config/BinConfigTests.java new file mode 100644 index 00000000..cbe8ee01 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/config/BinConfigTests.java @@ -0,0 +1,64 @@ +package org.shedlang.compiler.config; + +import org.junit.jupiter.api.Test; +import org.shedlang.compiler.config.errors.ConfigError; +import org.shedlang.compiler.config.toml.TomlTableWithSource; +import org.shedlang.compiler.sources.Sources; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.equalTo; + +public class BinConfigTests { + private static final Path PROJECT_PATH = Path.of("/projects/a"); + + @Test + public void whenBinConfigIsMissingNameThenErrorIsThrown() { + var source = Sources.string(""" + [[shed.bins]] + name = "one" + main-namespace = "One" + + [[shed.bins]] + main-namespace = "Two" + """); + + var error = assertThrows( + ConfigError.class, + () -> ProjectConfig.fromToml(PROJECT_PATH, TomlTableWithSource.parse(source)) + ); + + assertThat(error.getMessage(), equalTo("shed.bins[1] is missing name")); + assertThat(error.source().describe(), equalTo(""" + <string>:5:1 + [[shed.bins]] + ^""" + )); + } + + @Test + public void whenBinConfigIsMissingMainNamespaceThenErrorIsThrown() { + var source = Sources.string(""" + [[shed.bins]] + name = "one" + main-namespace = "One" + + [[shed.bins]] + name = "two" + """); + + var error = assertThrows( + ConfigError.class, + () -> ProjectConfig.fromToml(PROJECT_PATH, TomlTableWithSource.parse(source)) + ); + + assertThat(error.getMessage(), equalTo("shed.bins[1] is missing main-namespace")); + assertThat(error.source().describe(), equalTo(""" + <string>:5:1 + [[shed.bins]] + ^""" + )); + } +} |
