# -*- coding: utf-8 -*-

import codecs
import os

from mountain.join import expand_manifest
from mountain.split import split_combined_document


class TestExpandManifest(object):

    def test_expand_manifest_simple(self):

        actual = expand_manifest(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "fixtures",
                "simple",
                "manifest.fountain"),
            "test-path")

        expected_contents = codecs.open(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "fixtures",
                "simple",
                "screenplay.fountain"),
            "r",
            "utf-8"
        ).read()

        expected = [{"path": "test-path", "contents": expected_contents}]

        assert actual == expected

    def test_expand_manifest_complex(self):

        actual = expand_manifest(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "fixtures",
                "complex",
                "manifest.fountain"),
            "test-path")

        expected_contents = codecs.open(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "fixtures",
                "complex",
                "screenplay.fountain"),
            "r",
            "utf-8"
        ).read()

        expected = [{"path": "test-path", "contents": expected_contents}]

        assert actual == expected


class TestSplitCombinedDocument(object):

    def test_split_combined_document(self):

        actual = split_combined_document(
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "fixtures",
                "simple",
                "manifest.fountain"),
            os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "fixtures",
                "simple",
                "screenplay.fountain"))

        expected = list()

        for path in ["fixtures/simple/intro.fountain",
                     "fixtures/simple/inciting-incident.fountain",
                     "fixtures/simple/the-end.fountain",
                     "fixtures/simple/manifest.fountain"]:

            path = os.path.join(
                       os.path.dirname(os.path.realpath(__file__)),
                       path)

            expected.append(
                {"path": path,
                 "contents": codecs.open(path, "r", "utf-8").read()})

        assert actual == expected

@@ -209,32 +209,218 @@
 _simple(self):%0A%0A
+        combined_document_path = os.path.join(%0A            os.path.dirname(os.path.realpath(__file__)),%0A            %22fixtures%22,%0A            %22simple%22,%0A            %22screenplay.fountain%22)%0A%0A
         actual =
@@ -624,35 +624,46 @@
             
-%22test-
+combined_document_
 path
-%22
 )%0A%0A        e
@@ -710,175 +710,30 @@
     
-os.path.join(%0A                os.path.dirname(os.path.realpath(__file__)),%0A                %22fixtures%22,%0A                %22simple%22,%0A                %22screenplay.fountain%22)
+combined_document_path
 ,%0A  
@@ -810,35 +810,46 @@
 = %5B%7B%22path%22: 
-%22test-
+combined_document_
 path
-%22
 , %22contents%22
@@ -943,32 +943,219 @@
 complex(self):%0A%0A
+        combined_document_path = os.path.join(%0A            os.path.dirname(os.path.realpath(__file__)),%0A            %22fixtures%22,%0A            %22complex%22,%0A            %22screenplay.fountain%22)%0A%0A
         actual =
@@ -1364,27 +1364,38 @@
         
-%22test-
+combined_document_
 path
-%22
 )%0A%0A     
@@ -1700,19 +1700,30 @@
 h%22: 
-%22test-
+combined_document_
 path
-%22
 , %22c

Fix failing tests.