Skip to content

Commit

Permalink
Merge pull request #180 from DataValues/fix-multi-parse
Browse files Browse the repository at this point in the history
Fix multi parse regression in GlobeCoordinateParser
  • Loading branch information
JeroenDeDauw committed Dec 19, 2019
2 parents 4855a95 + 3035f7d commit e58eff0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -104,6 +104,10 @@ employees for the [Wikidata project](https://wikidata.org/).

## Release notes

### 4.2.1 (2019-12-18)

* Fixed `GlobeCoordinateParser` not being able to parse multiple values (4.2.0 regression)

### 4.2.0 (2019-09-20)

* Added `GlobeCoordinateValue::withPrecision`
Expand Down
14 changes: 8 additions & 6 deletions src/PackagePrivate/LatLongPrecisionParser.php
Expand Up @@ -40,17 +40,19 @@ public function parse( string $coordinate ): PreciseLatLong {
*/
private function getParsers(): iterable {
if ( $this->parsers === null ) {
$this->parsers = new \CachingIterator( $this->getNewParsers(), \CachingIterator::FULL_CACHE );
$this->parsers = $this->getNewParsers();
}

return $this->parsers;
}

private function getNewParsers(): \Generator {
yield new PrecisionParser( new FloatCoordinateParser( $this->options ), new FloatPrecisionDetector() );
yield new PrecisionParser( new DmsCoordinateParser( $this->options ), new DmsPrecisionDetector() );
yield new PrecisionParser( new DmCoordinateParser( $this->options ), new DmPrecisionDetector() );
yield new PrecisionParser( new DdCoordinateParser( $this->options ), new FloatPrecisionDetector() );
private function getNewParsers(): array {
return [
new PrecisionParser( new FloatCoordinateParser( $this->options ), new FloatPrecisionDetector() ),
new PrecisionParser( new DmsCoordinateParser( $this->options ), new DmsPrecisionDetector() ),
new PrecisionParser( new DmCoordinateParser( $this->options ), new DmPrecisionDetector() ),
new PrecisionParser( new DdCoordinateParser( $this->options ), new FloatPrecisionDetector() )
];
}

}
34 changes: 34 additions & 0 deletions tests/unit/PackagePrivate/LatLongPrecisionParserTest.php
@@ -0,0 +1,34 @@
<?php

declare( strict_types = 1 );

namespace Tests\DataValues\Geo\PackagePrivate;

use DataValues\Geo\PackagePrivate\LatLongPrecisionParser;
use PHPUnit\Framework\TestCase;

/**
* @covers \DataValues\Geo\PackagePrivate\LatLongPrecisionParser
* @license GPL-2.0-or-later
*/
class LatLongPrecisionParserTest extends TestCase {

public function testSuccessiveFloatParses() {
$parser = new LatLongPrecisionParser();

$this->assertEquals(
$parser->parse( 'S5.5 W37' ),
$parser->parse( 'S5.5 W37' )
);
}

public function testSuccessiveDmsParses() {
$parser = new LatLongPrecisionParser();

$this->assertEquals(
$parser->parse( '55° 0\' 0", 37° 0\' 0"' ),
$parser->parse( '55° 0\' 0", 37° 0\' 0"' )
);
}

}
14 changes: 14 additions & 0 deletions tests/unit/Parsers/GlobeCoordinateParserTest.php
Expand Up @@ -259,4 +259,18 @@ public function precisionDetectionProvider() {
];
}

public function testCanParseSuccessiveValues() {
$parser = new GlobeCoordinateParser();

$this->assertEquals(
$parser->parse( 'S5.5 W37' ),
$parser->parse( 'S5.5 W37' )
);

$this->assertEquals(
$parser->parse( '55° 0\' 0", 37° 0\' 0"' ),
$parser->parse( '55° 0\' 0", 37° 0\' 0"' )
);
}

}

0 comments on commit e58eff0

Please sign in to comment.