View source
<?php
require_once dirname(__FILE__) . '/coder_review_test_case.tinc';
class CoderReviewCommentTest extends CoderReviewTestCase {
public static $modules = array(
'coder_review',
);
function __construct($id = NULL) {
parent::__construct('comment', $id);
}
public static function getInfo() {
return array(
'name' => 'Coder Review Comment Style Tests',
'description' => 'Tests for the coder commenting standards review.',
'group' => 'CoderReview',
);
}
function setUp() {
parent::setUp();
$this->file_line = "/**\n * @file\n * Foo\n */\n";
$this->comment_header = $this->file_line;
}
function testGeneralCommentStyle() {
$this
->assertCoderReviewPass($this->comment_header . "/**\n * Comment.\n");
$this
->assertCoderReviewFail($this->comment_header . "/**\n* Comment.\n");
$this
->assertCoderReviewFail($this->comment_header . "/**\n *Comment.\n");
}
function testIdCommentLine() {
$this
->assertCoderReviewFail($this->comment_header . '// $Id$' . "\n");
$this
->assertCoderReviewFail($this->comment_header . '/* $Id$ */' . "\n");
}
function testHookImplementationComment() {
$this
->assertCoderReviewPass($this->comment_header . "/**\n * Implements hook_foo().\n */");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * Implements hook_foo()\n */");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * Implements hook_foo\n */");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * Implements hook_foo.\n */");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * implements hook_foo().\n */");
$this
->assertCoderReviewFail($this->comment_header . '// Implements hook_foo().');
$this
->assertCoderReviewFail($this->comment_header . "/* Implements hook_foo().\n */");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * Implementation of hook_foo().\n */");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * Implements of hook_foo().\n */");
}
function testFileDoxygenComment() {
$this
->assertCoderReviewPass("/**\n * @file\n * File description.");
$this
->assertCoderReviewFail("/**\n * @file File description.");
$this
->assertCoderReviewFail("/**\n * @file File description.");
}
function testSeeDoxygenComment() {
$this
->assertCoderReviewPass($this->comment_header . "/**\n * @see some_function()");
$this
->assertCoderReviewPass($this->comment_header . "/**\n * @see some_function(), foo.tpl.php");
$this
->assertCoderReviewPass($this->comment_header . "/**\n * @see some_function(), foo.tpl.php, bar.tpl.php");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * foo bar @see some_function()");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function, foo.tpl.php");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function(),foo.tpl.php");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function() foo.tpl.php");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function(), foo.tpl.php bar.tpl.php");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function(),");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function().");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see some_function(), foo.tpl.php.");
$this
->assertCoderReviewFail($this->comment_header . "/**\n * @see\n * some_function()");
$this
->assertCoderReviewPass($this->comment_header . "// @see some_function()");
$this
->assertCoderReviewPass($this->comment_header . "// @see foo.tpl.php");
$this
->assertCoderReviewPass($this->comment_header . "// @see some_function(), foo.tpl.php");
$this
->assertCoderReviewFail($this->comment_header . "// @see some_function");
}
function testShellComment() {
$this
->assertCoderReviewFail($this->comment_header . "# function shell_comment() {\n");
}
function testForExample() {
$this
->assertCoderReviewFail($this->comment_header . "// Whatever, e.g. this is wrong.\n");
$this
->assertCoderReviewPass($this->comment_header . "// Whatever, e.g., this is right.\n");
$this
->assertCoderReviewFail($this->comment_header . "// Whatever, (eg this is wrong).\n");
$this
->assertCoderReviewFail($this->comment_header . "// Whatever, (eg, this is wrong).\n");
$this
->assertCoderReviewPass($this->comment_header . "// Whatever, (e.g., this is right).\n");
$this
->assertCoderReviewFail($this->comment_header . "// Whatever, i.e., this is wrong.\n");
$this
->assertCoderReviewPass($this->comment_header . "// Whatever, i.e. this is right.\n");
$this
->assertCoderReviewFail($this->comment_header . "// Whatever, (ie this is wrong).\n");
$this
->assertCoderReviewFail($this->comment_header . "// Whatever, ie this is wrong.\n");
$this
->assertCoderReviewFail($this->comment_header . "// ie stands for example, and this is not OK.\n");
$this
->assertCoderReviewPass($this->comment_header . "// IE stands for Internet Explorer, and this is OK.\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('Whatever, e.g. this is wrong.');\n");
$this
->assertCoderReviewPass($this->comment_header . " return t('Whatever, e.g., this is right.');\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('Whatever, (eg this is wrong).');\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('Whatever, (eg, this is wrong).');\n");
$this
->assertCoderReviewPass($this->comment_header . " return t('Whatever, (e.g., this is right).');\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('Whatever, i.e., this is wrong.');\n");
$this
->assertCoderReviewPass($this->comment_header . " return t('Whatever, i.e. this is right.');\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('Whatever, (ie this is wrong).');\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('Whatever, ie this is wrong.');\n");
$this
->assertCoderReviewFail($this->comment_header . " return t('ie stands for example, and this is not OK.');\n");
$this
->assertCoderReviewPass($this->comment_header . " return t('IE stands for Internet Explorer, and this is OK.');\n");
}
}