Changeset 21235
- Timestamp:
- 08/18/09 22:01:43 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/lime/branches/2.0-experimental/lib/LimePrinter.php
r20982 r21235 21 21 HAPPY = 6, 22 22 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; 27 28 28 29 protected … … 42 43 $colorizer->setStyle(self::HAPPY, array('fg' => 'white', 'bg' => 'green', 'bold' => true)); 43 44 $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')); 45 47 $colorizer->setStyle(self::INFO, array('fg' => 'cyan', 'bold' => true)); 46 48 $colorizer->setStyle(self::TRACE, array('fg' => 'green', 'bold' => true)); … … 89 91 if (is_null($style)) 90 92 { 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); 92 94 } 93 95 else … … 112 114 return $this->colorizer->colorize($text, self::STRING); 113 115 } 116 else if (in_array(strtolower($text), array('true', 'false'))) 117 { 118 return $this->colorizer->colorize($text, self::BOOLEAN); 119 } 114 120 else 115 121 { 116 return $this->colorizer->colorize($text, self:: METHOD);122 return $this->colorizer->colorize($text, self::NUMBER); 117 123 } 118 124 } tools/lime/branches/2.0-experimental/test/unit/LimePrinterTest.php
r21230 r21235 14 14 LimeAnnotationSupport::enable(); 15 15 16 $t = new LimeTest( 6);16 $t = new LimeTest(10); 17 17 18 18 // @Before … … 96 96 97 97 98 // @Test: strings in unformatted text are automatically formatted98 // @Test: Strings in unformatted text are automatically formatted 99 99 100 100 // fixtures … … 107 107 // assertions 108 108 $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'); 109 159 110 160 /*