예제 #1
0
	def testNormalCase(self):
		files = ["a", "b"]
		# create a and b with stuff
		searchExpression = "old"
		replaceExpression = "new"
		vimsub = VimSub(files, searchExpression, replaceExpression)
		
		expectedOutput = vimsub.getVimFileHeader() + r"""
edit a
try
	execute "%s/old/new/gc"
catch /^Vim\%((\a\+)\)\=:E486/
	echo "Expression not found"
endtry
write
bd

edit b
try
	execute "%s/old/new/gc"
catch /^Vim\%((\a\+)\)\=:E486/
	echo "Expression not found"
endtry
write
bd

quit
"""
		
		#self.fileWrite("expected", expectedOutput)
		#self.fileWrite("received", vimsub.getVimFileContents())
		self.myAssertEqual(expectedOutput, vimsub.getVimFileContents())
		self.assertContains(vimsub.getVimFileContents(), "/gc")
예제 #2
0
	def testConfirmReplacementsFlag(self):
		files = ["a", "b"]
		# create a and b with stuff
		searchExpression = "old"
		replaceExpression = "new"
		vimsub = VimSub(files, searchExpression, replaceExpression)
		vimsub.confirmReplacements = False
		self.assertContains(vimsub.getVimFileContents(), "/g")
		self.assertDoesntContain(vimsub.getVimFileContents(), "/gc")
예제 #3
0
	def testEscapingDoneBy_buildSubstituteCommand(self):
		files = ["a"]

		searchExpression = r"something \(with a capture group\)"
		replaceExpression = r"something \1"
		vimsub = VimSub(files, searchExpression, replaceExpression)
		self.myAssertEqual(r"%s/something \\(with a capture group\\)/something \\1/gc", vimsub.buildSubstituteCommand())
	
		searchExpression = r"""$GLOBALS["variableName"] = true;"""
		replaceExpression = r"""$GLOBALS["variableName"] = true;"""
		vimsub = VimSub(files, searchExpression, replaceExpression)
		self.myAssertEqual(r"""%s/$GLOBALS["variableName"] = true;/$GLOBALS["variableName"] = true;/gc""", vimsub.buildSubstituteCommand())
예제 #4
0
	def testEscapingOfQuotes(self):
		# Double-quotes (") must be escaped because the argument for the execute command is delimited by them (").
		files = ["a"]
		searchExpression = r"""$GLOBALS["variableName"] = true;"""
		replaceExpression = r"""$GLOBALS["variableName"] = true;"""
		vimsub = VimSub(files, searchExpression, replaceExpression)
		
		expectedOutput = vimsub.getVimFileHeader() + r"""
edit a
try
	execute "%s/$GLOBALS[\"variableName\"] = true;/$GLOBALS[\"variableName\"] = true;/gc"
catch /^Vim\%((\a\+)\)\=:E486/
	echo "Expression not found"
endtry
write
bd

quit
"""
		self.myAssertEqual(expectedOutput, vimsub.getVimFileContents())
		self.assertContains(vimsub.getVimFileContents(), "/gc")
예제 #5
0
	def testEscapingOfParentheses(self):
		files = ["a"]
		searchExpression = r"something \(with a capture group\)"
		replaceExpression = r"something \1"
		vimsub = VimSub(files, searchExpression, replaceExpression)
		
		expectedOutput = vimsub.getVimFileHeader() + r"""
edit a
try
	execute "%s/something \\(with a capture group\\)/something \\1/gc"
catch /^Vim\%((\a\+)\)\=:E486/
	echo "Expression not found"
endtry
write
bd

quit
"""
		
		#self.fileWrite("expected", expectedOutput)
		#self.fileWrite("received", vimsub.getVimFileContents())
		self.myAssertEqual(expectedOutput, vimsub.getVimFileContents())
		self.assertContains(vimsub.getVimFileContents(), "/gc")