Ejemplo n.º 1
0
        public void TextRangeCollection_AddSorted()
        {
            ITextRange[] ranges = new ITextRange[3];

            ranges[0] = TextRange.FromBounds(1, 2);
            ranges[1] = TextRange.FromBounds(3, 5);
            ranges[2] = TextRange.FromBounds(5, 7);

            TextRangeCollection <ITextRange> target = new TextRangeCollection <ITextRange>();

            target.Count.Should().Be(0);

            target.Add(ranges[2]);
            target.Count.Should().Be(1);

            target.AddSorted(ranges[0]);
            target.Count.Should().Be(2);
            target.Start.Should().Be(1);
            target.End.Should().Be(7);
            target[0].Start.Should().Be(1);
            target[1].Start.Should().Be(5);

            target.AddSorted(ranges[1]);
            target.Count.Should().Be(3);
            target.Start.Should().Be(1);
            target.End.Should().Be(7);
            target[0].Start.Should().Be(1);
            target[1].Start.Should().Be(3);
            target[2].Start.Should().Be(5);

            target.Start.Should().Be(1);
            target.End.Should().Be(7);
        }
Ejemplo n.º 2
0
        public void AppendChild(IAstNode child)
        {
            if (child.Parent == null)
            {
                child.Parent = this;
            }
            else if (child.Parent == this)
            {
#if DEBUG
                //foreach (var c in _children)
                //{
                //    Debug.Assert(!TextRange.Intersect(c, child), "Children collection already contains overlapping node");
                //}
#endif
                _children.AddSorted(child);
            }
            else
            {
                throw new InvalidOperationException("Node already has parent");
            }
        }
        public void TextRangeCollection_AddSorted() {
            ITextRange[] ranges = new ITextRange[3];

            ranges[0] = TextRange.FromBounds(1, 2);
            ranges[1] = TextRange.FromBounds(3, 5);
            ranges[2] = TextRange.FromBounds(5, 7);

            TextRangeCollection<ITextRange> target = new TextRangeCollection<ITextRange>();

            target.Count.Should().Be(0);

            target.Add(ranges[2]);
            target.Count.Should().Be(1);

            target.AddSorted(ranges[0]);
            target.Count.Should().Be(2);
            target.Start.Should().Be(1);
            target.End.Should().Be(7);
            target[0].Start.Should().Be(1);
            target[1].Start.Should().Be(5);

            target.AddSorted(ranges[1]);
            target.Count.Should().Be(3);
            target.Start.Should().Be(1);
            target.End.Should().Be(7);
            target[0].Start.Should().Be(1);
            target[1].Start.Should().Be(3);
            target[2].Start.Should().Be(5);

            target.Start.Should().Be(1);
            target.End.Should().Be(7);
        }