datatable.directory codebase
https://datatable.directory/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.9 KiB
72 lines
1.9 KiB
<?php
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use App\Tables\ColumnNumerator;
|
|
use Tests\TestCase;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
class ColumnNumeratorTest extends TestCase
|
|
{
|
|
public function testIncrementsWithDefaultInit()
|
|
{
|
|
$n = new ColumnNumerator();
|
|
|
|
self::assertEquals('a', $n->next());
|
|
self::assertEquals('b', $n->next());
|
|
self::assertEquals('c', $n->next());
|
|
}
|
|
|
|
public function testIncrementsWithCustomInit()
|
|
{
|
|
$n = new ColumnNumerator('r');
|
|
|
|
self::assertEquals('r', $n->next());
|
|
self::assertEquals('s', $n->next());
|
|
self::assertEquals('t', $n->next());
|
|
}
|
|
|
|
public function testIncrementsMultiChar()
|
|
{
|
|
$n = new ColumnNumerator('aaa');
|
|
|
|
self::assertEquals('aaa', $n->next());
|
|
self::assertEquals('aab', $n->next());
|
|
self::assertEquals('aac', $n->next());
|
|
}
|
|
|
|
public function testOverflowGrow()
|
|
{
|
|
$n = new ColumnNumerator('y');
|
|
|
|
self::assertEquals('y', $n->next());
|
|
self::assertEquals('z', $n->next());
|
|
self::assertEquals('aa', $n->next());
|
|
self::assertEquals('ab', $n->next());
|
|
}
|
|
|
|
public function testOverflowNoGrow()
|
|
{
|
|
$n = new ColumnNumerator('yy');
|
|
|
|
self::assertEquals('yy', $n->next());
|
|
self::assertEquals('yz', $n->next());
|
|
self::assertEquals('za', $n->next());
|
|
self::assertEquals('zb', $n->next());
|
|
}
|
|
|
|
public function testResume()
|
|
{
|
|
$n = new ColumnNumerator('yy');
|
|
self::assertEquals('yy', $n->next());
|
|
self::assertEquals('yz', $n->next());
|
|
|
|
$n2 = new ColumnNumerator($n->getState());
|
|
unset($n);
|
|
|
|
self::assertEquals('za', $n2->next(), 'recreated numerator continues');
|
|
self::assertEquals('zb', $n2->next());
|
|
|
|
self::assertEquals($n2->getState(), 'zc', 'State is next string');
|
|
}
|
|
}
|
|
|