コード例 #1
0
		public void TwoLineRegionConvertedToSegment()
		{
			DomRegion region = new DomRegion(1, 2, 2, 1);
			document.Text = "1234567890\r\n1234567890";
			WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(1, 12);
			
			Assert.AreEqual(expectedSegment, segment);
		}
コード例 #2
0
		public void ThreeLineRegionWithoutCarriageReturnConvertedToSegment()
		{
			DomRegion region = new DomRegion(1, 3, 3, 2);
			document.Text = "1234567890\n1234567890\n1234567890";
			WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 22);
			
			Assert.AreEqual(expectedSegment, segment);
		}
コード例 #3
0
        public override bool Equals(object obj)
        {
            WixDocumentLineSegment rhs = obj as WixDocumentLineSegment;

            if (rhs != null)
            {
                return((offset == rhs.offset) && (length == rhs.length));
            }
            return(false);
        }
コード例 #4
0
		public void RegionWithBeginLineOnSecondLineConvertedToSegment()
		{
			DomRegion region = new DomRegion(2, 1, 3, 1);
			document.Text = "1234567890\r\n1234567890\r\n1234567890";
			WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(12, 13);
			
			Assert.AreEqual(expectedSegment, segment);
		}
コード例 #5
0
		public void BeginLineOnSecondLine()
		{
			DomRegion region = new DomRegion(1, 0, 2, 0);
			DocumentFactory factory = new DocumentFactory();
			IDocument document = factory.CreateDocument();
			document.TextContent = "1234567890\r\n1234567890\r\n1234567890";
			ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(12, 13);
			
			Assert.AreEqual(expectedSegment, segment);
		}
コード例 #6
0
		public void ThreeLinesWithoutCarriageReturn()
		{
			DomRegion region = new DomRegion(0, 2, 2, 1);
			DocumentFactory factory = new DocumentFactory();
			IDocument document = factory.CreateDocument();
			document.TextContent = "1234567890\n1234567890\n1234567890";
			ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 22);
			
			Assert.AreEqual(expectedSegment, segment);
		}
コード例 #7
0
		public void SingleLine()
		{
			DomRegion region = new DomRegion(0, 0, 0, 5);
			DocumentFactory factory = new DocumentFactory();
			IDocument document = factory.CreateDocument();
			document.TextContent = "1234567890";
			ISegment segment = WixDocument.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(0, 6);
			
			Assert.AreEqual(expectedSegment, segment);
		}
コード例 #8
0
        public override bool Equals(object obj)
        {
            WixDocumentLineSegment lineSegment = obj as WixDocumentLineSegment;

            if (lineSegment == null)
            {
                return(false);
            }
            if (this == lineSegment)
            {
                return(true);
            }
            return(offset == lineSegment.offset && length == lineSegment.length);
        }
コード例 #9
0
        /// <summary>
        /// Replaces the text at the given region with the specified xml. After replacing
        /// the inserted text is indented and then selected.
        /// </summary>
        public void Replace(DomRegion region, string xml)
        {
            WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);

            using (textEditor.Document.OpenUndoGroup()) {
                // Replace the original xml with the new xml and indent it.
                int originalLineCount = document.TotalNumberOfLines;
                int initialIndent     = GetIndent(region.BeginLine);
                document.Replace(segment.Offset, segment.Length, xml);
                int addedLineCount = document.TotalNumberOfLines - originalLineCount;

                // Indent the xml.
                int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent);

                // Make sure the text inserted is visible.
                textEditor.JumpTo(region.BeginLine, 1);

                // Select the text just inserted.
                int textInsertedLength = insertedCharacterCount + xml.Length;
                textEditor.Select(segment.Offset, textInsertedLength);
            }
        }
コード例 #10
0
		public void NullSegmentIsNotEqualToSegment()
		{
			WixDocumentLineSegment lhs = new WixDocumentLineSegment(1, 4);
			Assert.IsFalse(lhs.Equals(null));
		}
コード例 #11
0
		public void SegmentsWithSameLengthAndDifferentOffsetAreNotEqual()
		{
			WixDocumentLineSegment lhs = new WixDocumentLineSegment(3, 5);
			WixDocumentLineSegment rhs = new WixDocumentLineSegment(4, 5);
			Assert.IsFalse(lhs.Equals(rhs));
		}
コード例 #12
0
		public void SegmentsWithSameOffsetAndLengthAreEqual()
		{
			WixDocumentLineSegment lhs = new WixDocumentLineSegment(4, 5);
			WixDocumentLineSegment rhs = new WixDocumentLineSegment(4, 5);
			Assert.IsTrue(lhs.Equals(rhs));
		}