private string GetVariableNameFeedback() { if (string.IsNullOrEmpty(NewName)) { return(string.Empty); } if (_forbiddenNames.Any(name => name.Equals(NewName, StringComparison.OrdinalIgnoreCase))) { return(string.Format(RubberduckUI.AssignedByValDialog_NewNameAlreadyUsedFormat, NewName)); } if (VariableNameValidator.StartsWithDigit(NewName)) { return(RubberduckUI.AssignedByValDialog_DoesNotStartWithLetter); } if (VariableNameValidator.HasSpecialCharacters(NewName)) { return(RubberduckUI.AssignedByValDialog_InvalidCharacters); } if (VariableNameValidator.IsReservedIdentifier(NewName)) { return(string.Format(RubberduckUI.AssignedByValDialog_ReservedKeywordFormat, NewName)); } if (!VariableNameValidator.IsMeaningfulName(NewName)) { return(string.Format(RubberduckUI.AssignedByValDialog_QuestionableEntryFormat, NewName)); } return(string.Empty); }
private string GetVariableNameFeedback() { if (string.IsNullOrEmpty(NewName)) { return(string.Empty); } if (_isConflictingName(NewName)) { return(string.Format(RubberduckUI.AssignedByValDialog_NewNameAlreadyUsedFormat, NewName)); } if (VariableNameValidator.StartsWithDigit(NewName)) { return(RubberduckUI.AssignedByValDialog_DoesNotStartWithLetter); } if (VariableNameValidator.HasSpecialCharacters(NewName)) { return(RubberduckUI.AssignedByValDialog_InvalidCharacters); } if (VariableNameValidator.IsReservedIdentifier(NewName)) { return(string.Format(RubberduckUI.AssignedByValDialog_ReservedKeywordFormat, NewName)); } if (!VariableNameValidator.IsMeaningfulName(NewName)) { return(string.Format(RubberduckUI.AssignedByValDialog_QuestionableEntryFormat, NewName)); } return(string.Empty); }
public void DeclarationFinder_FindsAccessibleDeclarations_All() { //Tests that the DeclarationFinder does not return any unexpected declarations //excluding Reserved Identifiers SetupSUT("TestProject"); var allNamesUsedInTests = new List <string>(); List <string> names; foreach (var Key in _tdo.AccessibleNames.Keys) { _tdo.AccessibleNames.TryGetValue(Key, out names); allNamesUsedInTests.AddRange(names); } allNamesUsedInTests.AddRange(_tdo.Components.Select(n => n.Name)); var target = GetTargetForAccessibilityTests(); var accessibleNames = _tdo.Parser.State.DeclarationFinder.GetDeclarationsWithIdentifiersToAvoid(target) .Select(dec => dec.IdentifierName); Assert.IsTrue(accessibleNames.Count() > 0); var unexpectedDeclarations = accessibleNames.Except(allNamesUsedInTests).ToList().Where(n => !VariableNameValidator.IsReservedIdentifier(n)); string failureMessage = string.Empty; if (unexpectedDeclarations.Count() > 0) { failureMessage = unexpectedDeclarations.Count().ToString() + " unexpected declaration(s) found:"; foreach (string identifier in unexpectedDeclarations) { failureMessage = failureMessage + " '" + identifier + "', "; } failureMessage = failureMessage.Substring(0, failureMessage.Length - 2); } Assert.AreEqual(0, unexpectedDeclarations.Count(), failureMessage); }