public void PredictReturnsCorrectResult(string patternString, string[] pushDirectory, string expectSegment, bool expectWildcard) { var builder = new PatternBuilder(); var pattern = builder.Build(patternString) as IRaggedPattern; Assert.NotNull(pattern); var context = new PatternContextRaggedInclude(pattern); PatternContextHelper.PushDirectory(context, pushDirectory); context.Declare((segment, last) => { if (expectSegment != null) { var mockSegment = segment as LiteralPathSegment; Assert.NotNull(mockSegment); Assert.Equal(false, last); Assert.Equal(expectSegment, mockSegment.Value); } else { Assert.Equal(Microsoft.DotNet.ProjectModel.FileSystemGlobbing.Internal.PathSegments.WildcardPathSegment.MatchAll, segment); } }); }
public void BuildLinearPatternNegative(string sample) { var builder = new PatternBuilder(); var pattern = builder.Build(sample) as ILinearPattern; Assert.Null(pattern); }
public void BuildLinearPattern(string sample, int segmentCount) { var builder = new PatternBuilder(); var pattern = builder.Build(sample); Assert.True(pattern is ILinearPattern); Assert.Equal(segmentCount, (pattern as ILinearPattern).Segments.Count); }
public void PredictNotCallBackWhenEnterUnmatchDirectory(string patternString, string[] pushDirectory) { var builder = new PatternBuilder(); var pattern = builder.Build(patternString) as IRaggedPattern; var context = new PatternContextRaggedInclude(pattern); PatternContextHelper.PushDirectory(context, pushDirectory); context.Declare((segment, last) => { Assert.False(true, "No segment should be declared."); }); }
public void PredictBeforeEnterDirectoryShouldThrow() { var builder = new PatternBuilder(); var pattern = builder.Build("**") as IRaggedPattern; var context = new PatternContextRaggedInclude(pattern); Assert.Throws<InvalidOperationException>(() => { context.Declare((segment, last) => { Assert.False(true, "No segment should be declared."); }); }); }
public void BuildRaggedPattern(string sample, int segmentCount, int startSegmentsCount, int containSegmentCount, int endSegmentCount) { var builder = new PatternBuilder(); var pattern = builder.Build(sample) as IRaggedPattern; Assert.NotNull(pattern); Assert.Equal(segmentCount, pattern.Segments.Count); Assert.Equal(startSegmentsCount, pattern.StartsWith.Count); Assert.Equal(endSegmentCount, pattern.EndsWith.Count); Assert.Equal(containSegmentCount, pattern.Contains.Count); }
public Matcher(StringComparison comparisonType) { _comparison = comparisonType; _builder = new PatternBuilder(comparisonType); }
public void ThrowExceptionForNull() { Assert.Throws<ArgumentNullException>(() => { var builder = new PatternBuilder(); builder.Build(null); }); }
public void ThrowExceptionForInvalidParentsPath(string sample) { // parent segment is only allowed at the beginning of the pattern Assert.Throws<ArgumentException>(() => { var builder = new PatternBuilder(); var pattern = builder.Build(sample); Assert.Null(pattern); }); }