0948eed0fb483c6cb45faed2047410218e2bb3fc
[lhc/web/wiklou.git] / maintenance / parserTests.inc
1 <?php
2 # Copyright (C) 2004 Brion Vibber <brion@pobox.com>
3 # http://www.mediawiki.org/
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * @todo Make this more independent of the configuration (and if possible the database)
22 * @todo document
23 * @package MediaWiki
24 * @subpackage Maintenance
25 */
26
27 /** */
28 $options = array( 'quick', 'color', 'quiet', 'help' );
29 $optionsWithArgs = array( 'regex' );
30
31 require_once( 'commandLine.inc' );
32 require_once( "$IP/includes/ObjectCache.php" );
33 require_once( "$IP/includes/BagOStuff.php" );
34 require_once( "$IP/languages/LanguageUtf8.php" );
35 require_once( "$IP/includes/Hooks.php" );
36 require_once( "$IP/maintenance/parserTestsParserHook.php" );
37 require_once( "$IP/maintenance/parserTestsStaticParserHook.php" );
38 require_once( "$IP/maintenance/parserTestsParserTime.php" );
39
40 /**
41 * @package MediaWiki
42 * @subpackage Maintenance
43 */
44 class ParserTest {
45 /**
46 * boolean $color whereas output should be colorized
47 * @private
48 */
49 var $color;
50
51 /**
52 * boolean $lightcolor whereas output should use light colors
53 * @private
54 */
55 var $lightcolor;
56
57 /**
58 * Sets terminal colorization and diff/quick modes depending on OS and
59 * command-line options (--color and --quick).
60 *
61 * @public
62 */
63 function ParserTest() {
64 global $options;
65
66 # Only colorize output if stdout is a terminal.
67 $this->lightcolor = false;
68 $this->color = !wfIsWindows() && posix_isatty(1);
69
70 if( isset( $options['color'] ) ) {
71 switch( $options['color'] ) {
72 case 'no':
73 $this->color = false;
74 break;
75 case 'light':
76 $this->lightcolor = true;
77 # Fall through
78 case 'yes':
79 default:
80 $this->color = true;
81 break;
82 }
83 }
84
85 $this->showDiffs = !isset( $options['quick'] );
86
87 $this->quiet = isset( $options['quiet'] );
88
89 if (isset($options['regex'])) {
90 $this->regex = $options['regex'];
91 } else {
92 # Matches anything
93 $this->regex = '';
94 }
95 }
96
97 /**
98 * Remove last character if it is a newline
99 * @private
100 */
101 function chomp($s) {
102 if (substr($s, -1) === "\n") {
103 return substr($s, 0, -1);
104 }
105 else {
106 return $s;
107 }
108 }
109
110 /**
111 * Run a series of tests listed in the given text file.
112 * Each test consists of a brief description, wikitext input,
113 * and the expected HTML output.
114 *
115 * Prints status updates on stdout and counts up the total
116 * number and percentage of passed tests.
117 *
118 * @param string $filename
119 * @return bool True if passed all tests, false if any tests failed.
120 * @public
121 */
122 function runTestsFromFile( $filename ) {
123 $infile = fopen( $filename, 'rt' );
124 if( !$infile ) {
125 wfDie( "Couldn't open $filename\n" );
126 }
127
128 $data = array();
129 $section = null;
130 $success = 0;
131 $total = 0;
132 $n = 0;
133 while( false !== ($line = fgets( $infile ) ) ) {
134 $n++;
135 if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
136 $section = strtolower( $matches[1] );
137 if( $section == 'endarticle') {
138 if( !isset( $data['text'] ) ) {
139 wfDie( "'endarticle' without 'text' at line $n\n" );
140 }
141 if( !isset( $data['article'] ) ) {
142 wfDie( "'endarticle' without 'article' at line $n\n" );
143 }
144 $this->addArticle($this->chomp($data['article']), $this->chomp($data['text']), $n);
145 $data = array();
146 $section = null;
147 continue;
148 }
149 if( $section == 'end' ) {
150 if( !isset( $data['test'] ) ) {
151 wfDie( "'end' without 'test' at line $n\n" );
152 }
153 if( !isset( $data['input'] ) ) {
154 wfDie( "'end' without 'input' at line $n\n" );
155 }
156 if( !isset( $data['result'] ) ) {
157 wfDie( "'end' without 'result' at line $n\n" );
158 }
159 if( !isset( $data['options'] ) ) {
160 $data['options'] = '';
161 }
162 else {
163 $data['options'] = $this->chomp( $data['options'] );
164 }
165 if (preg_match('/\\bdisabled\\b/i', $data['options'])
166 || !preg_match("/{$this->regex}/i", $data['test'])) {
167 # disabled test
168 $data = array();
169 $section = null;
170 continue;
171 }
172 if( $this->runTest(
173 $this->chomp( $data['test'] ),
174 $this->chomp( $data['input'] ),
175 $this->chomp( $data['result'] ),
176 $this->chomp( $data['options'] ) ) ) {
177 $success++;
178 }
179 $total++;
180 $data = array();
181 $section = null;
182 continue;
183 }
184 if ( isset ($data[$section] ) ) {
185 wfDie( "duplicate section '$section' at line $n\n" );
186 }
187 $data[$section] = '';
188 continue;
189 }
190 if( $section ) {
191 $data[$section] .= $line;
192 }
193 }
194 if( $total > 0 ) {
195 $ratio = wfPercent( 100 * $success / $total );
196 print $this->termColor( 1 ) . "\nPassed $success of $total tests ($ratio) ";
197 if( $success == $total ) {
198 print $this->termColor( 32 ) . "PASSED!";
199 } else {
200 print $this->termColor( 31 ) . "FAILED!";
201 }
202 print $this->termReset() . "\n";
203 return ($success == $total);
204 } else {
205 wfDie( "No tests found.\n" );
206 }
207 }
208
209 /**
210 * Run a given wikitext input through a freshly-constructed wiki parser,
211 * and compare the output against the expected results.
212 * Prints status and explanatory messages to stdout.
213 *
214 * @param string $input Wikitext to try rendering
215 * @param string $result Result to output
216 * @return bool
217 */
218 function runTest( $desc, $input, $result, $opts ) {
219 if( !$this->quiet ) {
220 $this->showTesting( $desc );
221 }
222
223 $this->setupGlobals($opts);
224
225 $user =& new User();
226 $options = ParserOptions::newFromUser( $user );
227
228 if (preg_match('/\\bmath\\b/i', $opts)) {
229 # XXX this should probably be done by the ParserOptions
230 require_once('Math.php');
231
232 $options->setUseTex(true);
233 }
234
235 if (preg_match('/title=\[\[(.*)\]\]/', $opts, $m)) {
236 $titleText = $m[1];
237 }
238 else {
239 $titleText = 'Parser test';
240 }
241
242 $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts );
243
244 $parser =& new Parser();
245 wfRunHooks( 'ParserTestParser', array( &$parser ) );
246
247 $title =& Title::makeTitle( NS_MAIN, $titleText );
248
249 if (preg_match('/\\bpst\\b/i', $opts)) {
250 $out = $parser->preSaveTransform( $input, $title, $user, $options );
251 } elseif (preg_match('/\\bmsg\\b/i', $opts)) {
252 $out = $parser->transformMsg( $input, $options );
253 } else {
254 $output = $parser->parse( $input, $title, $options, true, true, 1337 );
255 $out = $output->getText();
256
257 if (preg_match('/\\bill\\b/i', $opts)) {
258 $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
259 } else if (preg_match('/\\bcat\\b/i', $opts)) {
260 global $wgOut;
261 $wgOut->addCategoryLinks($output->getCategories());
262 $out = $this->tidy ( implode( ' ', $wgOut->getCategoryLinks() ) );
263 }
264
265 $result = $this->tidy($result);
266 }
267
268 $this->teardownGlobals();
269
270 if( $result === $out && ( $noxml === true || $this->wellFormed( $out ) ) ) {
271 return $this->showSuccess( $desc );
272 } else {
273 return $this->showFailure( $desc, $result, $out );
274 }
275 }
276
277 /**
278 * Set up the global variables for a consistent environment for each test.
279 * Ideally this should replace the global configuration entirely.
280 *
281 * @private
282 */
283 function setupGlobals($opts = '') {
284 # Save the prefixed / quoted table names for later use when we make the temporaries.
285 $db =& wfGetDB( DB_READ );
286 $this->oldTableNames = array();
287 foreach( $this->listTables() as $table ) {
288 $this->oldTableNames[$table] = $db->tableName( $table );
289 }
290 if( !isset( $this->uploadDir ) ) {
291 $this->uploadDir = $this->setupUploadDir();
292 }
293
294 if( preg_match( '/language=([a-z]+(?:_[a-z]+)?)/', $opts, $m ) ) {
295 $lang = $m[1];
296 } else {
297 $lang = 'en';
298 }
299 $langClass = 'Language' . str_replace( '-', '_', ucfirst( $lang ) );
300 $langObj = setupLangObj( $langClass );
301
302 $settings = array(
303 'wgServer' => 'http://localhost',
304 'wgScript' => '/index.php',
305 'wgScriptPath' => '/',
306 'wgArticlePath' => '/wiki/$1',
307 'wgActionPaths' => array(),
308 'wgUploadPath' => 'http://example.com/images',
309 'wgUploadDirectory' => $this->uploadDir,
310 'wgStyleSheetPath' => '/skins',
311 'wgSitename' => 'MediaWiki',
312 'wgServerName' => 'Britney Spears',
313 'wgLanguageCode' => $lang,
314 'wgContLanguageCode' => $lang,
315 'wgDBprefix' => 'parsertest_',
316 'wgDefaultUserOptions' => array(),
317
318 'wgLang' => $langObj,
319 'wgContLang' => $langObj,
320 'wgNamespacesWithSubpages' => array( 0 => preg_match('/\\bsubpage\\b/i', $opts)),
321 'wgMaxTocLevel' => 999,
322 'wgCapitalLinks' => true,
323 'wgDefaultUserOptions' => array(),
324 'wgNoFollowLinks' => true,
325 'wgThumbnailScriptPath' => false,
326 'wgUseTeX' => false,
327 'wgLocaltimezone' => 'UTC',
328 );
329 $this->savedGlobals = array();
330 foreach( $settings as $var => $val ) {
331 $this->savedGlobals[$var] = $GLOBALS[$var];
332 $GLOBALS[$var] = $val;
333 }
334 $GLOBALS['wgLoadBalancer']->loadMasterPos();
335 $GLOBALS['wgMessageCache']->initialise( new BagOStuff(), false, 0, $GLOBALS['wgDBname'] );
336 $this->setupDatabase();
337
338 global $wgUser;
339 $wgUser = new User();
340 }
341
342 # List of temporary tables to create, without prefix
343 # Some of these probably aren't necessary
344 function listTables() {
345 $tables = array('user', 'page', 'revision', 'text',
346 'pagelinks', 'imagelinks', 'categorylinks',
347 'templatelinks', 'externallinks', 'langlinks',
348 'site_stats', 'hitcounter',
349 'ipblocks', 'image', 'oldimage',
350 'recentchanges',
351 'watchlist', 'math', 'searchindex',
352 'interwiki', 'querycache',
353 'objectcache', 'job'
354 );
355
356 // FIXME manually adding additional table for the tasks extension
357 // we probably need a better software wide system to register new
358 // tables.
359 global $wgExtensionFunctions;
360 if( in_array('wfTasksExtension' , $wgExtensionFunctions ) ) {
361 $tables[] = 'tasks';
362 }
363
364 return $tables;
365 }
366
367 /**
368 * Set up a temporary set of wiki tables to work with for the tests.
369 * Currently this will only be done once per run, and any changes to
370 * the db will be visible to later tests in the run.
371 *
372 * @private
373 */
374 function setupDatabase() {
375 static $setupDB = false;
376 global $wgDBprefix;
377
378 # Make sure we don't mess with the live DB
379 if (!$setupDB && $wgDBprefix === 'parsertest_') {
380 # oh teh horror
381 $GLOBALS['wgLoadBalancer'] = LoadBalancer::newFromParams( $GLOBALS['wgDBservers'] );
382 $db =& wfGetDB( DB_MASTER );
383
384 $tables = $this->listTables();
385
386 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
387 # Database that supports CREATE TABLE ... LIKE
388 global $wgDBtype;
389 if( $wgDBtype == 'PostgreSQL' ) {
390 $def = 'INCLUDING DEFAULTS';
391 } else {
392 $def = '';
393 }
394 foreach ($tables as $tbl) {
395 $newTableName = $db->tableName( $tbl );
396 $tableName = $this->oldTableNames[$tbl];
397 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName $def)");
398 }
399 } else {
400 # Hack for MySQL versions < 4.1, which don't support
401 # "CREATE TABLE ... LIKE". Note that
402 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
403 # would not create the indexes we need....
404 foreach ($tables as $tbl) {
405 $res = $db->query("SHOW CREATE TABLE {$this->oldTableNames[$tbl]}");
406 $row = $db->fetchRow($res);
407 $create = $row[1];
408 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
409 . $wgDBprefix . $tbl .'`', $create);
410 if ($create === $create_tmp) {
411 # Couldn't do replacement
412 wfDie("could not create temporary table $tbl");
413 }
414 $db->query($create_tmp);
415 }
416
417 }
418
419 # Hack: insert a few Wikipedia in-project interwiki prefixes,
420 # for testing inter-language links
421 $db->insert( 'interwiki', array(
422 array( 'iw_prefix' => 'Wikipedia',
423 'iw_url' => 'http://en.wikipedia.org/wiki/$1',
424 'iw_local' => 0 ),
425 array( 'iw_prefix' => 'MeatBall',
426 'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
427 'iw_local' => 0 ),
428 array( 'iw_prefix' => 'zh',
429 'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
430 'iw_local' => 1 ),
431 array( 'iw_prefix' => 'es',
432 'iw_url' => 'http://es.wikipedia.org/wiki/$1',
433 'iw_local' => 1 ),
434 array( 'iw_prefix' => 'fr',
435 'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
436 'iw_local' => 1 ),
437 array( 'iw_prefix' => 'ru',
438 'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
439 'iw_local' => 1 ),
440 ) );
441
442 # Hack: Insert an image to work with
443 $db->insert( 'image', array(
444 'img_name' => 'Foobar.jpg',
445 'img_size' => 12345,
446 'img_description' => 'Some lame file',
447 'img_user' => 1,
448 'img_user_text' => 'WikiSysop',
449 'img_timestamp' => $db->timestamp( '20010115123500' ),
450 'img_width' => 1941,
451 'img_height' => 220,
452 'img_bits' => 24,
453 'img_media_type' => MEDIATYPE_BITMAP,
454 'img_major_mime' => "image",
455 'img_minor_mime' => "jpeg",
456 ) );
457
458 # Update certain things in site_stats
459 $db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 1, 'ss_good_articles' => 1 ) );
460
461 $setupDB = true;
462 }
463 }
464
465 /**
466 * Create a dummy uploads directory which will contain a couple
467 * of files in order to pass existence tests.
468 * @return string The directory
469 * @private
470 */
471 function setupUploadDir() {
472 global $IP;
473
474 $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
475 mkdir( $dir );
476 mkdir( $dir . '/3' );
477 mkdir( $dir . '/3/3a' );
478
479 $img = "$IP/skins/monobook/headbg.jpg";
480 $h = fopen($img, 'r');
481 $c = fread($h, filesize($img));
482 fclose($h);
483
484 $f = fopen( $dir . '/3/3a/Foobar.jpg', 'wb' );
485 fwrite( $f, $c );
486 fclose( $f );
487 return $dir;
488 }
489
490 /**
491 * Restore default values and perform any necessary clean-up
492 * after each test runs.
493 *
494 * @private
495 */
496 function teardownGlobals() {
497 foreach( $this->savedGlobals as $var => $val ) {
498 $GLOBALS[$var] = $val;
499 }
500 if( isset( $this->uploadDir ) ) {
501 $this->teardownUploadDir( $this->uploadDir );
502 unset( $this->uploadDir );
503 }
504 }
505
506 /**
507 * Remove the dummy uploads directory
508 * @private
509 */
510 function teardownUploadDir( $dir ) {
511 unlink( "$dir/3/3a/Foobar.jpg" );
512 rmdir( "$dir/3/3a" );
513 rmdir( "$dir/3" );
514 @rmdir( "$dir/thumb/6/65" );
515 @rmdir( "$dir/thumb/6" );
516
517 @unlink( "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg" );
518 @rmdir( "$dir/thumb/3/3a/Foobar.jpg" );
519 @rmdir( "$dir/thumb/3/3a" );
520 @rmdir( "$dir/thumb/3/39" ); # wtf?
521 @rmdir( "$dir/thumb/3" );
522 @rmdir( "$dir/thumb" );
523 rmdir( "$dir" );
524 }
525
526 /**
527 * "Running test $desc..."
528 * @private
529 */
530 function showTesting( $desc ) {
531 print "Running test $desc... ";
532 }
533
534 /**
535 * Print a happy success message.
536 *
537 * @param string $desc The test name
538 * @return bool
539 * @private
540 */
541 function showSuccess( $desc ) {
542 if( !$this->quiet ) {
543 print $this->termColor( '1;32' ) . 'PASSED' . $this->termReset() . "\n";
544 }
545 return true;
546 }
547
548 /**
549 * Print a failure message and provide some explanatory output
550 * about what went wrong if so configured.
551 *
552 * @param string $desc The test name
553 * @param string $result Expected HTML output
554 * @param string $html Actual HTML output
555 * @return bool
556 * @private
557 */
558 function showFailure( $desc, $result, $html ) {
559 if( $this->quiet ) {
560 # In quiet mode we didn't show the 'Testing' message before the
561 # test, in case it succeeded. Show it now:
562 $this->showTesting( $desc );
563 }
564 print $this->termColor( '1;31' ) . 'FAILED!' . $this->termReset() . "\n";
565 if( $this->showDiffs ) {
566 print $this->quickDiff( $result, $html );
567 if( !$this->wellFormed( $html ) ) {
568 print "XML error: $this->mXmlError\n";
569 }
570 }
571 return false;
572 }
573
574 /**
575 * Run given strings through a diff and return the (colorized) output.
576 * Requires writable /tmp directory and a 'diff' command in the PATH.
577 *
578 * @param string $input
579 * @param string $output
580 * @param string $inFileTail Tailing for the input file name
581 * @param string $outFileTail Tailing for the output file name
582 * @return string
583 * @private
584 */
585 function quickDiff( $input, $output, $inFileTail='expected', $outFileTail='actual' ) {
586 $prefix = wfTempDir() . "/mwParser-" . mt_rand();
587
588 $infile = "$prefix-$inFileTail";
589 $this->dumpToFile( $input, $infile );
590
591 $outfile = "$prefix-$outFileTail";
592 $this->dumpToFile( $output, $outfile );
593
594 $diff = `diff -au $infile $outfile`;
595 unlink( $infile );
596 unlink( $outfile );
597
598 return $this->colorDiff( $diff );
599 }
600
601 /**
602 * Write the given string to a file, adding a final newline.
603 *
604 * @param string $data
605 * @param string $filename
606 * @private
607 */
608 function dumpToFile( $data, $filename ) {
609 $file = fopen( $filename, "wt" );
610 fwrite( $file, $data . "\n" );
611 fclose( $file );
612 }
613
614 /**
615 * Return ANSI terminal escape code for changing text attribs/color,
616 * or empty string if color output is disabled.
617 *
618 * @param string $color Semicolon-separated list of attribute/color codes
619 * @return string
620 * @private
621 */
622 function termColor( $color ) {
623 if($this->lightcolor) {
624 return $this->color ? "\x1b[1;{$color}m" : '';
625 } else {
626 return $this->color ? "\x1b[{$color}m" : '';
627 }
628 }
629
630 /**
631 * Return ANSI terminal escape code for restoring default text attributes,
632 * or empty string if color output is disabled.
633 *
634 * @return string
635 * @private
636 */
637 function termReset() {
638 return $this->color ? "\x1b[0m" : '';
639 }
640
641 /**
642 * Colorize unified diff output if set for ANSI color output.
643 * Subtractions are colored blue, additions red.
644 *
645 * @param string $text
646 * @return string
647 * @private
648 */
649 function colorDiff( $text ) {
650 return preg_replace(
651 array( '/^(-.*)$/m', '/^(\+.*)$/m' ),
652 array( $this->termColor( 34 ) . '$1' . $this->termReset(),
653 $this->termColor( 31 ) . '$1' . $this->termReset() ),
654 $text );
655 }
656
657 /**
658 * Insert a temporary test article
659 * @param string $name the title, including any prefix
660 * @param string $text the article text
661 * @param int $line the input line number, for reporting errors
662 * @static
663 * @private
664 */
665 function addArticle($name, $text, $line) {
666 $this->setupGlobals();
667 $title = Title::newFromText( $name );
668 if ( is_null($title) ) {
669 wfDie( "invalid title at line $line\n" );
670 }
671
672 $aid = $title->getArticleID( GAID_FOR_UPDATE );
673 if ($aid != 0) {
674 wfDie( "duplicate article at line $line\n" );
675 }
676
677 $art = new Article($title);
678 $art->insertNewArticle($text, '', false, false );
679 $this->teardownGlobals();
680 }
681
682 /*
683 * Run the "tidy" command on text if the $wgUseTidy
684 * global is true
685 *
686 * @param string $text the text to tidy
687 * @return string
688 * @static
689 * @private
690 */
691 function tidy( $text ) {
692 global $wgUseTidy;
693 if ($wgUseTidy) {
694 $text = Parser::tidy($text);
695 }
696 return $text;
697 }
698
699 function wellFormed( $text ) {
700 $html =
701 Sanitizer::hackDocType() .
702 '<html>' .
703 $text .
704 '</html>';
705
706 $parser = xml_parser_create( "UTF-8" );
707
708 # case folding violates XML standard, turn it off
709 xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false );
710
711 if( !xml_parse( $parser, $html, true ) ) {
712 $err = xml_error_string( xml_get_error_code( $parser ) );
713 $position = xml_get_current_byte_index( $parser );
714 $fragment = $this->extractFragment( $html, $position );
715 $this->mXmlError = "$err at byte $position:\n$fragment";
716 xml_parser_free( $parser );
717 return false;
718 }
719 xml_parser_free( $parser );
720 return true;
721 }
722
723 function extractFragment( $text, $position ) {
724 $start = max( 0, $position - 10 );
725 $before = $position - $start;
726 $fragment = '...' .
727 $this->termColor( 34 ) .
728 substr( $text, $start, $before ) .
729 $this->termColor( 0 ) .
730 $this->termColor( 31 ) .
731 $this->termColor( 1 ) .
732 substr( $text, $position, 1 ) .
733 $this->termColor( 0 ) .
734 $this->termColor( 34 ) .
735 substr( $text, $position + 1, 9 ) .
736 $this->termColor( 0 ) .
737 '...';
738 $display = str_replace( "\n", ' ', $fragment );
739 $caret = ' ' .
740 str_repeat( ' ', $before ) .
741 $this->termColor( 31 ) .
742 '^' .
743 $this->termColor( 0 );
744 return "$display\n$caret";
745 }
746
747 }
748
749 ?>