|
| 1 | +<?php |
| 2 | + use PHPUnit\Framework\TestCase; |
| 3 | + |
| 4 | + final class TablePropsTest extends TestCase{ |
| 5 | + |
| 6 | + function table_props_test($tokens, $props_expect){ |
| 7 | + |
| 8 | + $obj = new iamcal\SQLParser(); |
| 9 | + $i = 0; |
| 10 | + $props = $obj->parse_table_props($tokens, $i); |
| 11 | + |
| 12 | + $this->assertEquals($props, $props_expect); |
| 13 | + } |
| 14 | + |
| 15 | + |
| 16 | + function testEqualsIsOptional(){ |
| 17 | + |
| 18 | + # the equals is optional |
| 19 | + |
| 20 | + $this->table_props_test(array('ENGINE', '=', 'INNODB'), array('ENGINE' => 'INNODB')); |
| 21 | + $this->table_props_test(array('ENGINE', 'INNODB'), array('ENGINE' => 'INNODB')); |
| 22 | + } |
| 23 | + |
| 24 | + function testDefaultCharset(){ |
| 25 | + |
| 26 | + # lots of ways to say this |
| 27 | + |
| 28 | + $this->table_props_test(array('DEFAULT CHARACTER SET', 'foo'), array('CHARSET' => 'foo')); |
| 29 | + $this->table_props_test(array('CHARACTER SET', 'foo'), array('CHARSET' => 'foo')); |
| 30 | + $this->table_props_test(array('DEFAULT CHARSET', 'foo'), array('CHARSET' => 'foo')); |
| 31 | + $this->table_props_test(array('CHARSET', 'foo'), array('CHARSET' => 'foo')); |
| 32 | + } |
| 33 | + |
| 34 | + function testDefaultCollation(){ |
| 35 | + |
| 36 | + $this->table_props_test(array('DEFAULT COLLATE', 'bar'), array('COLLATE' => 'bar')); |
| 37 | + $this->table_props_test(array('COLLATE', 'bar'), array('COLLATE' => 'bar')); |
| 38 | + } |
| 39 | + |
| 40 | + function testTwoWordProps(){ |
| 41 | + |
| 42 | + # more two-word props |
| 43 | + |
| 44 | + $this->table_props_test(array('DATA DIRECTORY', '=', 'baz'), array('DATA DIRECTORY' => 'baz')); |
| 45 | + $this->table_props_test(array('INDEX DIRECTORY', '=', 'baz'), array('INDEX DIRECTORY' => 'baz')); |
| 46 | + } |
| 47 | + |
| 48 | + |
| 49 | + # TODO: case conversion, multiple options, optional commas |
| 50 | + } |
0 commit comments