| | 377 | |
| | 378 | /** |
| | 379 | * Tests value harmonization (e.g. case normalization and trimming) resulting in a valid preset match. |
| | 380 | * |
| | 381 | * @throws IOException if an I/O error occurs |
| | 382 | */ |
| | 383 | @Test |
| | 384 | void testTryGuessHarmonizedMatch() throws IOException { |
| | 385 | final List<TestError> errors = test(OsmUtils.createPrimitive("way highway=\"Residential \"")); |
| | 386 | assertEquals(1, errors.size()); |
| | 387 | final TestError error = errors.get(0); |
| | 388 | assertEquals(Severity.WARNING, error.getSeverity()); |
| | 389 | assertEquals(TagChecker.MISSPELLED_VALUE, error.getCode()); |
| | 390 | assertTrue(error.getDescription().contains("maybe 'residential' is meant?")); |
| | 391 | } |
| | 392 | |
| | 393 | /** |
| | 394 | * Tests a single unambiguous typo corrected via Levenshtein distance. |
| | 395 | * |
| | 396 | * @throws IOException if an I/O error occurs |
| | 397 | */ |
| | 398 | @Test |
| | 399 | void testTryGuessSingleLevenshteinMatch() throws IOException { |
| | 400 | final List<TestError> errors = test(OsmUtils.createPrimitive("way highway=residentail")); |
| | 401 | assertEquals(1, errors.size()); |
| | 402 | final TestError error = errors.get(0); |
| | 403 | assertEquals(Severity.WARNING, error.getSeverity()); |
| | 404 | assertEquals(TagChecker.MISSPELLED_VALUE, error.getCode()); |
| | 405 | assertTrue(error.getDescription().contains("maybe 'residential' is meant?")); |
| | 406 | } |
| | 407 | |
| | 408 | /** |
| | 409 | * Tests a misspelled value that has multiple equally close preset candidates. |
| | 410 | * |
| | 411 | * @throws IOException if an I/O error occurs |
| | 412 | */ |
| | 413 | @Test |
| | 414 | void testTryGuessMultipleLevenshteinMatches() throws IOException { |
| | 415 | // "radh" (length 4) has a Levenshtein distance of 2 to both "path" and "road" |
| | 416 | final List<TestError> errors = test(OsmUtils.createPrimitive("way highway=radh")); |
| | 417 | assertEquals(1, errors.size()); |
| | 418 | final TestError error = errors.get(0); |
| | 419 | assertEquals(Severity.WARNING, error.getSeverity()); |
| | 420 | assertEquals(TagChecker.MISSPELLED_VALUE_NO_FIX, error.getCode()); |
| | 421 | assertTrue(error.getDescription().contains("maybe one of [")); |
| | 422 | } |
| | 423 | |
| | 424 | /** |
| | 425 | * Tests that short values do not trigger false typo suggestions when length differences are too large. |
| | 426 | * |
| | 427 | * @throws IOException if an I/O error occurs |
| | 428 | */ |
| | 429 | @Test |
| | 430 | void testTryGuessShortValueGuard() throws IOException { |
| | 431 | final List<TestError> errors = test(OsmUtils.createPrimitive("way surface=u")); |
| | 432 | assertEquals(1, errors.size()); |
| | 433 | final TestError error = errors.get(0); |
| | 434 | assertEquals(Severity.OTHER, error.getSeverity()); |
| | 435 | assertEquals(TagChecker.INVALID_VALUE, error.getCode()); |
| | 436 | } |
| | 437 | |
| | 438 | /** |
| | 439 | * Tests that short values with no matching characters are reported as unknown instead of misspelled. |
| | 440 | * |
| | 441 | * @throws IOException if an I/O error occurs |
| | 442 | */ |
| | 443 | @Test |
| | 444 | void testTryGuessCompletelyDifferentShortValue() throws IOException { |
| | 445 | final List<TestError> errors = test(OsmUtils.createPrimitive("node amenity=parking fee=10")); |
| | 446 | assertEquals(1, errors.size()); |
| | 447 | final TestError error = errors.get(0); |
| | 448 | assertEquals(Severity.OTHER, error.getSeverity()); |
| | 449 | assertEquals(TagChecker.INVALID_VALUE, error.getCode()); |
| | 450 | } |
| | 451 | |
| | 452 | /** |
| | 453 | * Tests an unknown tag value that does not match any preset within the allowed Levenshtein distance. |
| | 454 | * |
| | 455 | * @throws IOException if an I/O error occurs |
| | 456 | */ |
| | 457 | @Test |
| | 458 | void testTryGuessUnknownValue() throws IOException { |
| | 459 | final List<TestError> errors = test(OsmUtils.createPrimitive("way highway=completely_unknown_value")); |
| | 460 | assertEquals(1, errors.size()); |
| | 461 | final TestError error = errors.get(0); |
| | 462 | assertEquals(Severity.OTHER, error.getSeverity()); |
| | 463 | assertEquals(TagChecker.INVALID_VALUE, error.getCode()); |
| | 464 | } |
| | 465 | |
| | 466 | /** |
| | 467 | * Tests that keys listed in {@code ignoreForLevenshtein} are skipped during typo detection. |
| | 468 | * |
| | 469 | * @throws IOException if an I/O error occurs |
| | 470 | */ |
| | 471 | @Test |
| | 472 | void testTryGuessIgnoredKey() throws IOException { |
| | 473 | final List<TestError> errors = test(OsmUtils.createPrimitive("way highway=residential name=Residentail")); |
| | 474 | assertTrue(errors.isEmpty()); |
| | 475 | } |
| | 476 | |
| | 477 | |