Henning Snater has uploaded a new change for review. https://gerrit.wikimedia.org/r/68354
Change subject: Applying precision set via parser options to GeoCoordinateParsers ...................................................................... Applying precision set via parser options to GeoCoordinateParsers Change-Id: I83a3247f870959a34ffdd811f4216758d02aa4ab --- M ValueParsers/includes/parsers/DdCoordinateParser.php M ValueParsers/includes/parsers/DmCoordinateParser.php M ValueParsers/includes/parsers/DmsCoordinateParser.php M ValueParsers/includes/parsers/FloatCoordinateParser.php M ValueParsers/tests/phpunit/parsers/DdCoordinateParserTest.php M ValueParsers/tests/phpunit/parsers/DmCoordinateParserTest.php M ValueParsers/tests/phpunit/parsers/DmsCoordinateParserTest.php M ValueParsers/tests/phpunit/parsers/FloatCoordinateParserTest.php 8 files changed, 37 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues refs/changes/54/68354/1 diff --git a/ValueParsers/includes/parsers/DdCoordinateParser.php b/ValueParsers/includes/parsers/DdCoordinateParser.php index bd80b7a..18f70b2 100644 --- a/ValueParsers/includes/parsers/DdCoordinateParser.php +++ b/ValueParsers/includes/parsers/DdCoordinateParser.php @@ -102,7 +102,9 @@ $latitude = $this->getParsedCoordinate( $latitude ); $longitude = $this->getParsedCoordinate( $longitude ); - $precision = min( $latitude['precision'], $longitude['precision'] ); + $precision = ( $this->options->hasOption( 'precision' ) ) + ? $this->options->getOption( 'precision' ) + : min( $latitude['precision'], $longitude['precision'] ); return new GeoCoordinateValue( $latitude['coordinate'], diff --git a/ValueParsers/includes/parsers/DmCoordinateParser.php b/ValueParsers/includes/parsers/DmCoordinateParser.php index c808005..0dda0cf 100644 --- a/ValueParsers/includes/parsers/DmCoordinateParser.php +++ b/ValueParsers/includes/parsers/DmCoordinateParser.php @@ -104,7 +104,9 @@ $latitude = $this->getParsedCoordinate( $latitude ); $longitude = $this->getParsedCoordinate( $longitude ); - $precision = min( $latitude['precision'], $longitude['precision'] ); + $precision = ( $this->options->hasOption( 'precision' ) ) + ? $this->options->getOption( 'precision' ) + : min( $latitude['precision'], $longitude['precision'] ); return new GeoCoordinateValue( $latitude['coordinate'], diff --git a/ValueParsers/includes/parsers/DmsCoordinateParser.php b/ValueParsers/includes/parsers/DmsCoordinateParser.php index c4f5075..68abac7 100644 --- a/ValueParsers/includes/parsers/DmsCoordinateParser.php +++ b/ValueParsers/includes/parsers/DmsCoordinateParser.php @@ -106,7 +106,9 @@ $latitude = $this->getParsedCoordinate( $latitude ); $longitude = $this->getParsedCoordinate( $longitude ); - $precision = min( $latitude['precision'], $longitude['precision'] ); + $precision = ( $this->options->hasOption( 'precision' ) ) + ? $this->options->getOption( 'precision' ) + : min( $latitude['precision'], $longitude['precision'] ); return new GeoCoordinateValue( $latitude['coordinate'], diff --git a/ValueParsers/includes/parsers/FloatCoordinateParser.php b/ValueParsers/includes/parsers/FloatCoordinateParser.php index 74d37b2..e5df27a 100644 --- a/ValueParsers/includes/parsers/FloatCoordinateParser.php +++ b/ValueParsers/includes/parsers/FloatCoordinateParser.php @@ -92,7 +92,9 @@ $latitude = $this->getParsedCoordinate( $latitude ); $longitude = $this->getParsedCoordinate( $longitude ); - $precision = min( $latitude['precision'], $longitude['precision'] ); + $precision = ( $this->options->hasOption( 'precision' ) ) + ? $this->options->getOption( 'precision' ) + : min( $latitude['precision'], $longitude['precision'] ); $coordinate = new GeoCoordinateValue( $latitude['coordinate'], @@ -105,7 +107,7 @@ } /** - * Parsers a single coordinate (either latitude or longitude) and returns it as a float along + * Parses a single coordinate (either latitude or longitude) and returns it as a float along * with the coordinate precision detected. * * @since 0.1 diff --git a/ValueParsers/tests/phpunit/parsers/DdCoordinateParserTest.php b/ValueParsers/tests/phpunit/parsers/DdCoordinateParserTest.php index 9198663..2734e00 100644 --- a/ValueParsers/tests/phpunit/parsers/DdCoordinateParserTest.php +++ b/ValueParsers/tests/phpunit/parsers/DdCoordinateParserTest.php @@ -63,6 +63,12 @@ $argLists[] = array( (string)$value, $expected ); } + // Checking whether precision gets set via the parser options: + $parser = $this->getInstance(); + $parser->getOptions()->setOption( 'precision', 0.1 ); + $expected = new GeoCoordinateValue( 1, 1, null, 0.1 ); + $argLists[] = array( '1°, 1°', $expected, $parser ); + return $argLists; } diff --git a/ValueParsers/tests/phpunit/parsers/DmCoordinateParserTest.php b/ValueParsers/tests/phpunit/parsers/DmCoordinateParserTest.php index 2c432fb..3aa62d3 100644 --- a/ValueParsers/tests/phpunit/parsers/DmCoordinateParserTest.php +++ b/ValueParsers/tests/phpunit/parsers/DmCoordinateParserTest.php @@ -63,6 +63,12 @@ $argLists[] = array( (string)$value, $expected ); } + // Checking whether precision gets set via the parser options: + $parser = $this->getInstance(); + $parser->getOptions()->setOption( 'precision', 0.1 ); + $expected = new GeoCoordinateValue( 1.2, 1.2, null, 0.1 ); + $argLists[] = array( '1° 12\', 1° 12\'', $expected, $parser ); + return $argLists; } diff --git a/ValueParsers/tests/phpunit/parsers/DmsCoordinateParserTest.php b/ValueParsers/tests/phpunit/parsers/DmsCoordinateParserTest.php index d63e38e..fc84fcc 100644 --- a/ValueParsers/tests/phpunit/parsers/DmsCoordinateParserTest.php +++ b/ValueParsers/tests/phpunit/parsers/DmsCoordinateParserTest.php @@ -50,7 +50,6 @@ // TODO: test with different parser options $valid = array( - // DMS '55° 45\' 20.8296", 37° 37\' 3.4788"' => array( 55.755786, 37.617633, 1 / 3600 * 0.0001 ), '55° 45\' 20.8296", -37° 37\' 3.4788"' => array( 55.755786, -37.617633, 1 / 3600 * 0.0001 ), '-55° 45\' 20.8296", -37° 37\' 3.4788"' => array( -55.755786, -37.617633, 1 / 3600 * 0.0001 ), @@ -69,6 +68,12 @@ $argLists[] = array( (string)$value, $expected ); } + // Checking whether precision gets set via the parser options: + $parser = $this->getInstance(); + $parser->getOptions()->setOption( 'precision', 0.1 ); + $expected = new GeoCoordinateValue( 1.02, 1.02, null, 0.1 ); + $argLists[] = array( '1° 1\' 12", 1° 1\' 12"', $expected, $parser ); + return $argLists; } diff --git a/ValueParsers/tests/phpunit/parsers/FloatCoordinateParserTest.php b/ValueParsers/tests/phpunit/parsers/FloatCoordinateParserTest.php index 83c124e..758689f 100644 --- a/ValueParsers/tests/phpunit/parsers/FloatCoordinateParserTest.php +++ b/ValueParsers/tests/phpunit/parsers/FloatCoordinateParserTest.php @@ -64,6 +64,12 @@ $argLists[] = array( (string)$value, $expected ); } + // Checking whether precision gets set via the parser options: + $parser = $this->getInstance(); + $parser->getOptions()->setOption( 'precision', 0.1 ); + $expected = new GeoCoordinateValue( 1, 1, null, 0.1 ); + $argLists[] = array( '1, 1', $expected, $parser ); + return $argLists; } -- To view, visit https://gerrit.wikimedia.org/r/68354 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I83a3247f870959a34ffdd811f4216758d02aa4ab Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DataValues Gerrit-Branch: master Gerrit-Owner: Henning Snater <henning.sna...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits