-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add options to the StructurizrDslParser to be able to inject some par…
…sing behaviors. The only option is to force unique constant declaration, in order to prevent constants override inside a workspace.
- Loading branch information
1 parent
d32faa9
commit e9e15f8
Showing
4 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParserOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.structurizr.dsl; | ||
|
||
/** | ||
* @param uniqueConstantsDeclaration If set to true, then constants declared with the !constant keyword cannot be overridden. | ||
*/ | ||
public record StructurizrDslParserOptions( | ||
boolean uniqueConstantsDeclaration | ||
) { | ||
} |
26 changes: 26 additions & 0 deletions
26
structurizr-dsl/src/test/java/com/structurizr/dsl/UniqueConstantsConfigurationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.structurizr.dsl; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
public class UniqueConstantsConfigurationTests { | ||
|
||
@Test | ||
void shouldFailOnConstantDuplication() { | ||
String dsl = """ | ||
workspace { | ||
!constant NAME toto | ||
!constant NAME titi | ||
} | ||
"""; | ||
|
||
StructurizrDslParser parser = new StructurizrDslParser( | ||
new StructurizrDslParserOptions(true) | ||
); | ||
|
||
assertThatCode(() -> parser.parse(dsl)) | ||
.isInstanceOf(StructurizrDslParserException.class) | ||
.hasMessageStartingWith("A constant named NAME already exists"); | ||
} | ||
} |