Revision: 9833
Author: ncha...@google.com
Date: Wed Mar  9 11:40:23 2011
Log: PatternValidator must match the whole input string.
[JSR 303 TCK Result] 111 of 257 (43.19%) Pass with 19 Failures and 9 Errors.

Review at http://gwt-code-reviews.appspot.com/1378801

Review by: rchan...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9833

Modified:
/trunk/user/src/com/google/gwt/validation/client/constraints/PatternValidator.java /trunk/user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java /trunk/user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java /trunk/user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java

=======================================
--- /trunk/user/src/com/google/gwt/validation/client/constraints/PatternValidator.java Mon Feb 28 07:12:19 2011 +++ /trunk/user/src/com/google/gwt/validation/client/constraints/PatternValidator.java Wed Mar 9 11:40:23 2011
@@ -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).length() == value.length();
   }

   private String toString(Flag flag) {
=======================================
--- /trunk/user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java Tue Jan 11 08:47:11 2011 +++ /trunk/user/test/com/google/gwt/validation/testing/constraints/PatternValidatorTest.java Wed Mar 9 11:40:23 2011
@@ -28,19 +28,27 @@
     ConstraintValidatorTestCase<Pattern, String> {

   @SuppressWarnings("unused")
-  @Pattern(regexp = "good")
+  @Pattern(regexp = "g..d")
   private Date defaultField;

-  protected PatternValidator createValidator() {
-    return new PatternValidator();
+  public void testAssertIsValid_goad() {
+    assertConstraintValidator("goad", true);
   }

   public void testAssertIsValid_good() {
-    assertConstraintValidator("this is good", true);
+    assertConstraintValidator("good", true);
   }

-  public void testAssertIsValid_bad() {
-    assertConstraintValidator("this is bad", false);
+  public void testAssertIsValid_goood() {
+    assertConstraintValidator("goood", false);
+  }
+
+  public void testAssertIsValid_not_good() {
+    assertConstraintValidator("this is not good", false);
+  }
+
+  protected PatternValidator createValidator() {
+    return new PatternValidator();
   }

   @Override
=======================================
--- /trunk/user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java Mon Feb 28 07:12:19 2011 +++ /trunk/user/test/org/hibernate/jsr303/tck/tests/constraints/constraintcomposition/ConstraintCompositionGwtTest.java Wed Mar 9 11:40:23 2011
@@ -43,7 +43,6 @@
     delegate.testComposedConstraintsAreRecursive();
   }

-  @Failing(issue = 5799)
   public void testEachFailingConstraintCreatesConstraintViolation() {
     delegate.testEachFailingConstraintCreatesConstraintViolation();
   }
=======================================
--- /trunk/user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java Wed Mar 2 06:32:23 2011 +++ /trunk/user/test/org/hibernate/jsr303/tck/tests/constraints/groups/GroupGwtTest.java Wed Mar 9 11:40:23 2011
@@ -51,7 +51,6 @@
     delegate.testGroupSequence();
   }

-  @Failing(issue = 5801)
   public void testGroupSequenceFollowedByGroup() {
     delegate.testGroupSequenceFollowedByGroup();
   }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to