@@ -1174,5 +1174,70 @@ public void testReplaceVariables3() {
11741174 assertEquals (expected , actual );
11751175 assertEquals ("${xxx}xyz" , StringOps .replaceVariables ("$${xxx}xyz" ,props ,PropertyMaps .GET_LAZY ));
11761176 }
1177-
1177+
1178+ public void testReplaceVariables4 () {
1179+ PropertyMaps props = new PropertyMaps ();
1180+ props .setProperty ("1" , new ConstantProperty ("var" , "foo" , "" ) {
1181+ public void resetAttributes () {
1182+ _attributes .clear ();
1183+ _attributes .put ("attr" , null );
1184+ }
1185+ public String getCurrent (PropertyMaps pm ) {
1186+ if (_attributes .get ("attr" )==null ) fail ("Attribute attr for property var should be set." );
1187+ return super .getCurrent (pm );
1188+ }
1189+ });
1190+ props .setProperty ("1" , new ConstantProperty ("xxx" , "bar" , "" ) {
1191+ public void resetAttributes () {
1192+ _attributes .clear ();
1193+ _attributes .put ("attr1" , null );
1194+ _attributes .put ("attr2" , null );
1195+ }
1196+ public String getCurrent (PropertyMaps pm ) {
1197+ if (_attributes .get ("attr1" )==null ) fail ("Attribute attr1 for property xxx should be set." );
1198+ if (_attributes .get ("attr2" )==null ) fail ("Attribute attr2 for property xxx should be set." );
1199+ return super .getCurrent (pm );
1200+ }
1201+ });
1202+
1203+ assertEquals ("abcxyz" , StringOps .replaceVariables ("abcxyz" ,props ,PropertyMaps .GET_LAZY ));
1204+ assertEquals ("abcfooxyz" , StringOps .replaceVariables ("abc${var;attr=\" xxx\" }xyz" ,props ,PropertyMaps .GET_LAZY ));
1205+ assertEquals ("abcbarxyz" , StringOps .replaceVariables ("abc${xxx;attr1=\" xxx\" ;attr2=\" yyy\" }xyz" ,props ,PropertyMaps .GET_LAZY ));
1206+ assertEquals ("abcbarxyz" , StringOps .replaceVariables ("abc${xxx;attr1=\" abc${var;attr=\" xxx\" }xyz\" ;attr2=\" yyy\" }xyz" ,props ,PropertyMaps .GET_LAZY ));
1207+ try {
1208+ assertEquals ("abcbarxyz" , StringOps .replaceVariables ("abc${xxx;attr2=\" yyy\" }xyz" ,props ,PropertyMaps .GET_LAZY ));
1209+ fail ("Forgot to set attr1, should fail." );
1210+ }
1211+ catch (junit .framework .AssertionFailedError afe ) { /* ignore, this is expected */ }
1212+ try {
1213+ StringOps .replaceVariables ("abc${xxx;attr1=\" abc${var}xyz\" ;attr2=\" yyy\" }xyz" ,props ,PropertyMaps .GET_LAZY );
1214+ fail ("Forgot to set attr1, should fail." );
1215+ }
1216+ catch (junit .framework .AssertionFailedError afe ) { /* ignore, this is expected */ }
1217+
1218+ assertEquals ("${notfound}" , StringOps .replaceVariables ("${notfound}" ,props ,PropertyMaps .GET_LAZY ));
1219+
1220+ props .setProperty ("1" , new ConstantProperty ("var" , "foo" , "" ));
1221+ props .setProperty ("1" , new ConstantProperty ("xxx" , "bar" , "" ));
1222+ assertTrue (StringOps .replaceVariables ("abc${xxx;;}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1223+ assertTrue (StringOps .replaceVariables ("abc${xxx;=}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1224+ assertTrue (StringOps .replaceVariables ("abc${xxx;\" \" }xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1225+ // TODO: should a semicolon at the end be disallowed?
1226+ // assertTrue(StringOps.replaceVariables("abc${xxx;}xyz",props,PropertyMaps.GET_LAZY).contains("<-- Error: "));
1227+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1228+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr\" \" }xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1229+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr${}}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1230+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr;}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1231+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr foo}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1232+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1233+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=${}}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1234+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=;}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1235+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=abc}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1236+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr==}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1237+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=\" abc\" ;}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1238+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=\" abc\" \" abc\" }xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1239+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=\" abc\" ${}}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1240+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=\" abc\" =}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1241+ assertTrue (StringOps .replaceVariables ("abc${xxx;attr=\" abc\" foo}xyz" ,props ,PropertyMaps .GET_LAZY ).contains ("<-- Error: " ));
1242+ }
11781243}
0 commit comments