Skip to content

Commit

Permalink
fix tests for ST2
Browse files Browse the repository at this point in the history
  • Loading branch information
philippotto committed Feb 10, 2015
1 parent 540b093 commit ccef8ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
22 changes: 14 additions & 8 deletions tests/testMultiEditUtils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# coding: utf8

import sublime
from unittest import TestCase
import re
Expand Down Expand Up @@ -193,25 +195,25 @@ def testMultiFindAll(self):
def testDecode(self):


sel = self.decode_sel("test some-Test├ ┤TEST")
sel = self.decode_sel(">test< some->Test< >TEST<")

print(sel)



def decode_sel(self, content):

splitted = re.split(r'([│┤├])', content)
splitted = re.split(r'([│><])', content)
content = ''
pos = 0
regionStart = 0
regions = []
for s in splitted:
if s == '│':
regions.append(pos)
elif s == '':
elif s == '<':
regions.append(sublime.Region(regionStart, pos))
elif s == '':
elif s == '>':
regionStart = pos
else:
pos += len(s)
Expand All @@ -222,12 +224,14 @@ def decode_sel(self, content):

def testBasicPreserveCase(self):

testString = "test some-Test some_test Some-Test TEST"
testString = ">test< some->Test< some_test Some-Test >TEST<"
testString, regions = self.decode_sel(testString)
self.view.run_command("insert", {"characters": testString})
selection = self.view.sel()

selection.add_all(regions)
for region in regions:
selection.add(region)

self.view.run_command("preserve_case", {"newString": "case"})

self.assertEqual(self.view.substr(regions[0]), "case")
Expand All @@ -238,12 +242,14 @@ def testBasicPreserveCase(self):
def testAdvancedPreserveCase(self):

expectedStrings = ["some case", "some-Case", "some_case", "Some-Case", "SomeCase", "someCase", "SomeCASE"]
testString = "some test├ ┤some-Test├ ┤some_test├ ┤Some-Test├ ┤SomeTest├ ┤someTest├ ┤SomeTEST"
testString = ">some test< >some-Test< >some_test< >Some-Test< >SomeTest< >someTest< >SomeTEST<"
testString, regions = self.decode_sel(testString)
self.view.run_command("insert", {"characters": testString})
selection = self.view.sel()

selection.add_all(regions)
for region in regions:
selection.add(region)

self.view.run_command("preserve_case", {"newString": "some case"})

for region, expectedString in zip(regions, expectedStrings):
Expand Down
16 changes: 12 additions & 4 deletions tests/testPreserveCase.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import sublime
from unittest import TestCase
version = sublime.version()

import os.path, sys
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))

try:
from MultiEditUtils.MultiEditUtils import MultiEditUtils
except:
version = sublime.version()
if int(version) > 3000:
from MultiEditUtils import MultiEditUtils
else:
import MultiEditUtils

version = sublime.version()

class TestPreserveCase(TestCase):

Expand All @@ -24,6 +25,13 @@ def tearDown(self):
self.view.set_scratch(True)
self.view.window().run_command("close_file")

def assertListEqual(self, listA, listB):

self.assertEqual(len(listA), len(listB))

for idx, el in enumerate(listA):
self.assertEqual(el, listB[idx])


def testAnalyzeString(self):

Expand Down

0 comments on commit ccef8ff

Please sign in to comment.