Development

Changeset 21235

You must first sign up to be able to contribute.

Changeset 21235

Show
Ignore:
Timestamp:
08/18/09 22:01:43 (5 years ago)
Author:
bschussek
Message:

Implemented automatic colorization of numbers and booleans

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/lime/branches/2.0-experimental/lib/LimePrinter.php

    r20982 r21235  
    2121    HAPPY = 6, 
    2222    STRING = 7, 
    23     METHOD = 8, 
    24     INFO = 9, 
    25     TRACE = 10, 
    26     TODO = 11; 
     23    NUMBER = 8, 
     24    BOOLEAN = 9, 
     25    INFO = 10, 
     26    TRACE = 11, 
     27    TODO = 12; 
    2728 
    2829  protected 
     
    4243      $colorizer->setStyle(self::HAPPY, array('fg' => 'white', 'bg' => 'green', 'bold' => true)); 
    4344      $colorizer->setStyle(self::STRING, array('fg' => 'cyan')); 
    44       $colorizer->setStyle(self::METHOD, array('fg' => 'cyan')); 
     45      $colorizer->setStyle(self::NUMBER, array('fg' => 'cyan')); 
     46      $colorizer->setStyle(self::BOOLEAN, array('fg' => 'cyan')); 
    4547      $colorizer->setStyle(self::INFO, array('fg' => 'cyan', 'bold' => true)); 
    4648      $colorizer->setStyle(self::TRACE, array('fg' => 'green', 'bold' => true)); 
     
    8991      if (is_null($style)) 
    9092      { 
    91         return preg_replace_callback('/("[^"]*"'/*|(->|::)?\w+\([^\)]*\)*/.')/', array($this, 'autoColorize'), $text); 
     93        return preg_replace_callback('/("[^"]*"|(?<!\w)\d+(\.\d+)?(?!\w)|true|false'/*|(->|::)?\w+\([^\)]*\)*/.')/', array($this, 'autoColorize'), $text); 
    9294      } 
    9395      else 
     
    112114        return $this->colorizer->colorize($text, self::STRING); 
    113115      } 
     116      else if (in_array(strtolower($text), array('true', 'false'))) 
     117      { 
     118        return $this->colorizer->colorize($text, self::BOOLEAN); 
     119      } 
    114120      else 
    115121      { 
    116         return $this->colorizer->colorize($text, self::METHOD); 
     122        return $this->colorizer->colorize($text, self::NUMBER); 
    117123      } 
    118124    } 
  • tools/lime/branches/2.0-experimental/test/unit/LimePrinterTest.php

    r21230 r21235  
    1414LimeAnnotationSupport::enable(); 
    1515 
    16 $t = new LimeTest(6); 
     16$t = new LimeTest(10); 
    1717 
    1818// @Before 
     
    9696 
    9797 
    98 // @Test: strings in unformatted text are automatically formatted 
     98// @Test: Strings in unformatted text are automatically formatted 
    9999 
    100100  // fixtures 
     
    107107  // assertions 
    108108  $t->is($result, 'My text with a <BLUE>"Test string"</BLUE>', 'The result was colorized and printed'); 
     109 
     110 
     111// @Test: Integers in unformatted text are automatically formatted 
     112 
     113  // fixtures 
     114  $colorizer->colorize('123', LimePrinter::NUMBER)->returns('<BLUE>123</BLUE>'); 
     115  $colorizer->replay(); 
     116  // test 
     117  ob_start(); 
     118  $printer->printText('My text with an integer: 123'); 
     119  $result = ob_get_clean(); 
     120  // assertions 
     121  $t->is($result, 'My text with an integer: <BLUE>123</BLUE>', 'The result was colorized and printed'); 
     122 
     123 
     124// @Test: Integers within words are not formatted 
     125 
     126  // test 
     127  ob_start(); 
     128  $printer->printText('My text with an inte123ger'); 
     129  $result = ob_get_clean(); 
     130  // assertions 
     131  $t->is($result, 'My text with an inte123ger', 'The result was not colorized and printed'); 
     132 
     133 
     134// @Test: Floats in unformatted text are automatically formatted 
     135 
     136  // fixtures 
     137  $colorizer->colorize('1.23', LimePrinter::NUMBER)->returns('<BLUE>1.23</BLUE>'); 
     138  $colorizer->replay(); 
     139  // test 
     140  ob_start(); 
     141  $printer->printText('My text with a float: 1.23'); 
     142  $result = ob_get_clean(); 
     143  // assertions 
     144  $t->is($result, 'My text with a float: <BLUE>1.23</BLUE>', 'The result was colorized and printed'); 
     145 
     146 
     147// @Test: Booleans in unformatted text are automatically formatted 
     148 
     149  // fixtures 
     150  $colorizer->colorize('true', LimePrinter::BOOLEAN)->returns('<BLUE>true</BLUE>'); 
     151  $colorizer->colorize('false', LimePrinter::BOOLEAN)->returns('<BLUE>false</BLUE>'); 
     152  $colorizer->replay(); 
     153  // test 
     154  ob_start(); 
     155  $printer->printText('My text with true and false'); 
     156  $result = ob_get_clean(); 
     157  // assertions 
     158  $t->is($result, 'My text with <BLUE>true</BLUE> and <BLUE>false</BLUE>', 'The result was colorized and printed'); 
    109159 
    110160/*