codec.deserialize("abcd");
fail("Exception should have been thrown.");
} catch (final IllegalArgumentException ex) {
- LOG.debug("IllegalArgumentException was thrown as expected: {}", ex);
- assertTrue(ex.getMessage().contains("Supplied value does not match the regular expression ^[A-Z]+$. [abcd]"));
+ LOG.debug("IllegalArgumentException was thrown as expected", ex);
+ assertEquals("Supplied value does not match the regular expression ^(?:[A-Z]+)$. [abcd]", ex.getMessage());
}
}
}
* @return Java-compatible regex
*/
public static String getJavaRegexFromXSD(final String xsdRegex) {
- return "^" + fixUnicodeScriptPattern(escapeChars(xsdRegex)) + '$';
+ // Note: we are using a non-capturing group to deal with internal structure issues, like branches and similar.
+ return "^(?:" + fixUnicodeScriptPattern(escapeChars(xsdRegex)) + ")$";
}
/*
package org.opendaylight.yangtools.yang.model.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.junit.Test;
@Test
public void testValidPatternFix() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsArrows})*+");
- assertEquals("^(\\p{InArrows})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InArrows})*+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsDingbats})++");
- assertEquals("^(\\p{InDingbats})++$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InDingbats})++)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsSpecials})?+");
- assertEquals("^(\\p{InSpecials})?+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InSpecials})?+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBatak}){4}+");
- assertEquals("^(\\p{IsBatak}){4}+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsBatak}){4}+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}){4,6}+");
- assertEquals("^(\\p{IsLatin}){4,6}+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsLatin}){4,6}+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsTibetan}){4,}+");
- assertEquals("^(\\p{IsTibetan}){4,}+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsTibetan}){4,}+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsAlphabetic}){4}?");
- assertEquals("^(\\p{IsAlphabetic}){4}?$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsAlphabetic}){4}?)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLowercase}){4,6}?");
- assertEquals("^(\\p{IsLowercase}){4,6}?$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsLowercase}){4,6}?)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsUppercase}){4,}?");
- assertEquals("^(\\p{IsUppercase}){4,}?$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsUppercase}){4,}?)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{IsLatin-1Supplement})*");
- assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement})*)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+");
- assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement})+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{InLatin-1Supplement})?");
- assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement})?)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{InBasicLatin}|\\p{IsLatin-1Supplement}){4}");
- assertEquals("^(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4}$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InBasicLatin}|\\p{InLatin-1Supplement}){4})$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}|\\p{IsArmenian}){2,4}");
- assertEquals("^(\\p{IsLatin}|\\p{IsArmenian}){2,4}$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsLatin}|\\p{IsArmenian}){2,4})$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsLatin}|\\p{IsBasicLatin}){2,}");
- assertEquals("^(\\p{IsLatin}|\\p{InBasicLatin}){2,}$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{IsLatin}|\\p{InBasicLatin}){2,})$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\p{IsBasicLatin}|\\p{IsLatin})*?");
- assertEquals("^(\\p{InBasicLatin}|\\p{IsLatin})*?$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InBasicLatin}|\\p{IsLatin})*?)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
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 = 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 = RegexUtils.getJavaRegexFromXSD("(\\\\\\p{IsBasicLatin})*+");
- assertEquals("^(\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\\\\\p{InBasicLatin})*+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\p{IsBasicLatin})*+");
- assertEquals("^(\\\\\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\\\\\\\\\p{InBasicLatin})*+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\\\\\\\\\\\p{IsBasicLatin})*+");
- assertEquals("^(\\\\\\\\\\\\\\p{InBasicLatin})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\\\\\\\\\\\\\p{InBasicLatin})*+)$", fixedUnicodeScriptPattern);
assertNotNull(Pattern.compile(fixedUnicodeScriptPattern));
}
@Test(expected = PatternSyntaxException.class)
public void testInvalidPattern() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD("(\\\\p{IsBasicLatin})*+");
- assertEquals("^(\\\\p{IsBasicLatin})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\\\p{IsBasicLatin})*+)$", fixedUnicodeScriptPattern);
// should throw exception
Pattern.compile(fixedUnicodeScriptPattern);
}
public void testInvalidPattern2() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
"(\\p{IsSpecials}|\\\\\\\\p{IsBasicLatin})*+");
- assertEquals("^(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\p{InSpecials}|\\\\\\\\p{IsBasicLatin})*+)$", fixedUnicodeScriptPattern);
// should throw exception
Pattern.compile(fixedUnicodeScriptPattern);
}
public void testInvalidPattern3() {
String fixedUnicodeScriptPattern = RegexUtils.getJavaRegexFromXSD(
"(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+");
- assertEquals("^(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+$", fixedUnicodeScriptPattern);
+ assertEquals("^(?:(\\\\\\\\\\\\p{IsBasicLatin}|\\p{IsTags})*+)$", fixedUnicodeScriptPattern);
// should throw exception
Pattern.compile(fixedUnicodeScriptPattern);
}
+
+ @Test
+ public void testCorrectBranches() {
+ String str = RegexUtils.getJavaRegexFromXSD("a|bb");
+ assertEquals("^(?:a|bb)$", str);
+ Predicate<String> pred = Pattern.compile(str).asPredicate();
+
+ assertTrue(pred.test("a"));
+ assertTrue(pred.test("bb"));
+ assertFalse(pred.test("ab"));
+ assertFalse(pred.test("abb"));
+ assertFalse(pred.test("ac"));
+ }
}
@Test
public void testJavaRegexFromXSD() {
- testPattern("^[^:]+$", "^\\^[^:]+\\$$", ImmutableList.of("^a$", "^abc$"),
+ testPattern("^[^:]+$", "^(?:\\^[^:]+\\$)$", ImmutableList.of("^a$", "^abc$"),
ImmutableList.of("abc$", "^abc", "^a:bc$"));
- testPattern("^[$^]$", "^\\^[$^]\\$$", ImmutableList.of("^^$", "^$$"), ImmutableList.of("^^", "^$", "$^", "$$"));
- testPattern("[$-%]+", "^[$-%]+$", ImmutableList.of("$", "%", "%$"), ImmutableList.of("$-", "$-%", "-", "^"));
- testPattern("[$-&]+", "^[$-&]+$", ImmutableList.of("$", "%&", "%$", "$%&"), ImmutableList.of("#", "$-&", "'"));
-
- testPattern("[a-z&&[^m-p]]+", "^[a-z&&[^m-p]]+$", ImmutableList.of("a", "z", "az"),
+ testPattern("^[$^]$", "^(?:\\^[$^]\\$)$", ImmutableList.of("^^$", "^$$"),
+ ImmutableList.of("^^", "^$", "$^", "$$"));
+ testPattern("[$-%]+", "^(?:[$-%]+)$", ImmutableList.of("$", "%", "%$"),
+ ImmutableList.of("$-", "$-%", "-", "^"));
+ testPattern("[$-&]+", "^(?:[$-&]+)$", ImmutableList.of("$", "%&", "%$", "$%&"),
+ ImmutableList.of("#", "$-&", "'"));
+
+ testPattern("[a-z&&[^m-p]]+", "^(?:[a-z&&[^m-p]]+)$", ImmutableList.of("a", "z", "az"),
ImmutableList.of("m", "anz", "o"));
- testPattern("^[\\[-b&&[^^-a]]+$", "^\\^[\\[-b&&[^^-a]]+\\$$", ImmutableList.of("^[$", "^\\$", "^]$", "^b$"),
+ testPattern("^[\\[-b&&[^^-a]]+$", "^(?:\\^[\\[-b&&[^^-a]]+\\$)$", ImmutableList.of("^[$", "^\\$", "^]$", "^b$"),
ImmutableList.of("^a$", "^^$", "^_$"));
- testPattern("[^^-~&&[^$-^]]", "^[^^-~&&[^$-^]]$", ImmutableList.of("!", "\"", "#"),
+ testPattern("[^^-~&&[^$-^]]", "^(?:[^^-~&&[^$-^]])$", ImmutableList.of("!", "\"", "#"),
ImmutableList.of("a", "A", "z", "Z", "$", "%", "^", "}"));
- testPattern("\\\\\\[^[^^-~&&[^$-^]]", "^\\\\\\[\\^[^^-~&&[^$-^]]$",
+ testPattern("\\\\\\[^[^^-~&&[^$-^]]", "^(?:\\\\\\[\\^[^^-~&&[^$-^]])$",
ImmutableList.of("\\[^ ", "\\[^!", "\\[^\"", "\\[^#"),
ImmutableList.of("\\[^a", "\\[^A", "\\[^z", "\\[^Z", "\\[^$", "\\[^%", "\\[^^", "\\[^}"));
- testPattern("^\\[^\\\\[^^-b&&[^\\[-\\]]]\\]^", "^\\^\\[\\^\\\\[^^-b&&[^\\[-\\]]]\\]\\^$",
+ testPattern("^\\[^\\\\[^^-b&&[^\\[-\\]]]\\]^", "^(?:\\^\\[\\^\\\\[^^-b&&[^\\[-\\]]]\\]\\^)$",
ImmutableList.of("^[^\\c]^", "^[^\\Z]^"),
ImmutableList.of("^[^\\[]^", "^[^\\\\]^", "^[^\\]]^", "^[^\\^]^", "^[^\\_]^", "^[^\\b]^"));
- testPattern("[\\^]$", "^[\\^]\\$$", ImmutableList.of("^$"),
+ testPattern("[\\^]$", "^(?:[\\^]\\$)$", ImmutableList.of("^$"),
ImmutableList.of("^", "$", "$^", "\\", "\\^", "\\^\\", "\\^\\$"));
}
}
private static void testPattern(final String xsdRegex, final String unanchoredJavaRegex) {
- testPattern(xsdRegex, '^' + unanchoredJavaRegex + '$', ImmutableList.of(), ImmutableList.of());
+ testPattern(xsdRegex, "^(?:" + unanchoredJavaRegex + ")$", ImmutableList.of(), ImmutableList.of());
}
private static void testPattern(final String javaRegex, final List<String> positiveMatches,
assertEquals(expectedYangRegex, rawRegex);
final String javaRegexFromYang = pattern.getRegularExpression();
- final String expectedJavaRegex = "^\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86}$";
+ final String expectedJavaRegex = "^(?:\\$0\\$.*|\\$1\\$[a-zA-Z0-9./]{1,8}\\$[a-zA-Z0-9./]{22}|\\$5\\$"
+ + "(rounds=\\d+\\$)?[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{43}|\\$6\\$(rounds=\\d+\\$)?"
+ + "[a-zA-Z0-9./]{1,16}\\$[a-zA-Z0-9./]{86})$";
assertEquals(expectedJavaRegex, javaRegexFromYang);
final String value = "$6$AnrKGc0V$B/0/A.pWg4HrrA6YiEJOtFGibQ9Fmm5.4rI/00gEz3QeB7joSxBU3YtbHDm6NSkS1dKTQy3BWhwKKDS8nB5S//";
Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10));
final PatternConstraint patternConstraint = patternConstraints.get(0);
- Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
+ Assert.assertEquals(patternConstraint.getRegularExpression(), "^(?:[0-9a-fA-F])$");
}
@Test
Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10));
final PatternConstraint patternConstraint = patternConstraints.get(0);
- Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
+ Assert.assertEquals(patternConstraint.getRegularExpression(), "^(?:[0-9a-fA-F])$");
}
@Test
Assert.assertEquals(lengthConstraint.getMax(), Integer.valueOf(10));
final PatternConstraint patternConstraint = patternConstraints.get(0);
- Assert.assertEquals(patternConstraint.getRegularExpression(), "^[0-9a-fA-F]$");
+ Assert.assertEquals(patternConstraint.getRegularExpression(), "^(?:[0-9a-fA-F])$");
}
-}
\ No newline at end of file
+}
PatternConstraint patternConstraint2 = patternConstraints2.get(0);
PatternConstraint patternConstraint3 = patternConstraints3.get(0);
- assertEquals("^dp[0-9]+o[0-9]+(d[0-9]+)?$", patternConstraint0.getRegularExpression());
- assertEquals("^dp[0-9]+s[0-9]+(f[0-9]+)?(d[0-9]+)?$", patternConstraint1.getRegularExpression());
- assertEquals("^dp[0-9]+(P[0-9]+)?p[0-9]{1,3}s[0-9]{1,3}(f[0-9]+)?(d[0-9]+)?$",
+ assertEquals("^(?:dp[0-9]+o[0-9]+(d[0-9]+)?)$", patternConstraint0.getRegularExpression());
+ assertEquals("^(?:dp[0-9]+s[0-9]+(f[0-9]+)?(d[0-9]+)?)$", patternConstraint1.getRegularExpression());
+ assertEquals("^(?:dp[0-9]+(P[0-9]+)?p[0-9]{1,3}s[0-9]{1,3}(f[0-9]+)?(d[0-9]+)?)$",
patternConstraint2.getRegularExpression());
- assertEquals("^dp[0-9]+p[0-9]+p[0-9]+$", patternConstraint3.getRegularExpression());
+ assertEquals("^(?:dp[0-9]+p[0-9]+p[0-9]+)$", patternConstraint3.getRegularExpression());
}
}
final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
assertEquals(1, patternConstraints.size());
final PatternConstraint pattern = patternConstraints.iterator().next();
- assertEquals("^\".*\"$", pattern.getRegularExpression());
+ assertEquals("^(?:\".*\")$", pattern.getRegularExpression());
assertTrue(Pattern.compile(pattern.getRegularExpression()).matcher("\"enclosed string in quotes\"").matches());
}
final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints();
assertEquals(1, patternConstraints.size());
final PatternConstraint pattern = patternConstraints.iterator().next();
- assertEquals("^'.*'$", pattern.getRegularExpression());
+ assertEquals("^(?:'.*')$", pattern.getRegularExpression());
assertTrue(Pattern.compile(pattern.getRegularExpression()).matcher("'enclosed string in quotes'").matches());
}
-}
\ No newline at end of file
+}
final PatternConstraintEffectiveImpl patternConstraintSecond = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
.getType())).getPatternConstraints().get(0);
- assertEquals("^[0-9a-fA-F]*$", patternConstraint.getRegularExpression());
+ assertEquals("^(?:[0-9a-fA-F]*)$", patternConstraint.getRegularExpression());
assertNull(patternConstraint.getReference());
assertNull(patternConstraint.getDescription());
- assertEquals("Supplied value does not match the regular expression ^[0-9a-fA-F]*$.", patternConstraint.getErrorMessage());
+ assertEquals("Supplied value does not match the regular expression ^(?:[0-9a-fA-F]*)$.", patternConstraint.getErrorMessage());
assertEquals("invalid-regular-expression", patternConstraint.getErrorAppTag());
assertNotNull(patternConstraint.toString());
assertNotNull(patternConstraint.hashCode());
StringTypeDefinition ipv4 = (StringTypeDefinition) unionTypes.get(0);
assertNotNull(ipv4.getBaseType());
- String expectedPattern = "^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
- + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?$";
+ String expectedPattern = "^(?:(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}"
+ + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?)$";
assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getRegularExpression());
StringTypeDefinition ipv6 = (StringTypeDefinition) unionTypes.get(1);
assertNotNull(ipv6.getBaseType());
List<PatternConstraint> ipv6Patterns = ipv6.getPatternConstraints();
- expectedPattern = "^((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+ expectedPattern = "^(?:((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}"
+ "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
- + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?$";
+ + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?)$";
assertEquals(expectedPattern, ipv6Patterns.get(0).getRegularExpression());
- expectedPattern = "^(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
- + "(%.+)?$";
+ expectedPattern = "^(?:(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
+ + "(%.+)?)$";
assertEquals(expectedPattern, ipv6Patterns.get(1).getRegularExpression());
}
assertNotNull(type.getBaseType());
List<PatternConstraint> patterns = type.getPatternConstraints();
assertEquals(1, patterns.size());
- String expectedPattern = "^((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
- + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.$";
+ String expectedPattern = "^(?:((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*"
+ + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.)$";
assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
List<LengthConstraint> lengths = type.getLengthConstraints();
List<PatternConstraint> patterns = testedType.getPatternConstraints();
assertEquals(1, patterns.size());
PatternConstraint pattern = patterns.get(0);
- assertEquals("^\\d*(\\.\\d*){1,127}$", pattern.getRegularExpression());
+ assertEquals("^(?:\\d*(\\.\\d*){1,127})$", pattern.getRegularExpression());
QName testedTypeQName = testedType.getQName();
assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace());
assertEquals(1, patterns.size());
pattern = patterns.get(0);
- assertEquals("^(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*$",
+ assertEquals("^(?:(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*)$",
pattern.getRegularExpression());
QName testedTypeBaseQName = testedTypeBase.getQName();
List<PatternConstraint> patterns = type.getPatternConstraints();
assertEquals(1, patterns.size());
PatternConstraint pattern = patterns.iterator().next();
- assertEquals("^[e-z]*$", pattern.getRegularExpression());
+ assertEquals("^(?:[e-z]*)$", pattern.getRegularExpression());
assertEquals(1, type.getLengthConstraints().size());
final StringTypeDefinition baseType1 = type.getBaseType();
patterns = baseType1.getPatternConstraints();
assertEquals(1, patterns.size());
pattern = patterns.iterator().next();
- assertEquals("^[b-u]*$", pattern.getRegularExpression());
+ assertEquals("^(?:[b-u]*)$", pattern.getRegularExpression());
assertEquals(1, baseType1.getLengthConstraints().size());
final StringTypeDefinition baseType2 = baseType1.getBaseType();
patterns = baseType3.getPatternConstraints();
assertEquals(1, patterns.size());
pattern = patterns.iterator().next();
- assertEquals("^[a-k]*$", pattern.getRegularExpression());
+ assertEquals("^(?:[a-k]*)$", pattern.getRegularExpression());
final List<LengthConstraint> baseType3Lengths = baseType3.getLengthConstraints();
assertEquals(1, baseType3Lengths.size());
length = baseType3Lengths.get(0);
assertTrue(!patterns.isEmpty());
assertEquals(1, patterns.size());
final PatternConstraint pattern = patterns.iterator().next();
- assertEquals("^[e-z]*$", pattern.getRegularExpression());
+ assertEquals("^(?:[e-z]*)$", pattern.getRegularExpression());
assertEquals(1, type.getLengthConstraints().size());
final LeafSchemaNode multiplePatternDirectStringDefLeaf = (LeafSchemaNode) foo
boolean isEZPattern = false;
boolean isADPattern = false;
for (final PatternConstraint patternConstraint : patterns) {
- if (patternConstraint.getRegularExpression().equals("^[e-z]*$")) {
+ if (patternConstraint.getRegularExpression().equals("^(?:[e-z]*)$")) {
isEZPattern = true;
- } else if (patternConstraint.getRegularExpression().equals("^[a-d]*$")) {
+ } else if (patternConstraint.getRegularExpression().equals("^(?:[a-d]*)$")) {
isADPattern = true;
}
}
final List<PatternConstraint> patterns = baseType2.getPatternConstraints();
assertEquals(1, patterns.size());
final PatternConstraint pattern = patterns.iterator().next();
- assertEquals("^[a-k]*$", pattern.getRegularExpression());
+ assertEquals("^(?:[a-k]*)$", pattern.getRegularExpression());
final List<LengthConstraint> baseType3Lengths = baseType2.getLengthConstraints();
assertEquals(1, baseType3Lengths.size());
length = baseType3Lengths.get(0);