-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix return type of substring method (#1504)
* Fix return type of substring method * Add test & refactor tests that load resources * Use try-with-resources
- Loading branch information
Showing
6 changed files
with
65 additions
and
23 deletions.
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
23 changes: 23 additions & 0 deletions
23
smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/RulesetTestUtil.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,23 @@ | ||
package software.amazon.smithy.rulesengine; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import software.amazon.smithy.model.node.Node; | ||
import software.amazon.smithy.model.node.ObjectNode; | ||
import software.amazon.smithy.rulesengine.language.EndpointRuleSet; | ||
|
||
public class RulesetTestUtil { | ||
public static EndpointRuleSet loadRuleSet(String resourceId) { | ||
try(InputStream is = RulesetTestUtil.class.getClassLoader().getResourceAsStream(resourceId)) { | ||
Node node = ObjectNode.parse(is); | ||
return EndpointRuleSet.fromNode(node); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public static EndpointRuleSet minimalRuleSet() { | ||
return loadRuleSet("software/amazon/smithy/rulesengine/testutil/valid-rules/minimal-ruleset.json"); | ||
} | ||
|
||
} |
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
35 changes: 35 additions & 0 deletions
35
...gine/src/test/java/software/amazon/smithy/rulesengine/language/TypeIntrospectionTest.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,35 @@ | ||
package software.amazon.smithy.rulesengine.language; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.InputStream; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import software.amazon.smithy.model.node.Node; | ||
import software.amazon.smithy.model.node.ObjectNode; | ||
import software.amazon.smithy.rulesengine.RulesetTestUtil; | ||
import software.amazon.smithy.rulesengine.language.EndpointRuleSet; | ||
import software.amazon.smithy.rulesengine.language.eval.Type; | ||
import software.amazon.smithy.rulesengine.language.syntax.rule.Condition; | ||
|
||
public class TypeIntrospectionTest { | ||
@Test | ||
void introspectCorrectTypesForFunctions() { | ||
EndpointRuleSet actual = RulesetTestUtil.loadRuleSet( | ||
"software/amazon/smithy/rulesengine/testutil/valid-rules/substring.json"); | ||
List<Condition> conditions = actual.getRules().get(0).getConditions(); | ||
// stringEquals({TestCaseId}, 1) | ||
assertEquals(conditions.get(0).getFn().type(), Type.bool()); | ||
|
||
// output = substring({Input}, ...); | ||
assertEquals(conditions.get(1).getFn().type(), Type.optional(Type.string())); | ||
} | ||
|
||
@Test | ||
void introspectCorrectTypesForGetAttr() { | ||
EndpointRuleSet actual = RulesetTestUtil.loadRuleSet( | ||
"software/amazon/smithy/rulesengine/testutil/valid-rules/get-attr-type-inference.json"); | ||
// bucketArn.resourceId[2] | ||
assertEquals(actual.getRules().get(0).getConditions().get(2).getFn().type(), Type.optional(Type.string())); | ||
} | ||
} |
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