Ejemplo n.º 1
0
        public void StringChangedTests()
        {
            string          part0      = "abc";
            AssembledStyles styles     = new AssembledStyles().WithWs(wsEn);
            StringClientRun clientRun0 = new StringClientRun(part0, styles);
            var             clientRuns = new List <IClientRun>();

            clientRuns.Add(clientRun0);
            TextSource        source     = new TextSource(clientRuns);
            List <IRenderRun> renderRuns = source.RenderRuns;

            VerifyRenderRun(renderRuns[0], 0, 3, "initial state has all in one run");
            var clientRun1 = new StringClientRun("abcd", styles);
            var output1    = source.ClientRunChanged(0, clientRun1);

            Assert.AreEqual(1, output1.NewSource.RenderRuns.Count, "replacing single run with simple string should produce single render run.");
            VerifyRenderRun(output1.NewSource.RenderRuns[0], 0, 4, "replacing client run should make a new source with modified single run");
            Assert.AreEqual(3, output1.StartChange);
            Assert.AreEqual(0, output1.DeleteCount);
            Assert.AreEqual(1, output1.InsertCount);

            // try changing the middle of three runs, from a simple one to a complex one.
            clientRuns = new List <IClientRun>();
            clientRuns.Add(clientRun0);
            string part2      = "def";
            var    clientRun2 = new StringClientRun(part2, styles);

            clientRuns.Add(clientRun2);
            string part3      = " mnop";
            var    clientRun3 = new StringClientRun(part3, styles);

            clientRuns.Add(clientRun3);
            source = new TextSource(clientRuns, MockInterpretOrc);

            string part4      = "q\xfffc";
            var    clientRun4 = new StringClientRun(part4, styles);
            var    output2    = source.ClientRunChanged(1, clientRun4);

            Assert.AreEqual(3, output2.NewSource.RenderRuns.Count,
                            "three render runs because ORC interprets as french string.");
            VerifyRenderRun(output2.NewSource.RenderRuns[0], 0, part0.Length + 1, "first run up to ORC");
            VerifyRenderRun(output2.NewSource.RenderRuns[1], part0.Length + 1, orcText.Length, "second run is French from ORC");
            VerifyRenderRun(output2.NewSource.RenderRuns[2], part0.Length + 1 + orcText.Length, part3.Length, "third run is  stuff after ORC");
            VerifyFetch(output2.NewSource, 0, output2.NewSource.Length, part0 + "q" + orcText + part3);
            Assert.AreEqual(part0.Length, output2.StartChange);
            Assert.AreEqual(part2.Length, output2.DeleteCount);
            Assert.AreEqual(1 + orcText.Length, output2.InsertCount);

            // Now do a variation where some of the new run survives at each end.
            // To catch a tricky special case, we want to replace some regular text with an ORC
            // that expands to the same thing.
            var bldr = tsf.MakeString("de" + orcText, wsEn).GetBldr();

            bldr.SetIntPropValues(2, 2 + orcText.Length, (int)FwTextPropType.ktptWs,
                                  (int)FwTextPropVar.ktpvDefault, wsFrn);
            var clientRunFakeOrc = new TssClientRun(bldr.GetString(), styles);

            clientRuns = new List <IClientRun>();
            clientRuns.Add(clientRun0);
            clientRuns.Add(clientRunFakeOrc);
            clientRuns.Add(clientRun3);
            source = new TextSource(clientRuns, MockInterpretOrc);

            string partDeqOrc = "deq\xfffc";
            var    clientRun5 = new StringClientRun(partDeqOrc, styles);
            var    output3    = source.ClientRunChanged(1, clientRun5);

            Assert.AreEqual(3, output3.NewSource.RenderRuns.Count,
                            "three render runs because ORC interprets as french string.");
            VerifyRenderRun(output3.NewSource.RenderRuns[0], 0, part0.Length + 3, "first run up to ORC");
            VerifyRenderRun(output3.NewSource.RenderRuns[1], part0.Length + 3, orcText.Length, "second run is French from ORC");
            VerifyRenderRun(output3.NewSource.RenderRuns[2], part0.Length + 3 + orcText.Length, part3.Length, "third run is  stuff after ORC");
            VerifyFetch(output3.NewSource, 0, output3.NewSource.Length, part0 + "deq" + orcText + part3);
            // This should be interpreted as inserting the "q" after the "de" and before the orc text.
            Assert.AreEqual(part0.Length + 2, output3.StartChange);
            Assert.AreEqual(0, output3.DeleteCount);
            Assert.AreEqual(1, output3.InsertCount);

            // special case where nothing changes.
            clientRuns = new List <IClientRun>();
            clientRuns.Add(clientRun0);
            clientRuns.Add(clientRun2);
            source = new TextSource(clientRuns, MockInterpretOrc);
            var output4 = source.ClientRunChanged(1, clientRun2);

            Assert.AreEqual(1, output4.NewSource.RenderRuns.Count, "two client runs collapse to one render");
            VerifyRenderRun(output4.NewSource.RenderRuns[0], 0, part0.Length + part2.Length, "run has expected length");
            VerifyFetch(output4.NewSource, 0, output4.NewSource.Length, part0 + part2);
            Assert.AreEqual(part0.Length, output4.StartChange);
            Assert.AreEqual(0, output4.DeleteCount);
            Assert.AreEqual(0, output4.InsertCount);
        }
