public void EqualsTestAnotherObject() { MatchResult mr1 = new MatchResult(); mr1.StartIndex = 1; mr1.EndIndex = 2; mr1.Result = true; Assert.IsFalse(mr1.Equals("Test")); }
public void EqualsTestSameMatchResult() { MatchResult mr1 = new MatchResult(); mr1.StartIndex = 1; mr1.EndIndex = 2; mr1.Result = true; MatchResult mr2 = new MatchResult(); mr2.StartIndex = 1; mr2.EndIndex = 2; mr2.Result = true; Assert.IsTrue(mr1.Equals(mr2)); }
public void EqualsTestDifferentMatchResult() { MatchResult mr1 = new MatchResult(); mr1.StartIndex = 1; mr1.EndIndex = 2; mr1.Result = true; MatchResult mr2 = new MatchResult(); mr2.StartIndex = 2; mr2.EndIndex = 2; mr2.Result = true; Assert.IsFalse(mr1.Equals(mr2)); }
public void EqualOperatorTest() { MatchResult mr1 = new MatchResult(); mr1.StartIndex = 1; mr1.EndIndex = 2; mr1.Result = true; MatchResult mr2 = new MatchResult(); mr2.StartIndex = 2; mr2.EndIndex = 2; mr2.Result = true; Assert.IsFalse(mr1 == mr2, "Equality operator fails when objects are different"); mr2.StartIndex = 1; Assert.IsTrue(mr1 == mr2, "Equality operator fails when objects are same"); }
public void Exec(string cmdName, vsCommandExecOption executeOption, ref object variantIn, ref object variantOut, ref bool handled) { if (cmdName == null) { throw new ArgumentNullException("CmdName"); } if (cmdName == typeof(Connect).FullName + "." + Strings.RefactorCommandName) { TextSelection selection = (TextSelection)(applicationObject.ActiveDocument.Selection); if (applicationObject.ActiveDocument.ProjectItem.Object != null) { Common.BaseHardCodedString stringInstance = BaseHardCodedString.GetHardCodedString(applicationObject.ActiveDocument); if (stringInstance == null) { MessageBox.Show( Strings.UnsupportedFile + " (" + applicationObject.ActiveDocument.Language + ")", Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Common.MatchResult scanResult = stringInstance.CheckForHardCodedString( selection.Parent, selection.AnchorPoint.AbsoluteCharOffset - 1, selection.BottomPoint.AbsoluteCharOffset - 1); if (!scanResult.Result && selection.AnchorPoint.AbsoluteCharOffset < selection.BottomPoint.AbsoluteCharOffset) { scanResult.StartIndex = selection.AnchorPoint.AbsoluteCharOffset - 1; scanResult.EndIndex = selection.BottomPoint.AbsoluteCharOffset - 1; scanResult.Result = true; } if (scanResult.Result) { stringInstance = stringInstance.CreateInstance(applicationObject.ActiveDocument.ProjectItem, scanResult.StartIndex, scanResult.EndIndex); if (stringInstance != null && stringInstance.Parent != null) { PerformAction(stringInstance); } } else { MessageBox.Show(Strings.NotStringLiteral, Strings.WarningTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public MatchResult CheckForHardCodedString(string text, int selectionStart, int selectionEnd) { MatchResult result = new MatchResult(); MatchCollection matches = this.literalRegex.Matches(text); foreach (Match match in matches) { if (match.Index <= selectionStart && match.Index + match.Length >= selectionEnd) { result.Result = true; result.StartIndex = match.Index; result.EndIndex = match.Index + match.Length; break; } } return result; }