This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git


The following commit(s) were added to refs/heads/master by this push:
     new 026ea33a51 more tests for workflow shorthand processing
026ea33a51 is described below

commit 026ea33a51eea12b68ded46b72d5d9234ec52baf
Author: Alex Heneveld <[email protected]>
AuthorDate: Mon Apr 17 13:22:11 2023 +0100

    more tests for workflow shorthand processing
---
 .../core/workflow/ShorthandProcessorTest.java      | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git 
a/core/src/test/java/org/apache/brooklyn/core/workflow/ShorthandProcessorTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/workflow/ShorthandProcessorTest.java
index 3d1e91ee01..3b32b00fc8 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/workflow/ShorthandProcessorTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/workflow/ShorthandProcessorTest.java
@@ -124,6 +124,35 @@ public class ShorthandProcessorTest extends 
BrooklynMgmtUnitTestSupport {
                 e -> Asserts.expectedFailureContainsIgnoreCase(e, "input", 
"trailing characters", "b x"));
         assertShorthandFailsWith("[${type}] ${key%...} [\"=\" ${value}]", 
"integer a b x",
                 e -> Asserts.expectedFailureContainsIgnoreCase(e, "invalid", 
"key%"));
+
+        /*
+
+optional expressions are greedy -- ie if it can bind an optional expression it 
will do so
+
+but the ... multi-word match is *not* greedy -- if it can defer extra words 
until later it will do so
+
+for example given
+
+template [ ${word1...} ] [ ${word2...} ]
+to match against a b c
+
+there are 4 valid matches for word1 :  unset or a or a b or a b c  (with the 
complement being in word2).
+
+the logic will take the one which matches the optional word1 but as minimally 
as possible, is word1 is a and word2 is b c
+
+(but if our template were [ ${word1...} ] [ " and " ${word2...} ] then a b c 
would all have to go into word1 because it cannot match the " and " for word2)
+
+         */
+        assertShorthandOfGives("[ ${word1...} ] [ ${word2...} ]", "a b c", 
MutableMap.of("word1", "a", "word2" , "b c"));
+
+        assertShorthandOfGives("${word1} [ ${word2} ] \" and \" ${word3}", "a 
b and c", MutableMap.of("word1", "a", "word2", "b", "word3", "c"));
+        assertShorthandOfGives("${word1} [ ${word2} ] \" and \" ${word3}", "a 
and c", MutableMap.of("word1", "a", "word3", "c"));
+
+        assertShorthandOfGives("${word1} [ ${word2} ] \" and \" ${word3}", "a 
and b and c", MutableMap.of("word1", "a", "word3", "b and c"));
+        assertShorthandOfGives("${word1} [ ${word2...} ] \" and \" ${word3}", 
"a and b and c", MutableMap.of("word1", "a", "word2" , "and b", "word3", "c"));
+        assertShorthandOfGives("${word1} [ ${word2...} ] [ \" and \" ${word3} 
]", "a and b and c", MutableMap.of("word1", "a", "word2" , "and b", "word3", 
"c"));
+        assertShorthandOfGives("${word1} [ ${word2...} ] [ \" and \" ${word3} 
]", "a and b not c", MutableMap.of("word1", "a", "word2" , "and b not c"));
+        assertShorthandOfGives("${word1} [ ${word2...} ] [ \" and \" ${word3} 
]", "a not b not c", MutableMap.of("word1", "a", "word2" , "not b not c"));
     }
 
     @Test

Reply via email to