Skip to content

Commit 7fa33c5

Browse files
committed
Add a test for full kind descriptor
1 parent 9c33412 commit 7fa33c5

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

PHPCtags.class.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ class PHPCtags
33
{
44
private $mFile;
55

6-
private $mKinds;
7-
86
private $mParser;
97

10-
public function __construct()
11-
{
12-
$this->mKinds= array(
8+
private static $mKinds = array(
139
'c' => 'class',
1410
'm' => 'method',
1511
'f' => 'function',
@@ -18,9 +14,17 @@ public function __construct()
1814
'v' => 'variable',
1915
'i' => 'interface',
2016
);
17+
18+
public function __construct()
19+
{
2120
$this->mParser = new PHPParser_Parser(new PHPParser_Lexer);
2221
}
2322

23+
public static function getMKinds()
24+
{
25+
return self::$mKinds;
26+
}
27+
2428
private function getNodeAccess($node)
2529
{
2630
if ($node->isPrivate()) return 'private';
@@ -179,7 +183,7 @@ private function render($structs, $options)
179183
#field=K, kind of tag as fullname
180184
if (in_array('K', $options['fields'])) {
181185
in_array('z', $options['fields']) && $str .= "kind:";
182-
$str .= "\t" . $this->mKinds[$struct['kind']];
186+
$str .= "\t" . self::$mKinds[$struct['kind']];
183187
}
184188

185189
#field=n

tests/PHPCtagsTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ abstract class PHPCtagsTestCase {
1010

1111
public function __construct()
1212
{
13-
$this->mFormat = "<name>\t<file>\t/^<line content>$/;\"\t<kind>\tline:<line number>\t<scope>\t<access>";
13+
$this->mFormat = "<name>\t<file>\t/^<line content>$/;\"\t<short kind>\tline:<line number>\t<scope>\t<access>";
1414
$this->mOptions = array(
1515
'excmd' => 'pattern',
1616
'fields' => array('n','k','s','a'),
@@ -46,6 +46,7 @@ public function getExampleContent()
4646

4747
public function getExpectResult()
4848
{
49+
$kinds = PHPCtags::getMKinds();
4950
$testcase_expect = '';
5051
$testcase_example_define = $this->getExampleDefine();
5152
$testcase_example_content = $this->getExampleContent();
@@ -55,7 +56,8 @@ public function getExpectResult()
5556
$line = preg_replace('/<name>/', $define['name'], $line);
5657
$line = preg_replace('/<file>/', $this->getExample(), $line);
5758
$line = preg_replace('/<line content>/', rtrim($testcase_example_content[$define['line'] - 1], "\n"), $line);
58-
$line = preg_replace('/<kind>/', $define['kind'], $line);
59+
$line = preg_replace('/<short kind>/', $define['kind'], $line);
60+
$line = preg_replace('/<full kind>/', $kinds[$define['kind']], $line);
5961
$line = preg_replace('/<line number>/', $define['line'], $line);
6062
if(!empty($define['scope'])) {
6163
$line = preg_replace('/<scope>/', $define['scope'], $line);

tests/testcases/0002.testcase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Test for full kind identifier
4+
**/
5+
class t_0002 extends PHPCtagsTestCase {
6+
7+
public function __construct()
8+
{
9+
parent::__construct();
10+
$this->mFormat = "<name>\t<file>\t/^<line content>$/;\"\t<full kind>\tline:<line number>\t<scope>\t<access>";
11+
$this->mExample = '0001';
12+
$this->mOptions['fields'] = array('n','K','s','a');
13+
}
14+
15+
}

0 commit comments

Comments
 (0)