From 2c2bd79ae2238dd599f9706cc0905556f8a4a159 Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Fri, 18 Aug 2023 11:47:50 -0600 Subject: [PATCH] music: trim simple names after punct removal Trim simple names once punctuation has been removed. This prevents situations where album names like "& Yet & Yet" (a real album by post-rock outfit Do Make Say Think) will have blank thumbs. This probably isn't the best approach in general, but nothing about the intelligent name system is a good approach. --- .../java/org/oxycblt/auxio/music/info/Name.kt | 7 +- .../org/oxycblt/auxio/music/info/DateTest.kt | 119 +----------------- .../org/oxycblt/auxio/music/info/NameTest.kt | 4 + 3 files changed, 11 insertions(+), 119 deletions(-) create mode 100644 app/src/test/java/org/oxycblt/auxio/music/info/NameTest.kt diff --git a/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt b/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt index bbde5aca3..fb753f641 100644 --- a/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt +++ b/app/src/main/java/org/oxycblt/auxio/music/info/Name.kt @@ -148,6 +148,8 @@ sealed interface Name : Comparable { private val collator: Collator = Collator.getInstance().apply { strength = Collator.PRIMARY } private val punctRegex by lazy { Regex("[\\p{Punct}+]") } +// TODO: Consider how you want to handle whitespace and "gaps" in names. + /** * Plain [Name.Known] implementation that is internationalization-safe. * @@ -159,7 +161,7 @@ private data class SimpleKnownName(override val raw: String, override val sort: private fun parseToken(name: String): SortToken { // Remove excess punctuation from the string, as those usually aren't considered in sorting. - val stripped = name.replace(punctRegex, "").ifEmpty { name } + val stripped = name.replace(punctRegex, "").trim().ifEmpty { name } val collationKey = collator.getCollationKey(stripped) // Always use lexicographic mode since we aren't parsing any numeric components return SortToken(collationKey, SortToken.Type.LEXICOGRAPHIC) @@ -180,7 +182,8 @@ private data class IntelligentKnownName(override val raw: String, override val s // optimize it val stripped = name - // Remove excess punctuation from the string, as those u + // Remove excess punctuation from the string, as those usually aren't + // considered in sorting. .replace(punctRegex, "") .ifEmpty { name } .run { diff --git a/app/src/test/java/org/oxycblt/auxio/music/info/DateTest.kt b/app/src/test/java/org/oxycblt/auxio/music/info/DateTest.kt index 075df1b1c..40c95bc56 100644 --- a/app/src/test/java/org/oxycblt/auxio/music/info/DateTest.kt +++ b/app/src/test/java/org/oxycblt/auxio/music/info/DateTest.kt @@ -1,119 +1,4 @@ -/* - * Copyright (c) 2023 Auxio Project - * DateTest.kt is part of Auxio. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - package org.oxycblt.auxio.music.info -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -class DateTest { - @Test - fun date_equals_varyingPrecision() { - assertTrue( - requireNotNull(Date.from("2016-08-16T00:01:02")) != - requireNotNull(Date.from("2016-08-16"))) - } - - @Test - fun date_compareTo_dates() { - val a = requireNotNull(Date.from("2016-08-16T00:01:02")) - val b = requireNotNull(Date.from("2016-09-16T00:01:02")) - assertEquals(-1, a.compareTo(b)) - } - - @Test - fun date_compareTo_times() { - val a = requireNotNull(Date.from("2016-08-16T00:02:02")) - val b = requireNotNull(Date.from("2016-08-16T00:01:02")) - assertEquals(1, a.compareTo(b)) - } - - @Test - fun date_compareTo_varyingPrecision() { - val a = requireNotNull(Date.from("2016-08-16T00:01:02")) - val b = requireNotNull(Date.from("2016-08-16")) - assertEquals( - 1, - a.compareTo(b), - ) - } - - @Test - fun date_from_values() { - assertEquals("2016", Date.from(2016).toString()) - assertEquals("2016-08-16", Date.from(2016, 8, 16).toString()) - assertEquals("2016-08-16T00:01Z", Date.from(2016, 8, 16, 0, 1).toString()) - } - - @Test - fun date_from_yearDate() { - assertEquals("2016-08-16", Date.from(20160816).toString()) - assertEquals("2016-08-16", Date.from("20160816").toString()) - } - - @Test - fun date_from_timestamp() { - assertEquals("2016-08-16T00:01:02Z", Date.from("2016-08-16T00:01:02").toString()) - assertEquals("2016-08-16T00:01:02Z", Date.from("2016-08-16 00:01:02").toString()) - } - - @Test - fun date_from_lesserPrecision() { - assertEquals("2016", Date.from("2016").toString()) - assertEquals("2016-08", Date.from("2016-08").toString()) - assertEquals("2016-08-16", Date.from("2016-08-16").toString()) - assertEquals("2016-08-16T00:01Z", Date.from("2016-08-16T00:01").toString()) - } - - @Test - fun date_from_wack() { - assertEquals(null, Date.from(0)) - assertEquals(null, Date.from("")) - assertEquals(null, Date.from("2016-08-16:00:01:02")) - assertEquals("2016-11", Date.from("2016-11-32 25:43:01").toString()) - } - - @Test - fun dateRange_from_correct() { - val range = - requireNotNull( - Date.Range.from( - listOf( - requireNotNull(Date.from("2016-08-16T00:01:02")), - requireNotNull(Date.from("2016-07-16")), - requireNotNull(Date.from("2014-03-12T00")), - requireNotNull(Date.from("2022-12-22T22:22:22"))))) - assertEquals("2014-03-12T00Z", range.min.toString()) - assertEquals("2022-12-22T22:22:22Z", range.max.toString()) - } - - @Test - fun dateRange_from_one() { - val range = - requireNotNull( - Date.Range.from(listOf(requireNotNull(Date.from("2016-08-16T00:01:02"))))) - assertEquals("2016-08-16T00:01:02Z", range.min.toString()) - assertEquals("2016-08-16T00:01:02Z", range.max.toString()) - } - - @Test - fun dateRange_from_none() { - assertEquals(null, Date.Range.from(listOf())) - } -} +class NameTest { +} \ No newline at end of file diff --git a/app/src/test/java/org/oxycblt/auxio/music/info/NameTest.kt b/app/src/test/java/org/oxycblt/auxio/music/info/NameTest.kt new file mode 100644 index 000000000..40c95bc56 --- /dev/null +++ b/app/src/test/java/org/oxycblt/auxio/music/info/NameTest.kt @@ -0,0 +1,4 @@ +package org.oxycblt.auxio.music.info + +class NameTest { +} \ No newline at end of file