import unittest

from clippings.parser import Document


class DocumentTest(unittest.TestCase):

    def test_create_document(self):
        title = 'Haunted'
        authors = ['Chuck Palahniuk']
        document = Document(title, authors)

        self.assertEqual(title, document.title)
        self.assertEqual(authors, document.authors)

    def test_parse_document_with_single_author(self):
        document_line = '1984 (George Orwell)'
        document = Document.parse(document_line)

        expected_authors = ['George Orwell']
        self.assertEqual(expected_authors, document.authors)

        expected_title = '1984'
        self.assertEqual(expected_title, document.title)

    def test_parse_document_with_multiple_authors(self):
        document_line = 'Java Concurrency in Practice (Joshua Bloch;Brian Goetz)'
        document = Document.parse(document_line)

        expected_authors = [
            'Joshua Bloch',
            'Brian Goetz',
        ]
        self.assertEqual(expected_authors, document.authors)

        expected_title = 'Java Concurrency in Practice'
        self.assertEqual(expected_title, document.title)

    def test_document_to_string(self):
        title = 'Also sprach Zarathustra'
        authors = ['Friedrich Nietzsche']
        document = Document(title, authors)

        expected_string = 'Also sprach Zarathustra (Friedrich Nietzsche)'
        self.assertEqual(expected_string, str(document))

    def test_document_to_dict(self):
        title = 'À la recherche du temps perdu'
        authors = ['Marcel Proust']
        document = Document(title, authors)

        expected_dict = {
            'title': title,
            'authors': authors
        }
        self.assertEqual(expected_dict, document.to_dict())

@@ -48,16 +48,54 @@
 ocument%0A
+from clippings.parser import Location%0A
 %0A%0Aclass 
@@ -1802,8 +1802,1652 @@
 dict())%0A
+%0A%0Aclass LocationTest(unittest.TestCase):%0A%0A    BEGIN = 666%0A    END = 1337%0A    SINGLE_LOCATION_STRING = '666'%0A    RANGE_LOCATION_STRING = '666-1337'%0A%0A    def test_create_location(self):%0A        location = Location(self.BEGIN, self.END)%0A        self.assertEqual(self.BEGIN, location.begin)%0A        self.assertEqual(self.END, location.end)%0A%0A    def test_parse_range_location(self):%0A        location_string = self.RANGE_LOCATION_STRING%0A        location = Location.parse(location_string)%0A        self.assertTrue(isinstance(location.begin, int))%0A        self.assertTrue(isinstance(location.end, int))%0A        self.assertEqual(self.BEGIN, location.begin)%0A        self.assertEqual(self.END, location.end)%0A%0A    def test_parse_single_location(self):%0A        location_string = self.SINGLE_LOCATION_STRING%0A        location = Location.parse(location_string)%0A        self.assertTrue(isinstance(location.begin, int))%0A        self.assertTrue(isinstance(location.end, int))%0A        self.assertEqual(self.BEGIN, location.begin)%0A        self.assertEqual(self.BEGIN, location.end)%0A%0A    def test_location_to_dict(self):%0A        location = Location(self.BEGIN, self.END)%0A        expected_dictionary = %7B%0A            'begin': self.BEGIN,%0A            'end': self.END,%0A        %7D%0A        self.assertEqual(expected_dictionary, location.to_dict())%0A%0A    def test_range_location_to_str(self):%0A        location = Location(self.BEGIN, self.BEGIN)%0A        self.assertEqual(self.SINGLE_LOCATION_STRING, str(location))%0A%0A    def test_single_location_to_str(self):%0A        location = Location(self.BEGIN, self.END)%0A        self.assertEqual(self.RANGE_LOCATION_STRING, str(location))%0A

Add tests for the Location class