mirror of
https://github.com/diocloid/LinkTitles.git
synced 2025-07-13 01:39:30 +02:00
Rename Delimiters to Splitter; add tests.
This commit is contained in:
@ -37,7 +37,7 @@
|
||||
"LinkTitles\\Linker": "includes/Linker.php",
|
||||
"LinkTitles\\Target": "includes/Target.php",
|
||||
"LinkTitles\\Targets": "includes/Targets.php",
|
||||
"LinkTitles\\Delimiters": "includes/Delimiters.php",
|
||||
"LinkTitles\\Splitter": "includes/Splitter.php",
|
||||
"LinkTitles\\Config": "includes/Config.php",
|
||||
"LinkTitles\\Special": "includes/Special.php",
|
||||
"LinkTitles\\TestCase": "tests/phpunit/TestCase.php"
|
||||
|
@ -72,7 +72,7 @@ class Linker {
|
||||
$limitReached = false;
|
||||
$newText = $text;
|
||||
|
||||
$delimiters = Delimiters::default( $this->config );
|
||||
$splitter = Splitter::default( $this->config );
|
||||
$targets = Targets::default( $title, $this->config );
|
||||
|
||||
// Iterate through the target page titles
|
||||
@ -89,7 +89,7 @@ class Linker {
|
||||
// Split the page content by non-linkable sections.
|
||||
// Credits to inhan @ StackOverflow for suggesting preg_split.
|
||||
// See http://stackoverflow.com/questions/10672286
|
||||
$arr = $delimiters->split( $newText );
|
||||
$arr = $splitter->split( $newText );
|
||||
$count = 0;
|
||||
|
||||
// Cache the target title text for the regex callbacks
|
||||
@ -113,7 +113,7 @@ class Linker {
|
||||
if ( $this->config->smartMode && !$limitReached ) {
|
||||
if ( $count > 0 ) {
|
||||
// Split the text again because it was changed in the first pass.
|
||||
$arr = $delimiters->split( $newText );
|
||||
$arr = $splitter->split( $newText );
|
||||
}
|
||||
|
||||
for ( $i = 0; $i < count( $arr ); $i+=2 ) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* The Delimiters class caches a regular expression that delimits text to be parsed.
|
||||
* The Splitter class caches a regular expression that delimits text to be parsed.
|
||||
*
|
||||
* Copyright 2012-2017 Daniel Kraus <bovender@bovender.de> ('bovender')
|
||||
*
|
||||
@ -26,7 +26,7 @@ namespace LinkTitles;
|
||||
/**
|
||||
* Caches a regular expression that delimits text to be parsed.
|
||||
*/
|
||||
class Delimiters {
|
||||
class Splitter {
|
||||
/**
|
||||
* The splitting expression that separates text to be parsed from text that
|
||||
* must not be parsed.
|
||||
@ -35,7 +35,7 @@ class Delimiters {
|
||||
public $splitter;
|
||||
|
||||
/**
|
||||
* The LinkTitles configuration for this Delimiters instance.
|
||||
* The LinkTitles configuration for this Splitter instance.
|
||||
* @var Config $config
|
||||
*/
|
||||
public $config;
|
||||
@ -43,12 +43,12 @@ class Delimiters {
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Gets the Delimiters singleton; may build one with the given config or the
|
||||
* Gets the Splitter singleton; may build one with the given config or the
|
||||
* default config if none is given.
|
||||
*
|
||||
* If the instance was already created, it does not matter what Config this
|
||||
* method is called with. To re-create an instance with a different Config,
|
||||
* call Delimiters::invalidate() first.
|
||||
* call Splitter::invalidate() first.
|
||||
*
|
||||
* @param Config|null $config LinkTitles configuration.
|
||||
*/
|
||||
@ -57,7 +57,7 @@ class Delimiters {
|
||||
if ( $config === null ) {
|
||||
$config = new Config();
|
||||
}
|
||||
self::$instance = new Delimiters( $config );
|
||||
self::$instance = new Splitter( $config );
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
@ -73,7 +73,7 @@ class Delimiters {
|
||||
|
||||
protected function __construct( Config $config) {
|
||||
$this->config = $config;
|
||||
$this->buildDelimiters();
|
||||
$this->buildSplitter();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +92,7 @@ class Delimiters {
|
||||
* text that should be parsed from text that should not be
|
||||
* parsed (e.g. inside existing links etc.)
|
||||
*/
|
||||
private function buildDelimiters() {
|
||||
private function buildSplitter() {
|
||||
if ( $this->config->skipTemplates )
|
||||
{
|
||||
// Use recursive regex to balance curly braces;
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @group bovender
|
||||
*/
|
||||
class DelimitersTest extends MediaWikiTestCase {
|
||||
/**
|
||||
* @dataProvider provideSplitData
|
||||
*/
|
||||
public function testSplit( $input, $output ) {
|
||||
|
||||
}
|
||||
|
||||
public static function provideSplitData() {
|
||||
return [
|
||||
[
|
||||
'this may be linked [[this may not be linked]]',
|
||||
[ 'this may be linked', '[[this may not be linked]]']
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
31
tests/phpunit/SplitterTest.php
Normal file
31
tests/phpunit/SplitterTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @group bovender
|
||||
*/
|
||||
class SplitterTest extends MediaWikiTestCase {
|
||||
/**
|
||||
* @dataProvider provideSplitData
|
||||
*/
|
||||
public function testSplit( $input, $expectedOutput ) {
|
||||
$splitter = LinkTitles\Splitter::default();
|
||||
$this->assertSame( $expectedOutput, $splitter->split( $input ) );
|
||||
}
|
||||
|
||||
// TODO: Add more examples.
|
||||
public static function provideSplitData() {
|
||||
return [
|
||||
[
|
||||
'this may be linked [[this may not be linked]]',
|
||||
[ 'this may be linked ', '[[this may not be linked]]', '' ]
|
||||
],
|
||||
[
|
||||
'this may be linked <gallery>this may not be linked</gallery>',
|
||||
[ 'this may be linked ', '<gallery>this may not be linked</gallery>', '' ]
|
||||
],
|
||||
[
|
||||
'this may be linked {{mytemplate|param={{transcluded}}}}',
|
||||
[ 'this may be linked ', '{{mytemplate|param={{transcluded}}}}', '' ]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user