Fix QRegExpValidator::validate docs about the pos parameter
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Sun, 14 Oct 2012 03:12:35 +0000 (04:12 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 22 Oct 2012 20:42:26 +0000 (22:42 +0200)
The code sets it to input.length() iff the regexp doesn't
match the string, while the docs say it's *always* set.

Therefore, make the docs match what the code does and
add a simple test to enforce it.

We're not changing the code to match the docs because

1) it's better to stay conservative (we don't want
to break existing behaviour);

2) this behaviour mimics what the int/double validators do
(they don't move pos at all).

Change-Id: I958074558de6b0fc5944101c6535fc7e00442ae9
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
src/gui/util/qvalidator.cpp
tests/auto/gui/util/qregexpvalidator/tst_qregexpvalidator.cpp

index 49945ae..6231a09 100644 (file)
@@ -862,7 +862,8 @@ QRegExpValidator::~QRegExpValidator()
     partially (i.e. could be a valid match if additional valid
     characters are added), and \l Invalid if \a input is not matched.
 
-    The \a pos parameter is set to the length of the \a input parameter.
+    Additionally, if \a input is not matched, the \a pos parameter is set to
+    the length of the \a input parameter.
 
     For example, if the regular expression is \b{\\w\\d\\d}
     (word-character, digit, digit) then "A57" is \l Acceptable,
index 7a2006b..d09a8e5 100644 (file)
@@ -116,8 +116,15 @@ void tst_QRegExpValidator::validate()
     QSignalSpy changedSpy(&rv, SIGNAL(changed()));
 
     rv.setRegExp( QRegExp( rx ) );
-    int dummy;
-    QCOMPARE( (int)rv.validate( value, dummy ), state );
+    int pos = -1;
+
+    QCOMPARE( (int)rv.validate( value, pos ), state );
+
+    if (state == QValidator::Invalid)
+        QCOMPARE(pos, value.length());
+    else
+        QCOMPARE(pos, -1); // untouched on Acceptable or Intermediate
+
     QCOMPARE(spy.count(), 1);
     QCOMPARE(changedSpy.count(), 1);
 }