import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils;
+import org.opendaylight.yangtools.yang.model.util.RegexUtils;
public class Bug4079Test {
@Test
public void testValidPatternFix() {
- String fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsArrows})*+");
- assertEquals("(\\p{InArrows})*+", fixedUnicodeScriptPattern);
+ String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsArrows})*+");
+ assertEquals("^(\\p{InArrows})*+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsDingbats})++");
- assertEquals("(\\p{InDingbats})++", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsDingbats})++");
+ assertEquals("^(\\p{InDingbats})++$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsSpecials})?+");
- assertEquals("(\\p{InSpecials})?+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsSpecials})?+");
+ assertEquals("^(\\p{InSpecials})?+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsBatak}){4}+");
- assertEquals("(\\p{IsBatak}){4}+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBatak}){4}+");
+ assertEquals("^(\\p{IsBatak}){4}+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsLatin}){4,6}+");
- assertEquals("(\\p{IsLatin}){4,6}+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}){4,6}+");
+ assertEquals("^(\\p{IsLatin}){4,6}+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsTibetan}){4,}+");
- assertEquals("(\\p{IsTibetan}){4,}+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsTibetan}){4,}+");
+ assertEquals("^(\\p{IsTibetan}){4,}+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsAlphabetic}){4}?");
- assertEquals("(\\p{IsAlphabetic}){4}?", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsAlphabetic}){4}?");
+ assertEquals("^(\\p{IsAlphabetic}){4}?$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsLowercase}){4,6}?");
- assertEquals("(\\p{IsLowercase}){4,6}?", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLowercase}){4,6}?");
+ assertEquals("^(\\p{IsLowercase}){4,6}?$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsUppercase}){4,}?");
- assertEquals("(\\p{IsUppercase}){4,}?", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsUppercase}){4,}?");
+ assertEquals("^(\\p{IsUppercase}){4,}?$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement})*");
- assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement})*");
+ assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+");
- assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+");
+ assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsBasicLatin}|\\p{InLatin-1Supplement})?");
- assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{InLatin-1Supplement})?");
+ assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}){4}");
- assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4}", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}){4}");
+ assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4}$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsLatin}|\\p{IsArmenian}){2,4}");
- assertEquals("(\\p{IsLatin}|\\p{IsArmenian}){2,4}", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}|\\p{IsArmenian}){2,4}");
+ assertEquals("^(\\p{IsLatin}|\\p{IsArmenian}){2,4}$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsLatin}|\\p{IsBasicLatin}){2,}");
- assertEquals("(\\p{IsLatin}|\\p{InBasicLatin}){2,}", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}|\\p{IsBasicLatin}){2,}");
+ assertEquals("^(\\p{IsLatin}|\\p{InBasicLatin}){2,}$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsBasicLatin}|\\p{IsLatin})*?");
- assertEquals("(\\p{InBasicLatin}|\\p{IsLatin})*?", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{IsLatin})*?");
+ assertEquals("^(\\p{InBasicLatin}|\\p{IsLatin})*?$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern(
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
"(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsArrows})+?");
- assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{InArrows})+?", fixedUnicodeScriptPattern);
+ assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{InArrows})+?$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern(
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
"(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}|\\p{IsLatin})??");
- assertEquals("(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{IsLatin})??", fixedUnicodeScriptPattern);
+ assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}|\\p{IsLatin})??$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\\\\\p{IsBasicLatin})*+");
- assertEquals("(\\\\\\p{InBasicLatin})*+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\p{IsBasicLatin})*+");
+ assertEquals("^(\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\\\\\\\\\p{IsBasicLatin})*+");
- assertEquals("(\\\\\\\\\\p{InBasicLatin})*+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\p{IsBasicLatin})*+");
+ assertEquals("^(\\\\\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
- fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\\\\\\\\\\\\\p{IsBasicLatin})*+");
- assertEquals("(\\\\\\\\\\\\\\p{InBasicLatin})*+", fixedUnicodeScriptPattern);
+ fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\\\\\p{IsBasicLatin})*+");
+ assertEquals("^(\\\\\\\\\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
}
@Test(expected = PatternSyntaxException.class)
public void testInvalidPattern() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- String fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\\\p{IsBasicLatin})*+");
- assertEquals("(\\\\p{IsBasicLatin})*+", fixedUnicodeScriptPattern);
+ String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\p{IsBasicLatin})*+");
+ assertEquals("^(\\\\p{IsBasicLatin})*+$", fixedUnicodeScriptPattern);
// should throw exception
Pattern.compile(fixedUnicodeScriptPattern);
}
@Test(expected = PatternSyntaxException.class)
public void testInvalidPattern2() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- String fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\p{IsSpecials}|\\\\\\\\p{IsBasicLatin})*+");
- assertEquals("(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+", fixedUnicodeScriptPattern);
+ String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsSpecials}|\\\\\\\\p{IsBasicLatin})*+");
+ assertEquals("^(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+$", fixedUnicodeScriptPattern);
// should throw exception
Pattern.compile(fixedUnicodeScriptPattern);
}
@Test(expected = PatternSyntaxException.class)
public void testInvalidPattern3() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
- String fixedUnicodeScriptPattern = Utils.fixUnicodeScriptPattern("(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+");
- assertEquals("(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+", fixedUnicodeScriptPattern);
+ String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+");
+ assertEquals("^(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+$", fixedUnicodeScriptPattern);
// should throw exception
Pattern.compile(fixedUnicodeScriptPattern);
}