1# Copyright 2007 Javier Kohen 2# 2010, 2014 Nick Boultbee 3# 4# This program is free software; you can redistribute it and/or modify 5# it under the terms of the GNU General Public License as published by 6# the Free Software Foundation; either version 2 of the License, or 7# (at your option) any later version. 8 9from tests import TestCase 10 11from quodlibet.util import title 12from quodlibet.util.string.titlecase import human_title as ht 13 14 15class Ttitle(TestCase): 16 17 def test_basics(s): 18 s.assertEquals(u"Mama's Boy", title(u"mama's boy")) 19 s.assertEquals(u"The A-Sides", title(u"the a-sides")) 20 s.assertEquals(u"Hello Goodbye", title(u"hello goodbye")) 21 s.assertEquals(u"HELLO GOODBYE", title(u"HELLO GOODBYE")) 22 s.assertEquals(u"", title(u"")) 23 24 def test_extra_spaces(s): 25 s.assertEquals(u" Space", title(u" space")) 26 s.assertEquals(u" Dodgy Spaces ", title(u" dodgy spaces ")) 27 28 def test_quirks(s): 29 # This character is not an apostrophe, it's a single quote! 30 s.assertEquals(u"Mama’S Boy", title(u"mama’s boy")) 31 # This is actually an accent character, not an apostrophe either. 32 s.assertEquals(u"Mama`S Boy", title(u"mama`s boy")) 33 34 def test_quotes(s): 35 s.assertEquals(u"Hello Goodbye (A Song)", 36 title(u"hello goodbye (a song)")) 37 s.assertEquals(u"Hello Goodbye 'A Song'", 38 title(u"hello goodbye 'a song'")) 39 s.assertEquals(u'Hello Goodbye "A Song"', 40 title(u'hello goodbye "a song"')) 41 s.assertEquals(u"Hello Goodbye „A Song”", 42 title(u"hello goodbye „a song”")) 43 s.assertEquals(u"Hello Goodbye ‘A Song’", 44 title(u"hello goodbye ‘a song’")) 45 s.assertEquals(u"Hello Goodbye “A Song”", 46 title(u"hello goodbye “a song”")) 47 s.assertEquals(u"Hello Goodbye »A Song«", 48 title(u"hello goodbye »a song«")) 49 s.assertEquals(u"Hello Goodbye «A Song»", 50 title(u"hello goodbye «a song»")) 51 s.assertEquals(u"\"24\" Theme", 52 title(u"\"24\" theme")) 53 s.assertEquals(u"\"Mad-Dog\" Mike", 54 title(u"\"mad-dog\" mike")) 55 56 def test_unicode(s): 57 s.assertEquals(u"Fooäbar", 58 title(u"fooäbar")) 59 s.assertEquals(u"Los Años Felices", 60 title(u"los años felices")) 61 s.assertEquals(u"Ñandú", 62 title(u"ñandú")) 63 s.assertEquals(u"Österreich", 64 title(u"österreich")) 65 # Not a real word - there is none with this character at the beginning 66 # but still Python doesn't capitalize the es-zed properly. 67 # s.assertEquals(u"SSbahn", title(u"ßbahn")) 68 69 # Old tests, somewhat redundant with the above, but you can never have 70 # too many tests... 71 72 def test_empty(self): 73 self.failUnlessEqual(title(""), "") 74 75 def test_oneword(self): 76 self.failUnlessEqual(title("foobar"), "Foobar") 77 78 def test_twowords(self): 79 self.failUnlessEqual(title("foo bar"), "Foo Bar") 80 81 def test_preserve(self): 82 self.failUnlessEqual(title("fooBar"), "FooBar") 83 84 def test_nonalphabet(self): 85 self.failUnlessEqual(title("foo 1bar"), "Foo 1bar") 86 87 def test_two_words_and_one_not(self): 88 self.failUnlessEqual(title("foo 1 bar"), "Foo 1 Bar") 89 90 def test_apostrophe(self): 91 self.failUnlessEqual(title("it's"), "It's") 92 93 def test_english_human_title_case(s): 94 s.assertEquals(u"System of a Down", ht(u"System Of A Down")) 95 s.assertEquals(u"The Man with the Golden Gun", 96 ht(u"The Man With The Golden gun")) 97 s.assertEquals(u"Live and Let Die", ht(u"Live And Let Die")) 98 # Updated to match modifications to is/are/am rules: 99 s.assertEquals(u"The Vitamins Are in My Fresh California Raisins", 100 ht(u"the vitamins are in my fresh california raisins")) 101 s.assertEquals(u"Dig In", 102 ht(u"dig in")) 103 s.assertEquals(u"In da Club", 104 ht(u"in da club")) 105 # See Issue 616 106 s.assertEquals(u" Dodgy Are the Spaces ", 107 ht(u" dodgy are the spaces ")) 108 s.assertEquals(u"Space: The Final Frontier", 109 ht(u"Space: the final frontier")) 110 s.assertEquals(u"- Out of Space", ht(u"- out Of space")) 111 112 def test_tricky_apostrophes(s): 113 s.assertEquals(u"Guns 'n' Roses", ht(u"Guns 'n' roses")) 114 s.assertEquals(u"Scarlett O'Hara", ht(u"scarlett o'hara")) 115 s.assertEquals(u"Scarlett O'Hara", ht(u"Scarlett O'hara")) 116 s.assertEquals(u"No Life 'til Leather", ht(u"no life 'til leather")) 117 118 def test_english_humanise_sentences(s): 119 """Checks trickier human title casing""" 120 s.assertEquals(u"Buffy the Vampire Slayer: The Album", 121 ht(u"Buffy the vampire slayer: the album")) 122 s.assertEquals(u"Killing Is My Business... and Business Is Good!", 123 ht(u"Killing is my business... And business is good!")) 124 s.assertEquals(u"Herbie Hancock - The Definitive", 125 ht(u"herbie hancock - the definitive")) 126