Ejemplo n.º 2
0
		public void StringChangedTests()
		{
			string part0 = "abc";
			AssembledStyles styles = new AssembledStyles().WithWs(wsEn);
			StringClientRun clientRun0 = new StringClientRun(part0, styles);
			var clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);
			TextSource source = new TextSource(clientRuns);
			List<IRenderRun> renderRuns = source.RenderRuns;
			VerifyRenderRun(renderRuns[0], 0, 3, "initial state has all in one run");
			var clientRun1 = new StringClientRun("abcd", styles);
			var output1 = source.ClientRunChanged(0, clientRun1);
			Assert.AreEqual(1, output1.NewSource.RenderRuns.Count, "replacing single run with simple string should produce single render run.");
			VerifyRenderRun(output1.NewSource.RenderRuns[0], 0, 4, "replacing client run should make a new source with modified single run");
			Assert.AreEqual(3, output1.StartChange);
			Assert.AreEqual(0, output1.DeleteCount);
			Assert.AreEqual(1, output1.InsertCount);

			// try changing the middle of three runs, from a simple one to a complex one.
			clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);
			string part2 = "def";
			var clientRun2 = new StringClientRun(part2, styles);
			clientRuns.Add(clientRun2);
			string part3 = " mnop";
			var clientRun3 = new StringClientRun(part3, styles);
			clientRuns.Add(clientRun3);
			source = new TextSource(clientRuns, MockInterpretOrc);

			string part4 = "q\xfffc";
			var clientRun4 = new StringClientRun(part4, styles);
			var output2 = source.ClientRunChanged(1, clientRun4);
			Assert.AreEqual(3, output2.NewSource.RenderRuns.Count,
							"three render runs because ORC interprets as french string.");
			VerifyRenderRun(output2.NewSource.RenderRuns[0], 0, part0.Length + 1, "first run up to ORC");
			VerifyRenderRun(output2.NewSource.RenderRuns[1], part0.Length + 1, orcText.Length, "second run is French from ORC");
			VerifyRenderRun(output2.NewSource.RenderRuns[2], part0.Length + 1 + orcText.Length, part3.Length, "third run is  stuff after ORC");
			VerifyFetch(output2.NewSource, 0, output2.NewSource.Length, part0 + "q" + orcText + part3);
			Assert.AreEqual(part0.Length, output2.StartChange);
			Assert.AreEqual(part2.Length, output2.DeleteCount);
			Assert.AreEqual(1 + orcText.Length, output2.InsertCount);

			// Now do a variation where some of the new run survives at each end.
			// To catch a tricky special case, we want to replace some regular text with an ORC
			// that expands to the same thing.
			var bldr = tsf.MakeString("de" + orcText, wsEn).GetBldr();
			bldr.SetIntPropValues(2, 2 + orcText.Length, (int)FwTextPropType.ktptWs,
				(int) FwTextPropVar.ktpvDefault, wsFrn);
			var clientRunFakeOrc = new TssClientRun(bldr.GetString(), styles);
			clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);
			clientRuns.Add(clientRunFakeOrc);
			clientRuns.Add(clientRun3);
			source = new TextSource(clientRuns, MockInterpretOrc);

			string partDeqOrc = "deq\xfffc";
			var clientRun5 = new StringClientRun(partDeqOrc, styles);
			var output3 = source.ClientRunChanged(1, clientRun5);
			Assert.AreEqual(3, output3.NewSource.RenderRuns.Count,
							"three render runs because ORC interprets as french string.");
			VerifyRenderRun(output3.NewSource.RenderRuns[0], 0, part0.Length + 3, "first run up to ORC");
			VerifyRenderRun(output3.NewSource.RenderRuns[1], part0.Length + 3, orcText.Length, "second run is French from ORC");
			VerifyRenderRun(output3.NewSource.RenderRuns[2], part0.Length + 3 + orcText.Length, part3.Length, "third run is  stuff after ORC");
			VerifyFetch(output3.NewSource, 0, output3.NewSource.Length, part0 + "deq" + orcText + part3);
			// This should be interpreted as inserting the "q" after the "de" and before the orc text.
			Assert.AreEqual(part0.Length + 2, output3.StartChange);
			Assert.AreEqual(0, output3.DeleteCount);
			Assert.AreEqual(1, output3.InsertCount);

			// special case where nothing changes.
			clientRuns = new List<IClientRun>();
			clientRuns.Add(clientRun0);
			clientRuns.Add(clientRun2);
			source = new TextSource(clientRuns, MockInterpretOrc);
			var output4 = source.ClientRunChanged(1, clientRun2);
			Assert.AreEqual(1, output4.NewSource.RenderRuns.Count, "two client runs collapse to one render");
			VerifyRenderRun(output4.NewSource.RenderRuns[0], 0, part0.Length + part2.Length, "run has expected length");
			VerifyFetch(output4.NewSource, 0, output4.NewSource.Length, part0 + part2);
			Assert.AreEqual(part0.Length, output4.StartChange);
			Assert.AreEqual(0, output4.DeleteCount);
			Assert.AreEqual(0, output4.InsertCount);

		}