Reviewers: rchandia,
Description:
PatternValidator matches the whole input string.
[JSR 303 TCK Result] 111 of 257 (43.19%) Pass with 19 Failures and 9
Errors.
Please review this at http://gwt-code-reviews.appspot.com/1378801/
Affected files:
M
user/src/com/google/gwt/validation/client/constraints/PatternValidator.java
M
user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java
M
user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java
M
user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java
Index:
user/src/com/google/gwt/validation/client/constraints/PatternValidator.java
===================================================================
---
user/src/com/google/gwt/validation/client/constraints/PatternValidator.java
(revision 9825)
+++
user/src/com/google/gwt/validation/client/constraints/PatternValidator.java
(working copy)
@@ -1,12 +1,12 @@
/*
* Copyright 2010 Google Inc.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may
not
* use this file except in compliance with the License. You may obtain a
copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -15,6 +15,7 @@
*/
package com.google.gwt.validation.client.constraints;
+import com.google.gwt.regexp.shared.MatchResult;
import com.google.gwt.regexp.shared.RegExp;
import javax.validation.ConstraintValidator;
@@ -41,7 +42,15 @@
}
public boolean isValid(String value, ConstraintValidatorContext context)
{
- return value == null || pattern.test(value);
+ if (value == null) {
+ return true;
+ }
+ MatchResult match = pattern.exec(value);
+ if (match == null) {
+ return false;
+ }
+ // Must match the entire string
+ return match.getGroup(0).equals(value);
}
private String toString(Flag flag) {
Index:
user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java
===================================================================
---
user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java
(revision 9825)
+++
user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java
(working copy)
@@ -28,19 +28,27 @@
ConstraintValidatorTestCase<Pattern, String> {
@SuppressWarnings("unused")
- @Pattern(regexp = "good")
+ @Pattern(regexp = "g..d")
private Date defaultField;
+
+ public void testAssertIsValid_goad() {
+ assertConstraintValidator("goad", true);
+ }
+
+ public void testAssertIsValid_good() {
+ assertConstraintValidator("good", true);
+ }
+
+ public void testAssertIsValid_goood() {
+ assertConstraintValidator("goood", false);
+ }
+
+ public void testAssertIsValid_not_good() {
+ assertConstraintValidator("this is not good", false);
+ }
protected PatternValidator createValidator() {
return new PatternValidator();
- }
-
- public void testAssertIsValid_good() {
- assertConstraintValidator("this is good", true);
- }
-
- public void testAssertIsValid_bad() {
- assertConstraintValidator("this is bad", false);
}
@Override
Index:
user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java
===================================================================
---
user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java
(revision 9825)
+++
user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java
(working copy)
@@ -43,7 +43,6 @@
delegate.testComposedConstraintsAreRecursive();
}
- @Failing(issue = 5799)
public void testEachFailingConstraintCreatesConstraintViolation() {
delegate.testEachFailingConstraintCreatesConstraintViolation();
}
Index:
user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java
===================================================================
---
user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java
(revision 9825)
+++
user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java
(working copy)
@@ -51,7 +51,6 @@
delegate.testGroupSequence();
}
- @Failing(issue = 5801)
public void testGroupSequenceFollowedByGroup() {
delegate.testGroupSequenceFollowedByGroup();
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors