Skip to content

Commit

Permalink
updated test suite
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.php.net/repository/pear/packages/SQL_Parser/trunk@263296 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Sebastian Mendel committed Jul 23, 2008
1 parent 186243a commit fc2398d
Show file tree
Hide file tree
Showing 14 changed files with 928 additions and 717 deletions.
9 changes: 9 additions & 0 deletions tests/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct($test, $name)
public function runTest()
{
$parser = new SQL_Parser();
$parser->setDialect($this->_test['dialect']);
$result = $parser->parse($this->_test['sql']);

if (false === $result) {
Expand Down Expand Up @@ -108,7 +109,15 @@ function sideBySide($array1, $array2)

$message = '';
for ($i = 0; $i < $lines; $i++) {
if (empty($text1[$i])) {
$text1[$i] = '';
}
if (empty($text2[$i])) {
$text2[$i] = '';
}

$message .= str_pad($text1[$i], 40, ' ');

if ($text1[$i] === $text2[$i]) {
$message .= ' = ';
} else {
Expand Down
18 changes: 14 additions & 4 deletions tests/generate_testcases.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@
foreach ($queries as $query) {
if ($query) {
echo ':';
if (strpos(trim($query), '-- SQL_PARSER_FLAG_FAIL') === 0) {

if (strpos($query, '-- SQL_PARSER_FLAG_FAIL') !== false) {
$fail = true;
} else {
$fail = false;
}

if (strpos($query, '-- SQL_PARSER_FLAG_MYSQL') !== false) {
$_dialect = 'MySQL';
} else {
$_dialect = $dialect;
}
$parser->setDialect($_dialect);

$results = $parser->parse($query);
//if (PEAR::isError($results)) {
if (false === $results) {
Expand All @@ -89,9 +98,10 @@
}

$testcases[] = array(
'sql' => $query,
'expect' => $result,
'fail' => $fail,
'sql' => $query,
'expect' => $result,
'fail' => $fail,
'dialect' => $_dialect,
);
}
}
Expand Down
49 changes: 30 additions & 19 deletions tests/testcases/between.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,40 @@
'expect' =>
array (
'command' => 'select',
'column_tables' =>
'fields' =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
),
'column_names' =>
array (
0 => 'a',
1 => 'b',
2 => 'a',
3 => 'c',
),
'column_aliases' =>
array (
0 => '',
1 => '',
2 => '',
3 => '',
0 =>
array (
'database' => '',
'table' => '',
'column' => 'a',
'alias' => '',
),
1 =>
array (
'database' => '',
'table' => '',
'column' => 'b',
'alias' => '',
),
2 =>
array (
'database' => '',
'table' => '',
'column' => 'a',
'alias' => '',
),
3 =>
array (
'database' => '',
'table' => '',
'column' => 'c',
'alias' => '',
),
),
),
'fail' => false,
'dialect' => 'ANSI',
),
);
?>
12 changes: 12 additions & 0 deletions tests/testcases/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
1 =>
array (
Expand Down Expand Up @@ -187,6 +188,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
2 =>
array (
Expand Down Expand Up @@ -218,6 +220,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
3 =>
array (
Expand Down Expand Up @@ -313,6 +316,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
4 =>
array (
Expand Down Expand Up @@ -408,6 +412,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
5 =>
array (
Expand Down Expand Up @@ -513,6 +518,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
6 =>
array (
Expand Down Expand Up @@ -553,6 +559,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
7 =>
array (
Expand Down Expand Up @@ -593,6 +600,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
8 =>
array (
Expand All @@ -613,6 +621,7 @@
),
),
'fail' => true,
'dialect' => 'ANSI',
),
9 =>
array (
Expand All @@ -625,6 +634,7 @@
array (
),
'fail' => true,
'dialect' => 'ANSI',
),
10 =>
array (
Expand All @@ -637,6 +647,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: ";"',
'fail' => true,
'dialect' => 'ANSI',
),
11 =>
array (
Expand All @@ -648,6 +659,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: ")"',
'fail' => true,
'dialect' => 'ANSI',
),
);
?>
5 changes: 5 additions & 0 deletions tests/testcases/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
1 =>
array (
Expand All @@ -77,6 +78,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: ";"',
'fail' => true,
'dialect' => 'ANSI',
),
2 =>
array (
Expand All @@ -93,6 +95,7 @@
),
),
'fail' => false,
'dialect' => 'ANSI',
),
3 =>
array (
Expand All @@ -105,6 +108,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: "where"',
'fail' => true,
'dialect' => 'ANSI',
),
4 =>
array (
Expand All @@ -116,6 +120,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: "happy"',
'fail' => true,
'dialect' => 'ANSI',
),
);
?>
6 changes: 6 additions & 0 deletions tests/testcases/drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'drop_behavior' => 'cascade',
),
'fail' => false,
'dialect' => 'ANSI',
),
1 =>
array (
Expand All @@ -33,6 +34,7 @@
'drop_behavior' => 'restrict',
),
'fail' => false,
'dialect' => 'ANSI',
),
2 =>
array (
Expand All @@ -45,6 +47,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: ","',
'fail' => true,
'dialect' => 'ANSI',
),
3 =>
array (
Expand All @@ -57,6 +60,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: "restrict"',
'fail' => true,
'dialect' => 'ANSI',
),
4 =>
array (
Expand All @@ -69,6 +73,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: "where"',
'fail' => true,
'dialect' => 'ANSI',
),
5 =>
array (
Expand All @@ -80,6 +85,7 @@
-- SQL_PARSER_FLAG_FAIL
^ found: "elephant"',
'fail' => true,
'dialect' => 'ANSI',
),
);
?>
Loading

0 comments on commit fc2398d

Please sign in to comment.