musikr: move tag tests away from auxio

This commit is contained in:
Alexander Capehart 2024-12-16 13:27:45 -05:00
parent 71667f378d
commit d4d00249df
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
7 changed files with 112 additions and 130 deletions

View file

@ -71,6 +71,14 @@ dependencies {
// Build // Build
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.3" coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.3"
// Testing
testImplementation "junit:junit:4.13.2"
testImplementation "io.mockk:mockk:1.13.7"
testImplementation "org.robolectric:robolectric:4.11"
testImplementation 'androidx.test:core-ktx:1.6.1'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
} }
task assembleTaglib(type: Exec) { task assembleTaglib(type: Exec) {

View file

@ -21,337 +21,317 @@ package org.oxycblt.musikr.tag
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals import org.junit.Assert.assertNotEquals
import org.junit.Test import org.junit.Test
import org.oxycblt.musikr.tag.interpret.Naming
import org.oxycblt.musikr.tag.interpret.Token
class NameTest { class NameTest {
@Test @Test
fun name_simple_withoutPunct() { fun name_simple_withoutPunct() {
val name = Name.Known.SimpleFactory.parse("Loveless", null) val name = Naming.simple().name("Loveless", null)
assertEquals("Loveless", name.raw) assertEquals("Loveless", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("L", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("Loveless", only.collationKey.sourceString) assertEquals("Loveless", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_simple_withPunct() { fun name_simple_withPunct() {
val name = Name.Known.SimpleFactory.parse("alt-J", null) val name = Naming.simple().name("alt-J", null)
assertEquals("alt-J", name.raw) assertEquals("alt-J", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("A", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("altJ", only.collationKey.sourceString) assertEquals("altJ", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_simple_oopsAllPunct() { fun name_simple_oopsAllPunct() {
val name = Name.Known.SimpleFactory.parse("!!!", null) val name = Naming.simple().name("!!!", null)
assertEquals("!!!", name.raw) assertEquals("!!!", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("!", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("!!!", only.collationKey.sourceString) assertEquals("!!!", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_simple_spacedPunct() { fun name_simple_spacedPunct() {
val name = Name.Known.SimpleFactory.parse("& Yet & Yet", null) val name = Naming.simple().name("& Yet & Yet", null)
assertEquals("& Yet & Yet", name.raw) assertEquals("& Yet & Yet", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("Y", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Yet Yet", first.collationKey.sourceString) assertEquals("Yet Yet", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
} }
@Test @Test
fun name_simple_withSort() { fun name_simple_withSort() {
val name = Name.Known.SimpleFactory.parse("The Smile", "Smile") val name = Naming.simple().name("The Smile", "Smile")
assertEquals("The Smile", name.raw) assertEquals("The Smile", name.raw)
assertEquals("Smile", name.sort) assertEquals("Smile", name.sort)
assertEquals("S", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("Smile", only.collationKey.sourceString) assertEquals("Smile", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withoutNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("Loveless", null) val name = Naming.intelligent().name("Loveless", null)
assertEquals("Loveless", name.raw) assertEquals("Loveless", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("L", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("Loveless", only.collationKey.sourceString) assertEquals("Loveless", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withSpacedStartNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withSpacedStartNumerics() {
val name = Name.Known.IntelligentFactory.parse("15 Step", null) val name = Naming.intelligent().name("15 Step", null)
assertEquals("15 Step", name.raw) assertEquals("15 Step", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("#", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("15", first.collationKey.sourceString) assertEquals("15", first.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, first.type) assertEquals(Token.Type.NUMERIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("Step", second.collationKey.sourceString) assertEquals("Step", second.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, second.type) assertEquals(Token.Type.LEXICOGRAPHIC, second.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withPackedStartNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withPackedStartNumerics() {
val name = Name.Known.IntelligentFactory.parse("23Kid", null) val name = Naming.intelligent().name("23Kid", null)
assertEquals("23Kid", name.raw) assertEquals("23Kid", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("#", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("23", first.collationKey.sourceString) assertEquals("23", first.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, first.type) assertEquals(Token.Type.NUMERIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("Kid", second.collationKey.sourceString) assertEquals("Kid", second.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, second.type) assertEquals(Token.Type.LEXICOGRAPHIC, second.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withSpacedMiddleNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withSpacedMiddleNumerics() {
val name = Name.Known.IntelligentFactory.parse("Foo 1 2 Bar", null) val name = Naming.intelligent().name("Foo 1 2 Bar", null)
assertEquals("Foo 1 2 Bar", name.raw) assertEquals("Foo 1 2 Bar", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("F", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Foo", first.collationKey.sourceString) assertEquals("Foo", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("1", second.collationKey.sourceString) assertEquals("1", second.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, second.type) assertEquals(Token.Type.NUMERIC, second.type)
val third = name.sortTokens[2] val third = name.tokens[2]
assertEquals(" ", third.collationKey.sourceString) assertEquals(" ", third.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, third.type) assertEquals(Token.Type.LEXICOGRAPHIC, third.type)
val fourth = name.sortTokens[3] val fourth = name.tokens[3]
assertEquals("2", fourth.collationKey.sourceString) assertEquals("2", fourth.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, fourth.type) assertEquals(Token.Type.NUMERIC, fourth.type)
val fifth = name.sortTokens[4] val fifth = name.tokens[4]
assertEquals("Bar", fifth.collationKey.sourceString) assertEquals("Bar", fifth.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, fifth.type) assertEquals(Token.Type.LEXICOGRAPHIC, fifth.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withPackedMiddleNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withPackedMiddleNumerics() {
val name = Name.Known.IntelligentFactory.parse("Foo12Bar", null) val name = Naming.intelligent().name("Foo12Bar", null)
assertEquals("Foo12Bar", name.raw) assertEquals("Foo12Bar", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("F", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Foo", first.collationKey.sourceString) assertEquals("Foo", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("12", second.collationKey.sourceString) assertEquals("12", second.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, second.type) assertEquals(Token.Type.NUMERIC, second.type)
val third = name.sortTokens[2] val third = name.tokens[2]
assertEquals("Bar", third.collationKey.sourceString) assertEquals("Bar", third.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, third.type) assertEquals(Token.Type.LEXICOGRAPHIC, third.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withSpacedEndNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withSpacedEndNumerics() {
val name = Name.Known.IntelligentFactory.parse("Foo 1", null) val name = Naming.intelligent().name("Foo 1", null)
assertEquals("Foo 1", name.raw) assertEquals("Foo 1", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("F", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Foo", first.collationKey.sourceString) assertEquals("Foo", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("1", second.collationKey.sourceString) assertEquals("1", second.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, second.type) assertEquals(Token.Type.NUMERIC, second.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withoutArticle_withPackedEndNumerics() { fun name_intelligent_withoutPunct_withoutArticle_withPackedEndNumerics() {
val name = Name.Known.IntelligentFactory.parse("Error404", null) val name = Naming.intelligent().name("Error404", null)
assertEquals("Error404", name.raw) assertEquals("Error404", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("E", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Error", first.collationKey.sourceString) assertEquals("Error", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("404", second.collationKey.sourceString) assertEquals("404", second.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, second.type) assertEquals(Token.Type.NUMERIC, second.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withThe_withoutNumerics() { fun name_intelligent_withoutPunct_withThe_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("The National Anthem", null) val name = Naming.intelligent().name("The National Anthem", null)
assertEquals("The National Anthem", name.raw) assertEquals("The National Anthem", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("N", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("National Anthem", first.collationKey.sourceString) assertEquals("National Anthem", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withAn_withoutNumerics() { fun name_intelligent_withoutPunct_withAn_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("An Eagle in Your Mind", null) val name = Naming.intelligent().name("An Eagle in Your Mind", null)
assertEquals("An Eagle in Your Mind", name.raw) assertEquals("An Eagle in Your Mind", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("E", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Eagle in Your Mind", first.collationKey.sourceString) assertEquals("Eagle in Your Mind", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_withA_withoutNumerics() { fun name_intelligent_withoutPunct_withA_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("A Song For Our Fathers", null) val name = Naming.intelligent().name("A Song For Our Fathers", null)
assertEquals("A Song For Our Fathers", name.raw) assertEquals("A Song For Our Fathers", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("S", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Song For Our Fathers", first.collationKey.sourceString) assertEquals("Song For Our Fathers", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
} }
@Test @Test
fun name_intelligent_withPunct_withoutArticle_withoutNumerics() { fun name_intelligent_withPunct_withoutArticle_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("alt-J", null) val name = Naming.intelligent().name("alt-J", null)
assertEquals("alt-J", name.raw) assertEquals("alt-J", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("A", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("altJ", only.collationKey.sourceString) assertEquals("altJ", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_intelligent_oopsAllPunct_withoutArticle_withoutNumerics() { fun name_intelligent_oopsAllPunct_withoutArticle_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("!!!", null) val name = Naming.intelligent().name("!!!", null)
assertEquals("!!!", name.raw) assertEquals("!!!", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("!", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("!!!", only.collationKey.sourceString) assertEquals("!!!", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_intelligent_withoutPunct_shortArticle_withNumerics() { fun name_intelligent_withoutPunct_shortArticle_withNumerics() {
val name = Name.Known.IntelligentFactory.parse("the 1", null) val name = Naming.intelligent().name("the 1", null)
assertEquals("the 1", name.raw) assertEquals("the 1", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("#", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("1", first.collationKey.sourceString) assertEquals("1", first.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, first.type) assertEquals(Token.Type.NUMERIC, first.type)
} }
@Test @Test
fun name_intelligent_spacedPunct_withoutArticle_withoutNumerics() { fun name_intelligent_spacedPunct_withoutArticle_withoutNumerics() {
val name = Name.Known.IntelligentFactory.parse("& Yet & Yet", null) val name = Naming.intelligent().name("& Yet & Yet", null)
assertEquals("& Yet & Yet", name.raw) assertEquals("& Yet & Yet", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("Y", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Yet Yet", first.collationKey.sourceString) assertEquals("Yet Yet", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
} }
@Test @Test
fun name_intelligent_withPunct_withoutArticle_withNumerics() { fun name_intelligent_withPunct_withoutArticle_withNumerics() {
val name = Name.Known.IntelligentFactory.parse("Design : 2 : 3", null) val name = Naming.intelligent().name("Design : 2 : 3", null)
assertEquals("Design : 2 : 3", name.raw) assertEquals("Design : 2 : 3", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("D", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("Design", first.collationKey.sourceString) assertEquals("Design", first.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, first.type) assertEquals(Token.Type.LEXICOGRAPHIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals("2", second.collationKey.sourceString) assertEquals("2", second.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, second.type) assertEquals(Token.Type.NUMERIC, second.type)
val third = name.sortTokens[2] val third = name.tokens[2]
assertEquals(" ", third.collationKey.sourceString) assertEquals(" ", third.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, third.type) assertEquals(Token.Type.LEXICOGRAPHIC, third.type)
val fourth = name.sortTokens[3] val fourth = name.tokens[3]
assertEquals("3", fourth.collationKey.sourceString) assertEquals("3", fourth.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, fourth.type) assertEquals(Token.Type.NUMERIC, fourth.type)
} }
@Test @Test
fun name_intelligent_oopsAllPunct_withoutArticle_oopsAllNumerics() { fun name_intelligent_oopsAllPunct_withoutArticle_oopsAllNumerics() {
val name = Name.Known.IntelligentFactory.parse("2 + 2 = 5", null) val name = Naming.intelligent().name("2 + 2 = 5", null)
assertEquals("2 + 2 = 5", name.raw) assertEquals("2 + 2 = 5", name.raw)
assertEquals(null, name.sort) assertEquals(null, name.sort)
assertEquals("#", name.thumb) val first = name.tokens[0]
val first = name.sortTokens[0]
assertEquals("2", first.collationKey.sourceString) assertEquals("2", first.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, first.type) assertEquals(Token.Type.NUMERIC, first.type)
val second = name.sortTokens[1] val second = name.tokens[1]
assertEquals(" ", second.collationKey.sourceString) assertEquals(" ", second.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, second.type) assertEquals(Token.Type.LEXICOGRAPHIC, second.type)
val third = name.sortTokens[2] val third = name.tokens[2]
assertEquals("2", third.collationKey.sourceString) assertEquals("2", third.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, third.type) assertEquals(Token.Type.NUMERIC, third.type)
val fourth = name.sortTokens[3] val fourth = name.tokens[3]
assertEquals(" ", fourth.collationKey.sourceString) assertEquals(" ", fourth.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, fourth.type) assertEquals(Token.Type.LEXICOGRAPHIC, fourth.type)
val fifth = name.sortTokens[4] val fifth = name.tokens[4]
assertEquals("5", fifth.collationKey.sourceString) assertEquals("5", fifth.collationKey.sourceString)
assertEquals(Token.Type.NUMERIC, fifth.type) assertEquals(Token.Type.NUMERIC, fifth.type)
} }
@Test @Test
fun name_intelligent_withSort() { fun name_intelligent_withSort() {
val name = Name.Known.IntelligentFactory.parse("The Smile", "Smile") val name = Naming.intelligent().name("The Smile", "Smile")
assertEquals("The Smile", name.raw) assertEquals("The Smile", name.raw)
assertEquals("Smile", name.sort) assertEquals("Smile", name.sort)
assertEquals("S", name.thumb) val only = name.tokens.single()
val only = name.sortTokens.single()
assertEquals("Smile", only.collationKey.sourceString) assertEquals("Smile", only.collationKey.sourceString)
assertEquals(Token.Type.LEXICOGRAPHIC, only.type) assertEquals(Token.Type.LEXICOGRAPHIC, only.type)
} }
@Test @Test
fun name_equals_simple() { fun name_equals_simple() {
val a = Name.Known.SimpleFactory.parse("The Same", "Same") val a = Naming.simple().name("The Same", "Same")
val b = Name.Known.SimpleFactory.parse("The Same", "Same") val b = Naming.simple().name("The Same", "Same")
assertEquals(a, b) assertEquals(a, b)
} }
@Test @Test
fun name_equals_differentSort() { fun name_equals_differentSort() {
val a = Name.Known.SimpleFactory.parse("The Same", "Same") val a = Naming.simple().name("The Same", "Same")
val b = Name.Known.SimpleFactory.parse("The Same", null) val b = Naming.simple().name("The Same", null)
assertNotEquals(a, b) assertNotEquals(a, b)
assertNotEquals(a.hashCode(), b.hashCode()) assertNotEquals(a.hashCode(), b.hashCode())
} }
@Test @Test
fun name_equals_intelligent_differentTokens() { fun name_equals_intelligent_differentTokens() {
val a = Name.Known.IntelligentFactory.parse("The Same", "Same") val a = Naming.intelligent().name("The Same", "Same")
val b = Name.Known.IntelligentFactory.parse("Same", "Same") val b = Naming.intelligent().name("Same", "Same")
assertNotEquals(a, b) assertNotEquals(a, b)
assertNotEquals(a.hashCode(), b.hashCode()) assertNotEquals(a.hashCode(), b.hashCode())
} }
@Test @Test
fun name_compareTo_simple_withoutSort_withoutArticle_withoutNumeric() { fun name_compareTo_simple_withoutSort_withoutArticle_withoutNumeric() {
val a = Name.Known.SimpleFactory.parse("A", null) val a = Naming.simple().name("A", null)
val b = Name.Known.SimpleFactory.parse("B", null) val b = Naming.simple().name("B", null)
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
} }
@Test @Test
fun name_compareTo_simple_withoutSort_withArticle_withoutNumeric() { fun name_compareTo_simple_withoutSort_withArticle_withoutNumeric() {
val a = Name.Known.SimpleFactory.parse("A Brain in a Bottle", null) val a = Naming.simple().name("A Brain in a Bottle", null)
val b = Name.Known.SimpleFactory.parse("Acid Rain", null) val b = Naming.simple().name("Acid Rain", null)
val c = Name.Known.SimpleFactory.parse("Boralis / Contrastellar", null) val c = Naming.simple().name("Boralis / Contrastellar", null)
val d = Name.Known.SimpleFactory.parse("Breathe In", null) val d = Naming.simple().name("Breathe In", null)
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
assertEquals(-1, a.compareTo(c)) assertEquals(-1, a.compareTo(c))
assertEquals(-1, a.compareTo(d)) assertEquals(-1, a.compareTo(d))
@ -359,40 +339,40 @@ class NameTest {
@Test @Test
fun name_compareTo_simple_withSort_withoutArticle_withNumeric() { fun name_compareTo_simple_withSort_withoutArticle_withNumeric() {
val a = Name.Known.SimpleFactory.parse("15 Step", null) val a = Naming.simple().name("15 Step", null)
val b = Name.Known.SimpleFactory.parse("128 Harps", null) val b = Naming.simple().name("128 Harps", null)
val c = Name.Known.SimpleFactory.parse("1969", null) val c = Naming.simple().name("1969", null)
assertEquals(1, a.compareTo(b)) assertEquals(1, a.compareTo(b))
assertEquals(-1, a.compareTo(c)) assertEquals(-1, a.compareTo(c))
} }
@Test @Test
fun name_compareTo_simple_withPartialSort() { fun name_compareTo_simple_withPartialSort() {
val a = Name.Known.SimpleFactory.parse("A", "C") val a = Naming.simple().name("A", "C")
val b = Name.Known.SimpleFactory.parse("B", null) val b = Naming.simple().name("B", null)
assertEquals(1, a.compareTo(b)) assertEquals(1, a.compareTo(b))
} }
@Test @Test
fun name_compareTo_simple_withSort() { fun name_compareTo_simple_withSort() {
val a = Name.Known.SimpleFactory.parse("D", "A") val a = Naming.simple().name("D", "A")
val b = Name.Known.SimpleFactory.parse("C", "B") val b = Naming.simple().name("C", "B")
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
} }
@Test @Test
fun name_compareTo_intelligent_withoutSort_withoutArticle_withoutNumeric() { fun name_compareTo_intelligent_withoutSort_withoutArticle_withoutNumeric() {
val a = Name.Known.IntelligentFactory.parse("A", null) val a = Naming.intelligent().name("A", null)
val b = Name.Known.IntelligentFactory.parse("B", null) val b = Naming.intelligent().name("B", null)
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
} }
@Test @Test
fun name_compareTo_intelligent_withoutSort_withArticle_withoutNumeric() { fun name_compareTo_intelligent_withoutSort_withArticle_withoutNumeric() {
val a = Name.Known.IntelligentFactory.parse("A Brain in a Bottle", null) val a = Naming.intelligent().name("A Brain in a Bottle", null)
val b = Name.Known.IntelligentFactory.parse("Acid Rain", null) val b = Naming.intelligent().name("Acid Rain", null)
val c = Name.Known.IntelligentFactory.parse("Boralis / Contrastellar", null) val c = Naming.intelligent().name("Boralis / Contrastellar", null)
val d = Name.Known.IntelligentFactory.parse("Breathe In", null) val d = Naming.intelligent().name("Breathe In", null)
assertEquals(1, a.compareTo(b)) assertEquals(1, a.compareTo(b))
assertEquals(1, a.compareTo(c)) assertEquals(1, a.compareTo(c))
assertEquals(-1, a.compareTo(d)) assertEquals(-1, a.compareTo(d))
@ -400,9 +380,9 @@ class NameTest {
@Test @Test
fun name_compareTo_intelligent_withoutSort_withoutArticle_withNumeric() { fun name_compareTo_intelligent_withoutSort_withoutArticle_withNumeric() {
val a = Name.Known.IntelligentFactory.parse("15 Step", null) val a = Naming.intelligent().name("15 Step", null)
val b = Name.Known.IntelligentFactory.parse("128 Harps", null) val b = Naming.intelligent().name("128 Harps", null)
val c = Name.Known.IntelligentFactory.parse("1969", null) val c = Naming.intelligent().name("1969", null)
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
assertEquals(-1, b.compareTo(c)) assertEquals(-1, b.compareTo(c))
assertEquals(-2, a.compareTo(c)) assertEquals(-2, a.compareTo(c))
@ -410,28 +390,22 @@ class NameTest {
@Test @Test
fun name_compareTo_intelligent_withPartialSort_withoutArticle_withoutNumeric() { fun name_compareTo_intelligent_withPartialSort_withoutArticle_withoutNumeric() {
val a = Name.Known.SimpleFactory.parse("A", "C") val a = Naming.simple().name("A", "C")
val b = Name.Known.SimpleFactory.parse("B", null) val b = Naming.simple().name("B", null)
assertEquals(1, a.compareTo(b)) assertEquals(1, a.compareTo(b))
} }
@Test @Test
fun name_compareTo_intelligent_withSort_withoutArticle_withoutNumeric() { fun name_compareTo_intelligent_withSort_withoutArticle_withoutNumeric() {
val a = Name.Known.IntelligentFactory.parse("D", "A") val a = Naming.intelligent().name("D", "A")
val b = Name.Known.IntelligentFactory.parse("C", "B") val b = Naming.intelligent().name("C", "B")
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
} }
@Test
fun name_unknown() {
val a = Name.Unknown(0)
assertEquals("?", a.thumb)
}
@Test @Test
fun name_compareTo_mixed() { fun name_compareTo_mixed() {
val a = Name.Unknown(0) val a = Name.Unknown(Placeholder.ALBUM)
val b = Name.Known.IntelligentFactory.parse("A", null) val b = Naming.intelligent().name("A", null)
assertEquals(-1, a.compareTo(b)) assertEquals(-1, a.compareTo(b))
} }
} }

View file

@ -23,7 +23,7 @@ import org.junit.Test
import org.oxycblt.musikr.tag.util.correctWhitespace import org.oxycblt.musikr.tag.util.correctWhitespace
import org.oxycblt.musikr.tag.util.parseId3GenreNames import org.oxycblt.musikr.tag.util.parseId3GenreNames
import org.oxycblt.musikr.tag.util.parseId3v2PositionField import org.oxycblt.musikr.tag.util.parseId3v2PositionField
import org.oxycblt.musikr.tag.util.parseVorbisPositionField import org.oxycblt.musikr.tag.util.parseXiphPositionField
import org.oxycblt.musikr.tag.util.splitEscaped import org.oxycblt.musikr.tag.util.splitEscaped
class TagUtilTest { class TagUtilTest {
@ -97,20 +97,20 @@ class TagUtilTest {
@Test @Test
fun parseVorbisPositionField_correct() { fun parseVorbisPositionField_correct() {
assertEquals(16, parseVorbisPositionField("16", "32")) assertEquals(16, parseXiphPositionField("16", "32"))
assertEquals(16, parseVorbisPositionField("16", null)) assertEquals(16, parseXiphPositionField("16", null))
} }
@Test @Test
fun parseVorbisPositionField_zeroed() { fun parseVorbisPositionField_zeroed() {
assertEquals(null, parseVorbisPositionField("0", null)) assertEquals(null, parseXiphPositionField("0", null))
assertEquals(0, parseVorbisPositionField("0", "32")) assertEquals(0, parseXiphPositionField("0", "32"))
} }
@Test @Test
fun parseVorbisPositionField_wack() { fun parseVorbisPositionField_wack() {
assertEquals(null, parseVorbisPositionField("a", null)) assertEquals(null, parseXiphPositionField("a", null))
assertEquals(null, parseVorbisPositionField("a", "b")) assertEquals(null, parseXiphPositionField("a", "b"))
} }
@Test @Test