Example #1
0
        public void TryGetAnnotationAtIndex_WhenIndexValidAndAtLeastOneAnnotation_ReturnsAnnotationAtIndex()
        {
            var document = new SplashDocument();
            var key      = new Key <string>("href");

            // begin/end an empty block of annotations, these will get stripped out
            document.BeginAnnotation(key, "empty");
            document.BeginAnnotation(key, "empty2");
            document.EndAnnotation(key);
            document.EndAnnotation(key);

            // add some unannotated text
            document.AppendText("some ");

            // add some annotated text
            using (document.BeginAnnotation(key, "a"))
            {
                document.AppendText("text ");

                using (document.BeginAnnotation(key, "b"))
                    document.AppendText("more");
            }

            // add some unannotated text
            document.AppendText("...");

            // begin another empty annotation at the end, should have no effect on current text
            document.BeginAnnotation(key, "trailer");

            Assert.Multiple(() =>
            {
                string value;
                for (int i = 0; i < 5; i++)
                {
                    Assert.IsFalse(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.IsNull(value);
                }
                for (int i = 5; i < 10; i++)
                {
                    Assert.IsTrue(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.AreEqual("a", value);
                }
                for (int i = 10; i < 14; i++)
                {
                    Assert.IsTrue(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.AreEqual("b", value);
                }
                for (int i = 14; i < 17; i++)
                {
                    Assert.IsFalse(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.IsNull(value);
                }
            });
        }
Example #2
0
        public void TryGetAnnotationAtIndex_WhenIndexBeyondDocument_Throws()
        {
            var    document = new SplashDocument();
            var    key      = new Key <string>("href");
            string value;

            document.AppendText("some text...");

            Assert.Throws <ArgumentOutOfRangeException>(() => document.TryGetAnnotationAtIndex(key, 12, out value));
        }
Example #3
0
        public void TryGetAnnotationAtIndex_WhenIndexValidAndNoAnnotations_ReturnsFalse()
        {
            var document = new SplashDocument();
            var key      = new Key <string>("href");

            document.AppendText("foo");

            string value;

            Assert.IsFalse(document.TryGetAnnotationAtIndex(key, 0, out value));
            Assert.IsNull(value);
        }
        public void TryGetAnnotationAtIndex_WhenIndexValidAndAtLeastOneAnnotation_ReturnsAnnotationAtIndex()
        {
            var document = new SplashDocument();
            var key = new Key<string>("href");

            // begin/end an empty block of annotations, these will get stripped out
            document.BeginAnnotation(key, "empty");
            document.BeginAnnotation(key, "empty2");
            document.EndAnnotation(key);
            document.EndAnnotation(key);

            // add some unannotated text
            document.AppendText("some ");

            // add some annotated text
            using (document.BeginAnnotation(key, "a"))
            {
                document.AppendText("text ");

                using (document.BeginAnnotation(key, "b"))
                    document.AppendText("more");
            }

            // add some unannotated text
            document.AppendText("...");

            // begin another empty annotation at the end, should have no effect on current text
            document.BeginAnnotation(key, "trailer");

            Assert.Multiple(() =>
            {
                string value;
                for (int i = 0; i < 5; i++)
                {
                    Assert.IsFalse(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.IsNull(value);
                }
                for (int i = 5; i < 10; i++)
                {
                    Assert.IsTrue(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.AreEqual("a", value);
                }
                for (int i = 10; i < 14; i++)
                {
                    Assert.IsTrue(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.AreEqual("b", value);
                }
                for (int i = 14; i < 17; i++)
                {
                    Assert.IsFalse(document.TryGetAnnotationAtIndex(key, i, out value));
                    Assert.IsNull(value);
                }
            });
        }
        public void TryGetAnnotationAtIndex_WhenIndexValidAndNoAnnotations_ReturnsFalse()
        {
            var document = new SplashDocument();
            var key = new Key<string>("href");

            document.AppendText("foo");

            string value;
            Assert.IsFalse(document.TryGetAnnotationAtIndex(key, 0, out value));
            Assert.IsNull(value);
        }
        public void TryGetAnnotationAtIndex_WhenIndexBeyondDocument_Throws()
        {
            var document = new SplashDocument();
            var key = new Key<string>("href");
            string value;
            document.AppendText("some text...");

            Assert.Throws<ArgumentOutOfRangeException>(() => document.TryGetAnnotationAtIndex(key, 12, out value));
        }