diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-12-23 11:36:15 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-12-23 11:36:15 +0000 |
| commit | ac56c2e61c8d4c9af26d49f419b2193a798ae68f (patch) | |
| tree | 96a94da71ee196e61f56af735dc7ab2813281f79 /src/test/java | |
| parent | f2ce971dc9389c2c964605a3f46a728108acf724 (diff) | |
Check fields for bin config are present
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]] + ^""" + )); + } +} |
