[ktexteditor] /: KTE::Cursor & Range: add QTest::toString() specializations

Kevin Funk kfunk at kde.org
Sun Mar 30 20:40:11 UTC 2014


On Saturday 22 March 2014 11:09:47 Dominik Haumann wrote:
> On Saturday 22 March 2014 10:02:33 Dominik Haumann wrote:
> > Git commit db9cfee22b89ac0aadde50af1e92d84b7ed4ac52 by Dominik Haumann.
> > Committed on 22/03/2014 at 09:58.
> > Pushed by dhaumann into branch 'master'.
> > 
> > KTE::Cursor & Range: add QTest::toString() specializations
> > 
> > [...]
> > 
> > M  +12   -0    src/include/ktexteditor/cursor.h
> > M  +12   -1    src/include/ktexteditor/range.h
> > M  +21   -0    src/utils/range.cpp
> > 
> > http://commits.kde.org/ktexteditor/db9cfee22b89ac0aadde50af1e92d84b7ed4ac5
> > 2
> 
> @KDevelop: With this patch, you can remove all template QTest::toString()
> specializations for KTextEditor::Cursor and KTextEditor::Range in KDevelop.
> 
> Just grep for "toString(const KTextEditor::" and you should find all
> occurances.
> 
> Greetings,
> Dominik

Done.

Thanks!

> > diff --git a/src/include/ktexteditor/cursor.h
> > b/src/include/ktexteditor/cursor.h index eb8b826..f04c84e 100644
> > --- a/src/include/ktexteditor/cursor.h
> > +++ b/src/include/ktexteditor/cursor.h
> > @@ -340,5 +340,17 @@ inline uint qHash(const KTextEditor::Cursor& cursor)
> > 
> >      return cursor.line() * 53 + cursor.column() * 47;
> >  
> >  }
> > 
> > +namespace QTest
> > +{
> > +    // forward declaration of template in qtestcase.h
> > +    template<typename T> char* toString(const T&);
> > +
> > +    /**
> > +     * QTestLib integration to have nice output in e.g. QCOMPARE
> > failures.
> > +     */
> > +    template<>
> > +    KTEXTEDITOR_EXPORT char *toString(const KTextEditor::Cursor &cursor);
> > +}
> > +
> > 
> >  #endif
> > 
> > diff --git a/src/include/ktexteditor/range.h
> > b/src/include/ktexteditor/range.h index 17b4a9b..0062049 100644
> > --- a/src/include/ktexteditor/range.h
> > +++ b/src/include/ktexteditor/range.h
> > @@ -578,5 +578,16 @@ inline uint qHash(const KTextEditor::Range& range)
> > 
> >      return qHash(range.start()) + qHash(range.end()) * 41;
> >  
> >  }
> > 
> > -#endif
> > +namespace QTest
> > +{
> > +    // forward declaration of template in qtestcase.h
> > +    template<typename T> char* toString(const T&);
> > 
> > +    /**
> > +     * QTestLib integration to have nice output in e.g. QCOMPARE
> > failures.
> > +     */
> > +    template<>
> > +    KTEXTEDITOR_EXPORT char *toString(const KTextEditor::Range &range);
> > +}
> > +
> > +#endif
> > diff --git a/src/utils/range.cpp b/src/utils/range.cpp
> > index be17baa..6c658b3 100644
> > --- a/src/utils/range.cpp
> > +++ b/src/utils/range.cpp
> > @@ -253,3 +253,24 @@ Range KTextEditor::Range::encompass(const Range
> > &range) const }
> > 
> >  }
> > 
> > +namespace QTest {
> > +    // Cursor: template specialization for QTest::toString()
> > +    template<>
> > +    char *toString(const KTextEditor::Cursor &cursor)
> > +    {
> > +        QByteArray ba = "Cursor[" + QByteArray::number(cursor.line())
> > +                        + ", " + QByteArray::number(cursor.column()) +
> > "]"; +        return qstrdup(ba.data());
> > +    }
> > +
> > +    // Range: template specialization for QTest::toString()
> > +    template<>
> > +    char *toString(const KTextEditor::Range &range)
> > +    {
> > +        QByteArray ba = "Range[";
> > +        ba += QByteArray::number(range.start().line()) + ", " +
> > QByteArray::number(range.start().column()) + " - "; +        ba +=
> > QByteArray::number(range.end().line())   + ", " +
> > QByteArray::number(range.end().column()); +        ba += "]";
> > +        return qstrdup(ba.data());
> > +    }
> > +}

-- 
Kevin Funk


More information about the KDevelop-devel mailing list