Ejemplo n.º 1
0
 def testUpdateCharMeta(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     doc.updateCharMeta( (1, 3), { "foo" : ["a", "a"],
                                   "bar" : ['b', None, 'b'],
                                 }
                       )
Ejemplo n.º 2
0
    def testSaveUnnamed(self):
        doc = TextDocument()
        self.assertRaises(TextDocument.MissingFilenameException, lambda: doc.save())

        path = fixtures.tempFile("testSaveUnnamed")
        doc.saveAs(path)
        self.assertTrue(os.path.exists(path))
        self.assertEqual(doc.filename(), path)
Ejemplo n.º 3
0
    def testDocumentMeta(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)
        doc.createDocumentMetaInfo("Hello")
        self.assertEqual(doc.documentMetaInfo("Hello").data(), None)

        doc.createDocumentMetaInfo("Hello2", 2)
        self.assertEqual(doc.documentMetaInfo("Hello2").data(), 2)
Ejemplo n.º 4
0
    def testDeleteLineMeta(self):
        doc = TextDocument()
        doc.open(fixtures.get("basic_nonempty_file.txt"))
        doc.updateLineMeta(1, {"hello": 5})
        self.assertEqual(doc.lineMeta(1)["hello"], 5)

        doc.deleteLineMeta(1, ["hello"])
        self.assertNotIn("hello", doc.lineMeta(1))

        self.assertRaises(IndexError, lambda : doc.deleteLineMeta(20, "hello"))
Ejemplo n.º 5
0
 def testDeleteDocumentMeta(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     doc.updateDocumentMeta({"Hello": 5})
     self.assertEqual(doc.documentMeta()["Hello"], 5)
     doc.deleteDocumentMeta("Hello")
     self.assertNotIn("Hello", doc.documentMeta())
Ejemplo n.º 6
0
    def testLineLength(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)
        self.assertEqual(doc.lineLength(1), 6)
        self.assertEqual(doc.lineLength(2), 13)

        doc = TextDocument()
        with open(fixtures.get("empty_file.txt"), 'r') as f:
            doc.read(f)
        self.assertEqual(doc.lineLength(1), 1)
Ejemplo n.º 7
0
    def testReplaceChars(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)
        doc.replaceChars((1, 3), 1, "hello")

        self.assertEqual(doc.lineText(1), 'hehellolo\n')

        doc.replaceChars((1, 1), 1, "c")

        self.assertEqual(doc.lineText(1), 'cehellolo\n')
Ejemplo n.º 8
0
 def testSameObject(self):
     doc = TextDocument()
     doc.createLineMetaInfo("whatever")
     doc.createLineMetaInfo("whatever2")
     self.assertEqual(doc.lineMetaInfo("whatever"),
                      doc.lineMetaInfo("whatever"))
     self.assertNotEqual(doc.lineMetaInfo("whatever"),
                         doc.lineMetaInfo("whatever2"))
Ejemplo n.º 9
0
    def testBasic(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        meta_info = doc.lineMetaInfo("whatever")

        self.assertEqual(meta_info.document, doc)
        self.assertEqual(meta_info.meta_type, "whatever")
        self.assertEqual(meta_info.numLines(), 1)
        self.assertEqual(meta_info.data(1), None)

        meta_info.setData("hello", 1)
        self.assertEqual(meta_info.data(1), "hello")
Ejemplo n.º 10
0
    def testBasic(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        meta_info = doc.lineMetaInfo("whatever")

        self.assertEqual(meta_info.document, doc)
        self.assertEqual(meta_info.meta_type, "whatever")
        self.assertEqual(meta_info.numLines(), 1)
        self.assertEqual(meta_info.data(1), None)

        meta_info.setData("hello",1)
        self.assertEqual(meta_info.data(1), "hello")
Ejemplo n.º 11
0
 def testCharMeta(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.updateCharMeta((1, 1), {"Hello": [1]})
     self.assertEqual(len(doc.charMeta((1, 1))["Hello"]),
                      len(doc.lineText(1)))
     self.assertEqual(
         doc.charMeta((1, 1))["Hello"], [1, None, None, None, None, None])
Ejemplo n.º 12
0
    def testDocumentMeta(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)
        doc.createDocumentMetaInfo("Hello")
        self.assertEqual(doc.documentMetaInfo("Hello").data(), None)

        doc.createDocumentMetaInfo("Hello2", 2)
        self.assertEqual(doc.documentMetaInfo("Hello2").data(), 2)
Ejemplo n.º 13
0
    def testIsEmpty(self):
        doc = TextDocument()

        self.assertTrue(doc.isEmpty())
        doc.insertLine(1, "hello")

        self.assertFalse(doc.isEmpty())

        doc.deleteLine(1)
        self.assertTrue(doc.isEmpty())
Ejemplo n.º 14
0
    def testReplaceChars(self):
        doc = TextDocument()
        doc.open(fixtures.get("basic_nonempty_file.txt"))
        doc.replaceChars( (1,3), 1, "hello")

        self.assertEqual(doc.lineText(1), 'hehellolo\n')

        doc.replaceChars( (1,1), 1, "c")

        self.assertEqual(doc.lineText(1), 'cehellolo\n')
Ejemplo n.º 15
0
 def testCharMeta(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.updateCharMeta((1, 1), {"Hello": [1]})
     self.assertEqual(len(doc.charMeta((1, 1))["Hello"]), len(doc.lineText(1)))
     self.assertEqual(doc.charMeta((1, 1))["Hello"], [1, None, None, None, None, None])
Ejemplo n.º 16
0
    def testSetDataForLines(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        doc.insertLine(1, "hello")
        doc.insertLine(1, "hello")
        doc.insertLine(1, "hello")
        meta_info = doc.lineMetaInfo("whatever")

        meta_info.setDataForLines({2: "damn"})

        self.assertEqual(meta_info.data(), [None, "damn", None, None])
Ejemplo n.º 17
0
    def testReplaceChars(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)
        doc.replaceChars((1, 3), 1, "hello")

        self.assertEqual(doc.lineText(1), "hehellolo\n")

        doc.replaceChars((1, 1), 1, "c")

        self.assertEqual(doc.lineText(1), "cehellolo\n")
Ejemplo n.º 18
0
 def testLastModified(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     last_modified = doc.lastModified()
     self.assertEqual(doc.lastModified(), last_modified)
     time.sleep(0.1)
     doc.insertLine(1,"")
     self.assertNotEqual(doc.lastModified(), last_modified)
Ejemplo n.º 19
0
 def testJoinWithNextLine2(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     doc.joinWithNextLine(2)
     self.assertEqual(doc.lineText(1), 'hello\n')
     self.assertEqual(doc.lineText(2), 'how are you?\n')
     self.assertEqual(doc.numLines(), 2)
     self.assertFalse(doc.isModified())
Ejemplo n.º 20
0
    def testUpdateLineMeta(self):
        doc = TextDocument()
        doc.open(fixtures.get("basic_nonempty_file.txt"))
        doc.updateLineMeta(1, {"hello": 5})
        self.assertEqual(type(doc.lineMeta(1)), dict)
        self.assertEqual(doc.lineMeta(1)["hello"], 5)

        self.assertRaises(IndexError, lambda : doc.updateLineMeta(20, {}))
Ejemplo n.º 21
0
 def testJoinWithNextLine2(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.joinWithNextLine(2)
     self.assertEqual(doc.lineText(1), 'hello\n')
     self.assertEqual(doc.lineText(2), 'how are you?\n')
     self.assertEqual(doc.numLines(), 2)
Ejemplo n.º 22
0
    def testInitFromNonEmptyFile(self):
        doc = TextDocument()
        doc.open(fixtures.get("basic_nonempty_file.txt"))

        self.assertFalse(doc.isEmpty())
        self.assertEqual(doc.filename(), fixtures.get("basic_nonempty_file.txt"))
        self.assertFalse(doc.isModified())
        self.assertEqual(doc.numLines(), 2)
        self.assertEqual(doc.documentText(), 'hello\nhow are you?\n')
Ejemplo n.º 23
0
    def testInitFromEmptyFile(self):
        doc = TextDocument()
        doc.open(fixtures.get("empty_file.txt"))

        self.assertTrue(doc.isEmpty())
        self.assertEqual(doc.filename(), fixtures.get("empty_file.txt"))
        self.assertFalse(doc.isModified())
        self.assertEqual(doc.numLines(), 1)
        self.assertEqual(doc.documentText(), '\n')
Ejemplo n.º 24
0
    def testLineLength(self):
        doc = TextDocument()
        doc.open(fixtures.get("basic_nonempty_file.txt"))
        self.assertEqual(doc.lineLength(1), 6)
        self.assertEqual(doc.lineLength(2), 13)

        doc = TextDocument()
        doc.open(fixtures.get("empty_file.txt"))
        self.assertEqual(doc.lineLength(1), 1)
Ejemplo n.º 25
0
    def testIsEmpty(self):
        doc = TextDocument()

        self.assertTrue(doc.isEmpty())
        doc.insertLine(1, "hello")

        self.assertFalse(doc.isEmpty())

        doc.deleteLine(1)
        self.assertTrue(doc.isEmpty())
Ejemplo n.º 26
0
 def testBreakLine(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.breakLine((1, 3))
     self.assertEqual(doc.lineText(1), "he\n")
     self.assertEqual(doc.lineText(2), "llo\n")
Ejemplo n.º 27
0
    def testSetDataForLines(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        doc.insertLine(1, "hello")
        doc.insertLine(1, "hello")
        doc.insertLine(1, "hello")
        meta_info = doc.lineMetaInfo("whatever")

        meta_info.setDataForLines({2: "damn"})

        self.assertEqual(meta_info.data(), [None, "damn", None, None])
Ejemplo n.º 28
0
 def testJoinWithNextLine2(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.joinWithNextLine(2)
     self.assertEqual(doc.lineText(1), "hello\n")
     self.assertEqual(doc.lineText(2), "how are you?\n")
     self.assertEqual(doc.numLines(), 2)
Ejemplo n.º 29
0
    def testInitFromNonEmptyFile(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)

        self.assertFalse(doc.isEmpty())
        self.assertEqual(doc.numLines(), 2)
        self.assertEqual(doc.documentText(), 'hello\nhow are you?\n')
Ejemplo n.º 30
0
    def testInitFromEmptyFile(self):
        doc = TextDocument()
        with open(fixtures.get("empty_file.txt"), "r") as f:
            doc.read(f)

        self.assertTrue(doc.isEmpty())
        self.assertEqual(doc.numLines(), 1)
        self.assertEqual(doc.documentText(), '\n')
Ejemplo n.º 31
0
 def testBreakLine(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
         doc.read(f)
     doc.breakLine((1, 3))
     self.assertEqual(doc.lineText(1), "he\n")
     self.assertEqual(doc.lineText(2), "llo\n")
Ejemplo n.º 32
0
    def testLine(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)

        self.assertEqual(doc.lineText(1), 'hello\n')
        self.assertEqual(doc.lineText(2), 'how are you?\n')

        self.assertRaises(IndexError, lambda: doc.lineText(-1))
        self.assertRaises(IndexError, lambda: doc.lineText(0))
        self.assertRaises(IndexError, lambda: doc.lineText(5))
Ejemplo n.º 33
0
 def testUpdateCharMeta(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.updateCharMeta((1, 3), {
         "foo": ["a", "a"],
         "bar": ['b', None, 'b'],
     })
Ejemplo n.º 34
0
    def testInitEmpty(self):
        doc = TextDocument()

        self.assertTrue(doc.isEmpty())
        self.assertEqual(doc.filename(), None)
        self.assertFalse(doc.isModified())
        self.assertEqual(doc.numLines(), 1)
        self.assertEqual(doc.documentText(), '\n')
Ejemplo n.º 35
0
    def testInitFromEmptyFile(self):
        doc = TextDocument()
        with open(fixtures.get("empty_file.txt"), "r") as f:
            doc.read(f)

        self.assertTrue(doc.isEmpty())
        self.assertEqual(doc.numLines(), 1)
        self.assertEqual(doc.documentText(), "\n")
Ejemplo n.º 36
0
    def testInitFromNonEmptyFile(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)

        self.assertFalse(doc.isEmpty())
        self.assertEqual(doc.numLines(), 2)
        self.assertEqual(doc.documentText(), "hello\nhow are you?\n")
Ejemplo n.º 37
0
    def testLine(self):
        doc = TextDocument()
        doc.open(fixtures.get("basic_nonempty_file.txt"))
        self.assertEqual(doc.lineText(1), 'hello\n')
        self.assertEqual(doc.lineText(2), 'how are you?\n')

        self.assertRaises(IndexError, lambda : doc.lineText(-1))
        self.assertRaises(IndexError, lambda : doc.lineText(0))
        self.assertRaises(IndexError, lambda : doc.lineText(5))
Ejemplo n.º 38
0
    def testLine(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), "r") as f:
            doc.read(f)

        self.assertEqual(doc.lineText(1), "hello\n")
        self.assertEqual(doc.lineText(2), "how are you?\n")

        self.assertRaises(IndexError, lambda: doc.lineText(-1))
        self.assertRaises(IndexError, lambda: doc.lineText(0))
        self.assertRaises(IndexError, lambda: doc.lineText(5))
Ejemplo n.º 39
0
 def testReplaceLine(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.replaceLine(1, "babau")
Ejemplo n.º 40
0
    def testInitEmpty(self):
        doc = TextDocument()

        self.assertTrue(doc.isEmpty())
        self.assertEqual(doc.numLines(), 1)
        self.assertEqual(doc.documentText(), '\n')
Ejemplo n.º 41
0
 def testHasLine(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     self.assertTrue(doc.hasLine(1))
     self.assertFalse(doc.hasLine(20))
Ejemplo n.º 42
0
 def testDocumentMeta(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     self.assertEqual(type(doc.documentMeta()), dict)
Ejemplo n.º 43
0
 def createCursor(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.createCursor()
Ejemplo n.º 44
0
 def testInsertChars(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.insertChars((1, 3), "babau")
Ejemplo n.º 45
0
 def testSameObject(self):
     doc = TextDocument()
     doc.createLineMetaInfo("whatever")
     doc.createLineMetaInfo("whatever2")
     self.assertEqual(doc.lineMetaInfo("whatever"), doc.lineMetaInfo("whatever"))
     self.assertNotEqual(doc.lineMetaInfo("whatever"), doc.lineMetaInfo("whatever2"))
Ejemplo n.º 46
0
    def testLineMetaInfoMemento(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")

        meta_info1 = doc.lineMetaInfo("whatever")
        meta_info2 = doc.lineMetaInfo("whatever2")
        doc.newLineAfter(1)
        doc.newLine(1)

        meta_info1.setData("hello", 1)
        meta_info2.setData("byebye", 1)

        memento = doc.lineMemento(1)

        doc.deleteLine(1)
        self.assertEqual(doc.lineMetaInfo("whatever").data(1), None)
        self.assertEqual(doc.lineMetaInfo("whatever2").data(1), None)

        doc.insertFromMemento(1, memento)
        self.assertEqual(doc.lineText(1), '\n')
        self.assertEqual(doc.lineMetaInfo("whatever").data(1), 'hello')
        self.assertEqual(doc.lineMetaInfo("whatever2").data(1), 'byebye')
Ejemplo n.º 47
0
 def testInsertLines(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     doc.insertLines(2, ['foo', 'bar'])
     self.assertEqual(doc.numLines(), 4)
Ejemplo n.º 48
0
 def testUpdateDocumentMeta(self):
     doc = TextDocument()
     doc.open(fixtures.get("basic_nonempty_file.txt"))
     doc.updateDocumentMeta({"Hello": 5})
     self.assertEqual(type(doc.documentMeta()), dict)
     self.assertEqual(doc.documentMeta()["Hello"], 5)
Ejemplo n.º 49
0
 def testInsertLines(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     doc.insertLines(2, ['foo', 'bar'])
     self.assertEqual(doc.numLines(), 4)
Ejemplo n.º 50
0
 def testDeleteLines(self):
     doc = TextDocument()
     with open(fixtures.get("bigfile.py"), 'r') as f:
         doc.read(f)
     doc.deleteLines(1, 3)
Ejemplo n.º 51
0
 def testWordAt(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     self.assertEqual(doc.wordAt((2, 6)), ('are', 5))
Ejemplo n.º 52
0
 def registerCursor(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     cursor = TextDocumentCursor(doc)
Ejemplo n.º 53
0
    def testChangeLineNumber(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")
        meta_info1 = doc.lineMetaInfo("whatever")
        meta_info2 = doc.lineMetaInfo("whatever2")

        meta_info1.setData("hello", 1)
        meta_info2.setData("byebye", 1)

        doc.newLineAfter(1)

        self.assertEqual(meta_info1.numLines(), 2)
        self.assertEqual(meta_info2.numLines(), 2)

        self.assertEqual(meta_info1.data(1, 2), ["hello", None])
        self.assertEqual(meta_info2.data(1, 2), ["byebye", None])

        doc.newLine(1)

        self.assertEqual(meta_info1.numLines(), 3)
        self.assertEqual(meta_info2.numLines(), 3)

        self.assertEqual(meta_info1.data(1, 3), [None, "hello", None])
        self.assertEqual(meta_info2.data(1, 3), [None, "byebye", None])

        doc.deleteLine(2)

        self.assertEqual(meta_info1.numLines(), 2)
        self.assertEqual(meta_info2.numLines(), 2)

        self.assertEqual(meta_info1.data(1, 2), [None, None])
        self.assertEqual(meta_info2.data(1, 2), [None, None])

        self.assertEqual(meta_info1.data(1, 1), [None])
        self.assertEqual(meta_info2.data(1, 1), [None])

        self.assertEqual(meta_info1.data(1), None)
        self.assertEqual(meta_info2.data(1), None)
Ejemplo n.º 54
0
    def testDeleteChars(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)

        self.assertRaises(ValueError, lambda: doc.deleteChars((1, 3), -1))

        d = doc.deleteChars((1, 3), 1)
        self.assertEqual(doc.lineText(1), 'helo\n')
        self.assertEqual(d[0], 'l')

        d = doc.deleteChars((1, 2), 100)
        self.assertEqual(doc.lineText(1), 'h\n')
        self.assertEqual(d[0], 'elo')

        d = doc.deleteChars((1, 2), 100)
        self.assertEqual(doc.lineText(1), 'h\n')
        self.assertEqual(d[0], '')

        d = doc.deleteChars((1, 1), 100)
        self.assertEqual(doc.lineText(1), '\n')
        self.assertEqual(d[0], 'h')

        d = doc.deleteChars((1, 1), 100)
        self.assertEqual(doc.lineText(1), '\n')
        self.assertEqual(d[0], '')
Ejemplo n.º 55
0
    def testExtractFragment(self):
        doc = TextDocument()
        with open(fixtures.get("bigfile.py"), 'r') as f:
            doc.read(f)
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")

        fragment = doc.extractFragment(2)
        self.assertEqual(fragment.numLines(), 1)
        self.assertEqual(fragment.lineText(1), doc.lineText(2))
        self.assertTrue(fragment.hasLineMetaInfo("whatever"))
        self.assertTrue(fragment.hasLineMetaInfo("whatever2"))

        fragment = doc.extractFragment(2, 3)
        self.assertEqual(fragment.numLines(), 3)
        self.assertEqual(fragment.lineText(1), doc.lineText(2))
        self.assertEqual(fragment.lineText(2), doc.lineText(3))
        self.assertEqual(fragment.lineText(3), doc.lineText(4))
        self.assertTrue(fragment.hasLineMetaInfo("whatever"))
        self.assertTrue(fragment.hasLineMetaInfo("whatever2"))
Ejemplo n.º 56
0
    def testInsertFragment(self):
        doc = TextDocument()
        with open(fixtures.get("numbers.txt"), 'r') as f:
            doc.read(f)
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")

        fragment = doc.extractFragment(2)
        self.assertNotEqual(fragment.lineText(1), doc.lineText(15))
        doc.insertFragment(15, fragment)
        self.assertEqual(fragment.lineText(1), doc.lineText(15))

        fragment = doc.extractFragment(2, 4)
        self.assertNotEqual(fragment.lineText(1), doc.lineText(10))
        doc.insertFragment(10, fragment)

        self.assertEqual(fragment.lineText(1), doc.lineText(10))
        self.assertEqual(fragment.lineText(2), doc.lineText(11))
        self.assertEqual(fragment.lineText(3), doc.lineText(12))
        self.assertEqual(fragment.lineText(4), doc.lineText(13))
Ejemplo n.º 57
0
    def testChangeLineNumber(self):
        doc = TextDocument()
        doc.createLineMetaInfo("whatever")
        doc.createLineMetaInfo("whatever2")
        meta_info1 = doc.lineMetaInfo("whatever")
        meta_info2 = doc.lineMetaInfo("whatever2")

        meta_info1.setData("hello", 1)
        meta_info2.setData("byebye", 1)

        doc.newLineAfter(1)

        self.assertEqual(meta_info1.numLines(), 2)
        self.assertEqual(meta_info2.numLines(), 2)

        self.assertEqual(meta_info1.data(1,2), ["hello", None])
        self.assertEqual(meta_info2.data(1,2), ["byebye", None])

        doc.newLine(1)

        self.assertEqual(meta_info1.numLines(), 3)
        self.assertEqual(meta_info2.numLines(), 3)

        self.assertEqual(meta_info1.data(1,3), [None, "hello", None])
        self.assertEqual(meta_info2.data(1,3), [None, "byebye", None])

        doc.deleteLine(2)

        self.assertEqual(meta_info1.numLines(), 2)
        self.assertEqual(meta_info2.numLines(), 2)

        self.assertEqual(meta_info1.data(1,2), [None, None])
        self.assertEqual(meta_info2.data(1,2), [None, None])

        self.assertEqual(meta_info1.data(1,1), [None])
        self.assertEqual(meta_info2.data(1,1), [None])

        self.assertEqual(meta_info1.data(1), None)
        self.assertEqual(meta_info2.data(1), None)

        doc.deleteLine(1)

        self.assertEqual(meta_info1.numLines(), 1)
        self.assertEqual(meta_info2.numLines(), 1)

        self.assertEqual(meta_info1.data(1,1), [None])
        self.assertEqual(meta_info2.data(1,1), [None])

        self.assertEqual(meta_info1.data(1), None)
        self.assertEqual(meta_info2.data(1), None)

        doc.deleteLine(1)

        self.assertEqual(meta_info1.numLines(), 1)
        self.assertEqual(meta_info2.numLines(), 1)

        self.assertEqual(meta_info1.data(1,1), [None])
        self.assertEqual(meta_info2.data(1,1), [None])

        self.assertEqual(meta_info1.data(1), None)
        self.assertEqual(meta_info2.data(1), None)
Ejemplo n.º 58
0
 def testHasLine(self):
     doc = TextDocument()
     with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
         doc.read(f)
     self.assertTrue(doc.hasLine(1))
     self.assertFalse(doc.hasLine(20))
Ejemplo n.º 59
0
    def testReplaceFromMemento(self):
        doc = TextDocument()
        with open(fixtures.get("basic_nonempty_file.txt"), 'r') as f:
            doc.read(f)
        doc.createLineMetaInfo("whatever")
        initial_text = doc.documentText()
        meta_info1 = doc.lineMetaInfo("whatever")
        meta_info1.setData("hello", 1)

        memento = doc.lineMemento(1)
        doc.insertChars((1, 1), 'gnakgnak')
        meta_info1.setData("byebye", 1)
        doc.replaceFromMemento(1, memento)

        self.assertEqual(doc.documentText(), initial_text)
        self.assertEqual(meta_info1.data(1), "hello")
Ejemplo n.º 60
0
 def testSave(self):
     path = fixtures.tempFile("testSave")
     doc = TextDocument()
     with open(path, 'w') as f:
         doc.write(f)
     self.assertTrue(os.path.exists(path))