test_stringutils.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /***************************************************************************
  2. test_stringutils.h
  3. --------------------
  4. begin : Jun 2020
  5. copyright : (C) 2020 by Ivan Ivanov
  6. email : ivan@opengis.ch
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #define CATCH_CONFIG_MAIN
  17. #include "utils/stringutils.h"
  18. #include "catch2.h"
  19. TEST_CASE( "StringUtils" )
  20. {
  21. SECTION( "InsertLinks" )
  22. {
  23. REQUIRE( StringUtils::insertLinks( QStringLiteral( "http://osm.org/" ) ) == QStringLiteral( "<a href=\"http://osm.org/\">http://osm.org/</a>" ) );
  24. REQUIRE( StringUtils::insertLinks( QStringLiteral( "https://osm.org/" ) ) == QStringLiteral( "<a href=\"https://osm.org/\">https://osm.org/</a>" ) );
  25. REQUIRE( StringUtils::insertLinks( QStringLiteral( "before https://osm.org/ after" ) ) == QStringLiteral( "before <a href=\"https://osm.org/\">https://osm.org/</a> after" ) );
  26. REQUIRE( StringUtils::insertLinks( QStringLiteral( "before https://osm.org/path?resource=;or=this%20one after" ) ) == QStringLiteral( "before <a href=\"https://osm.org/path?resource=;or=this%20one\">https://osm.org/path?resource=;or=this%20one</a> after" ) );
  27. }
  28. SECTION( "FuzzyMatch" )
  29. {
  30. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "Quercus rubra" ) == true );
  31. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "quercus r" ) == true );
  32. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "Pinus nigra" ) == false );
  33. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "Quercus" ) == true );
  34. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "qUERCUS" ) == true );
  35. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "ERcU" ) == true );
  36. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "rubra" ) == true );
  37. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "Rubra" ) == true );
  38. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "bra" ) == true );
  39. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra forma variegata", "rubra varieg" ) == true );
  40. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra (forma variegata)", "quercus forma" ) == true );
  41. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "q r" ) == true );
  42. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "q r" ) == true );
  43. REQUIRE( StringUtils::fuzzyMatch( "Quercus rubra", "q ubra" ) == false );
  44. }
  45. }