public void BeginAnnotationAndEndAnnotation_PushAndPopAnnotationsOnStack() { var document = new SplashDocument(); var key = new Key <string>("href"); string value; Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value)); Assert.IsNull(value); document.BeginAnnotation(key, "a"); Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("a", value); document.EndAnnotation(key); Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value)); Assert.IsNull(value); using (document.BeginAnnotation(key, "b")) { Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("b", value); using (document.BeginAnnotation(key, "c")) { Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("c", value); } Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("b", value); } Assert.IsFalse(document.TryGetCurrentAnnotation(key, 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 EndAnnotation_WhenNoCurrentAnnotation_Throws() { var document = new SplashDocument(); var key = new Key <string>("href"); // 1st case: no annotation table exists Assert.Throws <InvalidOperationException>(() => document.EndAnnotation(key)); // 2nd case: annotation table exists but there is no current annotation document.BeginAnnotation(key, "value"); document.EndAnnotation(key); Assert.Throws <InvalidOperationException>(() => document.EndAnnotation(key)); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); SplashDocument document = splashView.Document; document.AppendText("Text...\nText 2... "); using (document.BeginStyle(new StyleBuilder() { Color = Color.Green, Font = new Font(FontFamily.GenericSerif, 16) }.ToStyle())) { document.AppendText("Text 3... "); using (document.BeginStyle(new StyleBuilder() { Color = Color.Gold }.ToStyle(document.CurrentStyle))) { document.AppendText("Text 4...\n"); } document.AppendText("\nMore \tText...\n"); } document.AppendText("Why Hello ????? ??????? World? How are you?"); document.AppendLine(); document.AppendText("Tab1\tTab2\tTab3\tTab4\tTab5\tTab6\tTab7\tTab8\n"); document.AppendText("Tab.1\tTab.2\tTab.3\tTab.4\tTab.5\tTab.6\tTab.7\tTab.8\n"); using (document.BeginStyle(new StyleBuilder() { Font = new Font(Style.Default.Font, FontStyle.Underline), Color = Color.DarkBlue }.ToStyle())) { using (document.BeginAnnotation(HRefKey, "http://www.gallio.org/")) document.AppendText("Gallio.org\n"); } using (document.BeginStyle(new StyleBuilder() { Font = new Font(Style.Default.Font, FontStyle.Italic), LeftMargin = 30, RightMargin = 30, FirstLineIndent = 40 }.ToStyle())) { document.AppendText( "This paragraph has a first line indent, left margin and right margin. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n"); } using (document.BeginStyle(new StyleBuilder() { WordWrap = false, Color = Color.Blue, Font = new Font(Style.Default.Font, FontStyle.Bold) }.ToStyle())) { document.AppendText("Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled. Word wrap disabled.\n"); } using (document.BeginStyle(new StyleBuilder() { Color = Color.Red, Font = new Font(FontFamily.GenericSerif, 16) }.ToStyle())) { document.AppendLine(); document.AppendText("?????? ????? ?????? ??????? ???? ??? ? ??? ?????? ?????? ??????? ???????. ??? ?????? ??????? ????? ???? ???? ????? (??? ????? ????? ????? ? ??? ???? ?? ?????? ???????? ???? ?? ??????? ???? ????? ?????). ??? ?? ??? ???? ???? ??????? ???????? (???? ?? ??? ????? ???????)."); document.AppendLine(); } document.AppendLine(); document.AppendText("Sample image. "); document.AppendObject(new EmbeddedImage(Resources.SampleImage) { Baseline = 10 }); document.AppendText(" (with baseline adjusted by 10 px)."); document.AppendLine(); document.AppendLine(); document.AppendText("How many lambs did Mary have?"); document.AppendObject(new EmbeddedControl(new TextBox()) { Margin = new Padding(3, 3, 3, 3), Baseline = 6 }); document.AppendLine(); document.AppendObject(new EmbeddedImage(Resources.Passed) { Margin = new Padding(3, 3, 3, 3) }); document.AppendText("Passed 5 "); document.AppendObject(new EmbeddedImage(Resources.Failed) { Margin = new Padding(3, 3, 3, 3) }); document.AppendText("Failed 1"); document.AppendObject(new EmbeddedImage(Resources.Ignored) { Margin = new Padding(3, 3, 3, 3) }); document.AppendText("Inconclusive 0"); document.AppendLine(); document.AppendLine(); document.AppendText("What's the magic word?"); document.AppendObject(new EmbeddedControl(new TextBox()) { Margin = new Padding(3, 3, 3, 3), Baseline = 6 }); document.AppendLine(); for (int i = 0; i < 1000; i++) { document.AppendText(string.Format("Line #{0}\n", i)); } }
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 BeginAnnotationAndEndAnnotation_PushAndPopAnnotationsOnStack() { var document = new SplashDocument(); var key = new Key<string>("href"); string value; Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value)); Assert.IsNull(value); document.BeginAnnotation(key, "a"); Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("a", value); document.EndAnnotation(key); Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value)); Assert.IsNull(value); using (document.BeginAnnotation(key, "b")) { Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("b", value); using (document.BeginAnnotation(key, "c")) { Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("c", value); } Assert.IsTrue(document.TryGetCurrentAnnotation(key, out value)); Assert.AreEqual("b", value); } Assert.IsFalse(document.TryGetCurrentAnnotation(key, out value)); Assert.IsNull(value); }
public void EndAnnotation_WhenNoCurrentAnnotation_Throws() { var document = new SplashDocument(); var key = new Key<string>("href"); // 1st case: no annotation table exists Assert.Throws<InvalidOperationException>(() => document.EndAnnotation(key)); // 2nd case: annotation table exists but there is no current annotation document.BeginAnnotation(key, "value"); document.EndAnnotation(key); Assert.Throws<InvalidOperationException>(() => document.EndAnnotation(key)); }