|
6 | 6 |
|
7 | 7 | use PHPUnit\Framework\TestCase; |
8 | 8 | use Psl\Ansi\Color; |
| 9 | +use Psl\Ansi\Style; |
9 | 10 | use Psl\Terminal\Buffer; |
10 | 11 | use Psl\Terminal\Rect; |
11 | 12 | use Psl\Terminal\Widget\BarChart; |
@@ -127,4 +128,70 @@ public function testLabelStyleApplied(): void |
127 | 128 | static::assertNotNull($cell); |
128 | 129 | static::assertNotNull($cell->foreground); |
129 | 130 | } |
| 131 | + |
| 132 | + public function testBarStyleWithModifier(): void |
| 133 | + { |
| 134 | + $buffer = new Buffer(3, 3); |
| 135 | + $area = new Rect(0, 0, 3, 3); |
| 136 | + |
| 137 | + BarChart::new() |
| 138 | + ->data([['A', 1.0]]) |
| 139 | + ->barWidth(3) |
| 140 | + ->barGap(0) |
| 141 | + ->barStyle(foreground: Color\red(), style: Style\bold()) |
| 142 | + ->render($area, $buffer); |
| 143 | + |
| 144 | + $cell = $buffer->get(0, 0); |
| 145 | + static::assertNotNull($cell); |
| 146 | + static::assertSame("\u{2588}", $cell->grapheme); |
| 147 | + static::assertNotNull($cell->foreground); |
| 148 | + } |
| 149 | + |
| 150 | + public function testLabelStyleWithModifier(): void |
| 151 | + { |
| 152 | + $buffer = new Buffer(3, 3); |
| 153 | + $area = new Rect(0, 0, 3, 3); |
| 154 | + |
| 155 | + BarChart::new() |
| 156 | + ->data([['X', 0.5]]) |
| 157 | + ->barWidth(3) |
| 158 | + ->barGap(0) |
| 159 | + ->labelStyle(foreground: Color\white(), style: Style\bold()) |
| 160 | + ->render($area, $buffer); |
| 161 | + |
| 162 | + $cell = $buffer->get(1, 2); |
| 163 | + static::assertNotNull($cell); |
| 164 | + static::assertNotNull($cell->foreground); |
| 165 | + } |
| 166 | + |
| 167 | + public function testBarsClipWhenExceedingAreaWidth(): void |
| 168 | + { |
| 169 | + $buffer = new Buffer(5, 3); |
| 170 | + $area = new Rect(0, 0, 5, 3); |
| 171 | + |
| 172 | + BarChart::new() |
| 173 | + ->data([['A', 1.0], ['B', 1.0], ['C', 1.0]]) |
| 174 | + ->barWidth(3) |
| 175 | + ->barGap(1) |
| 176 | + ->render($area, $buffer); |
| 177 | + |
| 178 | + static::assertSame("\u{2588}", $buffer->get(0, 0)?->grapheme); |
| 179 | + static::assertSame("\u{2588}", $buffer->get(4, 0)?->grapheme); |
| 180 | + } |
| 181 | + |
| 182 | + public function testBarColumnClipsToAreaRight(): void |
| 183 | + { |
| 184 | + $buffer = new Buffer(4, 3); |
| 185 | + $area = new Rect(0, 0, 4, 3); |
| 186 | + |
| 187 | + BarChart::new() |
| 188 | + ->data([['A', 1.0]]) |
| 189 | + ->barWidth(6) |
| 190 | + ->barGap(0) |
| 191 | + ->render($area, $buffer); |
| 192 | + |
| 193 | + static::assertSame("\u{2588}", $buffer->get(0, 0)?->grapheme); |
| 194 | + static::assertSame("\u{2588}", $buffer->get(3, 0)?->grapheme); |
| 195 | + static::assertNull($buffer->get(4, 0)); |
| 196 | + } |
130 | 197 | } |
0 commit comments