public IParseResult TryLoadRegexPattern(string regex) { _wasInitialised = false; _expressionMetaData = null; _regularExpression = null; if (_replaceWildCards) { regex = regex.ReplaceRegexWildCards(); } regex = regex.TrimStart(SpecialCharacters.StartsWith).TrimEnd(SpecialCharacters.EndsWith); var result = new RegularExpressionFactory(_alphabet, _random, MaxCharClassInverseLength) .TryGetRegularExpression(regex, out var expression); if (!result.IsSuccess) { return(result); } _regularExpression = expression; _expressionMetaData = result.Value; _wasInitialised = true; return(new SuccessParseResult()); }
public void TryLoadRegex_ResultValueHasIntersectionIsFalse_WhenPatternDoesNotContainIntersectionToken(string pattern) { var factory = new RegularExpressionFactory(RegexAlphabetFactory.Default(), Substitute.For <IRandomGenerator>(), 1); var result = factory.TryGetRegularExpression(pattern, out _); Assert.IsFalse(result.Value.HasIntersection); }
public void TryLoadRegex_ReturnedExpressionYieldsExpectedMinExpansionLength_WhenCalledForPattern(string pattern, int expectedMinExpansionLength) { var factory = new RegularExpressionFactory(RegexAlphabetFactory.Default(), Substitute.For <IRandomGenerator>(), 1); factory.TryGetRegularExpression(pattern, out var union); var result = union.MaxExpansionRange.Start; Assert.AreEqual(expectedMinExpansionLength, result); }
/// <summary> /// Retrieves all regular expressions from the database assigned to a user /// </summary> public RegularExpressionData GetRegularExpressionsOfUser(int userId, int surveyId) { return(RegularExpressionFactory.Create().GetRegularExpressionsOfUser(userId, surveyId)); }
/// <summary> /// Retrieves regular expression details from the database /// </summary> public RegularExpressionData GetRegularExpressionById(int regularExpressionId) { return(RegularExpressionFactory.Create().GetRegularExpressionById(regularExpressionId)); }
/// <summary> /// Retrieves all regular expressions from the database that can be edited /// by the user /// </summary> public RegularExpressionData GetEditableRegularExpressionsListOfUser(int userId) { return(RegularExpressionFactory.Create().GetEditableRegularExpressionsListOfUser(userId)); }
/// <summary> /// Retrieves all regular expressions from the database /// </summary> public RegularExpressionData GetAllRegularExpressionsList() { return(RegularExpressionFactory.Create().GetAllRegularExpressionsList()); }
/// <summary> /// Updates regular expressions data /// </summary> public void UpdateRegularExpression(RegularExpressionData updatedRegularExpression) { RegularExpressionFactory.Create().UpdateRegularExpression(updatedRegularExpression); }
/// <summary> /// Makes the regular expression as builtin /// </summary> public void SetBuiltInRegularExpression(int regularExpressionId) { RegularExpressionFactory.Create().SetBuiltInRegularExpression(regularExpressionId); }
/// <summary> /// Remove the regular expression /// </summary> public void DeleteRegularExpressionById(int regularExpressionId) { RegularExpressionFactory.Create().DeleteRegularExpressionById(regularExpressionId); }
/// <summary> /// Adds a new regular expression to the database /// </summary> public void AddRegularExpression(RegularExpressionData newRegularExpression, int userId) { RegularExpressionFactory.Create().AddRegularExpression(newRegularExpression, userId); }