summaryrefslogtreecommitdiffstats
path: root/kdecore/tests/kstringhandlertest.cpp
blob: 2efdc96fc2b095212a3d1613a792c704b2a857e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "kstringhandler.h"
#include <iostream>
using std::cout;
using std::endl;

bool check(const TQString &txt, const TQString &a, const TQString &b)
{
    if ( a != b ) {
        cout << "ERROR: Tested " << txt.latin1() << ", expected" << endl;
        cout << "'" << b.latin1() << "' (" << b.length() << " chars)" << endl;
        cout << "but got" << endl;
        cout << "'" << a.latin1() << "' (" << a.length() << " chars)" << endl;
        exit( 1 );
    }
  return true; 
}

int main(int argc, char *argv[]) 
{
  TQString test = "The quick brown fox jumped over the lazy bridge. ";

  check("word(test, 3)", 
	KStringHandler::word(test, 2), 
	"brown");
  check("word(test, \"3:5\")", 
	KStringHandler::word(test, "2:4"), 
	"brown fox jumped");
  check("insword(test, \"very\", 1)", 
	KStringHandler::insword(test, "very", 1),
       "The very quick brown fox jumped over the lazy bridge. ");
  check("setword(test, \"very\", 1)", 
	KStringHandler::setword(test, "very", 1),
       "The very brown fox jumped over the lazy bridge. ");
  check("remrange(test, \"4:6\")", 
	KStringHandler::remrange(test, "4:6"),
       "The quick brown fox lazy bridge. " );
  check("remrange(test, \"4:8\")", 
	KStringHandler::remrange(test, "4:8"),
       "The quick brown fox ");
  check("remword(test, 4)", 
	KStringHandler::remword(test, 4),
       "The quick brown fox over the lazy bridge. "); 
  check("remword(test, \"lazy\")", 
	KStringHandler::remword(test, "lazy"),
       "The quick brown fox jumped over the bridge. "); 
  check("capwords(test)", 
	KStringHandler::capwords(test),
       "The Quick Brown Fox Jumped Over The Lazy Bridge. "); 
  check("reverse(test)", 
	KStringHandler::reverse(test),
       " bridge. lazy the over jumped fox brown quick The"); 
  TQString result;
  result = KStringHandler::ljust(test, 70);
  if (result.length() != 70)
  {
     printf("Length = %d, expected 70.\n", result.length());
     exit(1);
  }
  check("ljust(test, 70)", 
	result,
        "The quick brown fox jumped over the lazy bridge.                      ");
  result = KStringHandler::rjust(test, 70);
  if (result.length() != 70)
  {
     printf("Length = %d, expected 70.\n", result.length());
     exit(1);
  }
  check("rjust(test, 70)", 
	result,
        "                      The quick brown fox jumped over the lazy bridge.");
  result = KStringHandler::center(test, 70);
  if (result.length() != 70)
  {
     printf("Length = %d, expected 70.\n", result.length());
     exit(1);
  }
  check("center(test, 70)", 
	result,
        "           The quick brown fox jumped over the lazy bridge.           ");

  test = "Click on http://foo@bar:www.kde.org/yoyo/dyne.html#a1 for info.";
  check( "tagURLs()", KStringHandler::tagURLs( test ),
	"Click on <a href=\"http://foo@bar:www.kde.org/yoyo/dyne.html#a1\">http://foo@bar:www.kde.org/yoyo/dyne.html#a1</a> for info." );

  test = "http://www.foo.org/story$806";
  check( "tagURLs()", KStringHandler::tagURLs( test ),
	 "<a href=\"http://www.foo.org/story$806\">http://www.foo.org/story$806</a>" );

#if 0
  // XFAIL - i.e. this needs to be fixed, but has never been
  test = "&lt;a href=www.foo.com&gt;";
  check( "tagURLs()", KStringHandler::tagURLs( test ),
	 "&lt;a href=<a href=\"www.foo.com\">www.foo.com</a>&gt;" );
#endif

  cout << "All OK!" << endl;
}