/// <summary> /// Checks for value equality between the <see cref="Cell"/> and an object. /// </summary> /// <param name="obj">The object to check for value equality.</param> /// <returns>True if the <see cref="Cell"/>'s value is equal to the object's value, false otherwise.</returns> public override bool Equals(object obj) { return(obj is Cell cell && Lines.ToString() == cell.Lines.ToString() && // Not efficient, but StringLineGroup does not override Object.Equals StartColumnIndex == cell.StartColumnIndex && EndColumnIndex == cell.EndColumnIndex && StartRowIndex == cell.StartRowIndex && EndRowIndex == cell.EndRowIndex && StartOffset == cell.StartOffset && EndOffset == cell.EndOffset && LineIndex == cell.LineIndex && IsOpen == cell.IsOpen); }
public void TestStringLineGroupSimple() { var text = new StringLineGroup(4) { new StringSlice("ABC"), new StringSlice("E"), new StringSlice("F") }; var iterator = text.ToCharIterator(); Assert.AreEqual("ABC\nE\nF".Length, iterator.End - iterator.Start + 1); var chars = ToString(text.ToCharIterator()); TextAssert.AreEqual("ABC\nE\nF", chars.ToString()); TextAssert.AreEqual("ABC\nE\nF", text.ToString()); }
public void CreateCore_CreatesFlexiCodeBlock() { // Arrange const int dummyLine = 6; const int dummyColumn = 2; var dummySpan = new SourceSpan(5, 10); const string dummyBlockName = "dummyBlockName"; const string dummyTitle = "dummyTitle"; const string dummyCopyIcon = "dummyCopyIcon"; const bool dummyRenderHeader = false; const string dummyLanguage = "dummyLanguage"; var dummyLines = new StringLineGroup(2); dummyLines.Add(new StringSlice("dummy")); dummyLines.Add(new StringSlice("line")); const SyntaxHighlighter dummySyntaxHighlighter = SyntaxHighlighter.HighlightJS; var dummyLineNumbers = new ReadOnlyCollection <NumberedLineRange>(new List <NumberedLineRange>()); var dummyResolvedLineNumbers = new ReadOnlyCollection <NumberedLineRange>(new List <NumberedLineRange>()); const string dummyOmittedLinesIcon = "dummyOmittedLinesIcon"; var dummyHighlightedLines = new ReadOnlyCollection <LineRange>(new List <LineRange>()); var dummyResolvedHighlightedLines = new ReadOnlyCollection <LineRange>(new List <LineRange>()); var dummyHighlightedPhrases = new ReadOnlyCollection <PhraseGroup>(new List <PhraseGroup>()); var dummyResolvedHighlightedPhrases = new ReadOnlyCollection <Phrase>(new List <Phrase>()); const FlexiCodeBlockRenderingMode dummyRenderingMode = FlexiCodeBlockRenderingMode.Classic; var dummyAttributes = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>()); Mock <BlockParser> dummyBlockParser = _mockRepository.Create <BlockParser>(); var dummyProxyLeafBlock = new ProxyLeafBlock(null, dummyBlockParser.Object); dummyProxyLeafBlock.Line = dummyLine; dummyProxyLeafBlock.Column = dummyColumn; dummyProxyLeafBlock.Span = dummySpan; dummyProxyLeafBlock.Lines = dummyLines; BlockProcessor dummyBlockProcessor = MarkdigTypesFactory.CreateBlockProcessor(); Mock <IFlexiCodeBlockOptions> mockFlexiCodeBlockOptions = _mockRepository.Create <IFlexiCodeBlockOptions>(); mockFlexiCodeBlockOptions.Setup(f => f.BlockName).Returns(dummyBlockName); mockFlexiCodeBlockOptions.Setup(f => f.Title).Returns(dummyTitle); mockFlexiCodeBlockOptions.Setup(f => f.CopyIcon).Returns(dummyCopyIcon); mockFlexiCodeBlockOptions.Setup(f => f.RenderHeader).Returns(dummyRenderHeader); mockFlexiCodeBlockOptions.Setup(f => f.Language).Returns(dummyLanguage); mockFlexiCodeBlockOptions.Setup(f => f.SyntaxHighlighter).Returns(dummySyntaxHighlighter); mockFlexiCodeBlockOptions.Setup(f => f.LineNumbers).Returns(dummyLineNumbers); mockFlexiCodeBlockOptions.Setup(f => f.OmittedLinesIcon).Returns(dummyOmittedLinesIcon); mockFlexiCodeBlockOptions.Setup(f => f.HighlightedLines).Returns(dummyHighlightedLines); mockFlexiCodeBlockOptions.Setup(f => f.HighlightedPhrases).Returns(dummyHighlightedPhrases); mockFlexiCodeBlockOptions.Setup(f => f.RenderingMode).Returns(dummyRenderingMode); mockFlexiCodeBlockOptions.Setup(f => f.Attributes).Returns(dummyAttributes); Mock <IOptionsService <IFlexiCodeBlockOptions, IFlexiCodeBlocksExtensionOptions> > mockOptionsService = _mockRepository. Create <IOptionsService <IFlexiCodeBlockOptions, IFlexiCodeBlocksExtensionOptions> >(); mockOptionsService.Setup(f => f.CreateOptions(dummyBlockProcessor)). Returns((mockFlexiCodeBlockOptions.Object, null)); Mock <FlexiCodeBlockFactory> mockTestSubject = CreateMockFlexiCodeBlockFactory(mockOptionsService.Object); mockTestSubject.CallBase = true; mockTestSubject.Setup(t => t.ResolveBlockName(dummyBlockName)).Returns(dummyBlockName); mockTestSubject.Setup(t => t.ValidateSyntaxHighlighter(dummySyntaxHighlighter)); mockTestSubject.Setup(t => t.TryCreateSortedLineRanges(dummyLineNumbers, dummyLines.Count)).Returns(dummyResolvedLineNumbers); mockTestSubject.Setup(t => t.ValidateSortedLineNumbers(It.Is <ReadOnlyCollection <NumberedLineRange> >(lineNumbers => lineNumbers == dummyResolvedLineNumbers), dummyLines.Count)); mockTestSubject.Setup(t => t.TryCreateSortedLineRanges(dummyHighlightedLines, dummyLines.Count)).Returns(dummyResolvedHighlightedLines); mockTestSubject. Setup(t => t.ResolveHighlightedPhrases(dummyLines.ToString(), It.Is <ReadOnlyCollection <PhraseGroup> >(highlightedPhrases => highlightedPhrases == dummyHighlightedPhrases))) .Returns(dummyResolvedHighlightedPhrases); mockTestSubject.Setup(t => t.ValidateRenderingMode(dummyRenderingMode)); // Act FlexiCodeBlock result = mockTestSubject.Object.CreateCore(dummyProxyLeafBlock, dummyBlockProcessor); // Assert _mockRepository.VerifyAll(); Assert.Equal(dummyBlockName, result.BlockName); Assert.Equal(dummyTitle, result.Title); Assert.Equal(dummyCopyIcon, result.CopyIcon); Assert.Equal(dummyRenderHeader, result.RenderHeader); Assert.Equal(dummyLanguage, result.Language); Assert.Equal(dummyLines.ToString(), result.Code); Assert.Equal(dummyLines.Count, result.CodeNumLines); Assert.Equal(dummySyntaxHighlighter, result.SyntaxHighlighter); Assert.Same(dummyResolvedLineNumbers, result.LineNumbers); Assert.Same(dummyOmittedLinesIcon, result.OmittedLinesIcon); Assert.Same(dummyResolvedHighlightedLines, result.HighlightedLines); Assert.Same(dummyResolvedHighlightedPhrases, result.HighlightedPhrases); Assert.Equal(dummyRenderingMode, result.RenderingMode); Assert.Same(dummyAttributes, result.Attributes); Assert.Same(dummyBlockParser.Object, result.Parser); Assert.Equal(dummyLine, result.Line); Assert.Equal(dummyColumn, result.Column); Assert.Equal(dummySpan, result.Span); }