Class to support displaying the context(s) for a character string.
Inheritance: System.Windows.Forms.UserControl
Ejemplo n.º 1
0
        public void GetTokenSubstrings_ValidatorThatRemovesSomeResults()
        {
            using (var ctrl = new CharContextCtrl())
            {
                ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
                                null, null, null, null);
                ctrl.ListValidator = RemoveFirstAndLastSubString;

                var        tokens = new List <ITextToken>();
                ITextToken token  = new ScrCheckingToken();
                ReflectionHelper.SetField(token, "m_sText", "Mom. Dad! Brother(Sister)");
                tokens.Add(token);
                var inventory = new DummyScrInventory
                {
                    m_references = new List <TextTokenSubstring>
                    {
                        new TextTokenSubstring(token, 3, 2),
                        new TextTokenSubstring(token, 8, 2),
                        new TextTokenSubstring(token, 17, 1),
                        new TextTokenSubstring(token, 24, 1)
                    }
                };
                var validatedList =
                    (List <TextTokenSubstring>)ReflectionHelper.GetResult(ctrl, "GetTokenSubstrings",
                                                                          inventory, tokens);
                Assert.AreEqual(2, validatedList.Count);
                Assert.AreEqual("! ", validatedList[0].Text);
                Assert.AreEqual("(", validatedList[1].Text);
            }
        }
Ejemplo n.º 2
0
        public void GetTokenSubstrings_ValidatorThatRemovesSomeResults()
        {
            CharContextCtrl ctrl = new CharContextCtrl();

            ctrl.Cache         = Cache;
            ctrl.ListValidator = RemoveFirstAndLastSubString;

            List <ITextToken> tokens = new List <ITextToken>();
            ITextToken        token  = new ScrCheckingToken();

            ReflectionHelper.SetField(token, "m_sText", "Mom. Dad! Brother(Sister)");
            tokens.Add(token);
            DummyScrInventory inventory = new DummyScrInventory();

            inventory.m_references = new List <TextTokenSubstring>();
            inventory.m_references.Add(new TextTokenSubstring(token, 3, 2));
            inventory.m_references.Add(new TextTokenSubstring(token, 8, 2));
            inventory.m_references.Add(new TextTokenSubstring(token, 17, 1));
            inventory.m_references.Add(new TextTokenSubstring(token, 24, 1));
            List <TextTokenSubstring> validatedList =
                (List <TextTokenSubstring>)ReflectionHelper.GetResult(ctrl, "GetTokenSubstrings",
                                                                      inventory, tokens);

            Assert.AreEqual(2, validatedList.Count);
            Assert.AreEqual("! ", validatedList[0].Text);
            Assert.AreEqual("(", validatedList[1].Text);
        }
Ejemplo n.º 3
0
        public void NormalizeFileData_Hebrew()
        {
            using (var ctrl = new CharContextCtrl())
            {
                ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
                                null, null, null, null);

                // First string is the normalized order that ICU produces.
                // Second string is the normalized order that .Net produces.
                var icuStyleNormalizationOrder    = "\u05E9\u05c1\u05b4\u0596";
                var dotnetStyleNormalizationOrder = "\u05E9\u05b4\u05c1\u0596";
                ReflectionHelper.SetField(ctrl, "m_fileData",
                                          new[] { icuStyleNormalizationOrder, dotnetStyleNormalizationOrder });

                // SUT
                ReflectionHelper.CallMethod(ctrl, "NormalizeFileData");

                // Verify
                var results = (string[])ReflectionHelper.GetField(ctrl, "m_fileData");
                Assert.That(results.Length, Is.EqualTo(2));
                Assert.That(results[0], Is.EqualTo(icuStyleNormalizationOrder),
                            GetMessage("Expect ICU-style normalization (from ICU order)",
                                       icuStyleNormalizationOrder,
                                       results[0]));
                Assert.That(results[1], Is.EqualTo(icuStyleNormalizationOrder),
                            GetMessage("Expect ICU-style normalization (from .NET order)",
                                       icuStyleNormalizationOrder,
                                       results[1]));
            }
        }
Ejemplo n.º 4
0
        public void NormalizeFileData_EnsureNFD()
        {
            CharContextCtrl ctrl = new CharContextCtrl();

            // First string is the normalized order that ICU produces.
            // Second string is the normalized order that .Net produces.
            ReflectionHelper.SetField(ctrl, "m_fileData", new string[] { "\u2074" });
            ReflectionHelper.SetProperty(ctrl, "Cache", Cache);

            ReflectionHelper.CallMethod(ctrl, "NormalizeFileData");

            string[] results = (string[])ReflectionHelper.GetField(ctrl, "m_fileData");
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual("\u2074", results[0], "Expect ICU-style normalization");
        }
Ejemplo n.º 5
0
        public void NormalizeFileData_EnsureNFD()
        {
            using (var ctrl = new CharContextCtrl())
            {
                ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
                                null, null, null, null);

                // First string is the normalized order that ICU produces.
                // Second string is the normalized order that .Net produces.
                ReflectionHelper.SetField(ctrl, "m_fileData", new[] { "\u2074" });

                ReflectionHelper.CallMethod(ctrl, "NormalizeFileData");

                var results = (string[])ReflectionHelper.GetField(ctrl, "m_fileData");
                Assert.AreEqual(1, results.Length);
                Assert.AreEqual("\u2074", results[0], "Expect ICU-style normalization");
            }
        }
Ejemplo n.º 6
0
        public void NormalizeFileData_EnsureNFD()
        {
            using (var ctrl = new CharContextCtrl())
            {
                ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
                                null, null, null, null);

                ReflectionHelper.SetField(ctrl, "m_fileData", new[] { "\u2074" });

                // SUT
                ReflectionHelper.CallMethod(ctrl, "NormalizeFileData");

                // Verify
                var results = (string[])ReflectionHelper.GetField(ctrl, "m_fileData");
                Assert.That(results.Length, Is.EqualTo(1));
                Assert.That(results[0], Is.EqualTo("\u2074"), "Expect ICU-style normalization");
            }
        }
Ejemplo n.º 7
0
        public void GetTokenSubstrings_NoValidator()
        {
            CharContextCtrl ctrl = new CharContextCtrl();

            ctrl.Cache = Cache;

            List <ITextToken> tokens = new List <ITextToken>();
            ITextToken        token  = new ScrCheckingToken();

            ReflectionHelper.SetField(token, "m_sText", "Mom. Dad!");
            tokens.Add(token);
            DummyScrInventory inventory = new DummyScrInventory();

            inventory.m_references = new List <TextTokenSubstring>();
            inventory.m_references.Add(new TextTokenSubstring(token, 3, 2));
            List <TextTokenSubstring> validatedList =
                (List <TextTokenSubstring>)ReflectionHelper.GetResult(ctrl, "GetTokenSubstrings",
                                                                      inventory, tokens);

            Assert.AreEqual(1, validatedList.Count);
            Assert.AreEqual(". ", validatedList[0].Text);
        }
Ejemplo n.º 8
0
        public void GetTokenSubstrings_NoValidator()
        {
            using (var ctrl = new CharContextCtrl())
            {
                ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
                                null, null, null, null);

                var        tokens = new List <ITextToken>();
                ITextToken token  = new ScrCheckingToken();
                ReflectionHelper.SetField(token, "m_sText", "Mom. Dad!");
                tokens.Add(token);
                var inventory = new DummyScrInventory
                {
                    m_references = new List <TextTokenSubstring>
                    {
                        new TextTokenSubstring(token, 3, 2)
                    }
                };
                var validatedList = (List <TextTokenSubstring>)ReflectionHelper.GetResult(ctrl, "GetTokenSubstrings",
                                                                                          inventory, tokens);
                Assert.AreEqual(1, validatedList.Count);
                Assert.AreEqual(". ", validatedList[0].Text);
            }
        }
Ejemplo n.º 9
0
		public void GetTokenSubstrings_ValidatorThatRemovesSomeResults()
		{
			using (var ctrl = new CharContextCtrl())
			{
				ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
					null, null, null, null);
				ctrl.ListValidator = RemoveFirstAndLastSubString;

				var tokens = new List<ITextToken>();
				ITextToken token = new ScrCheckingToken();
				ReflectionHelper.SetField(token, "m_sText", "Mom. Dad! Brother(Sister)");
				tokens.Add(token);
				var inventory = new DummyScrInventory
									{
										m_references = new List<TextTokenSubstring>
														{
															new TextTokenSubstring(token, 3, 2),
															new TextTokenSubstring(token, 8, 2),
															new TextTokenSubstring(token, 17, 1),
															new TextTokenSubstring(token, 24, 1)
														}
									};
				var validatedList =
					(List<TextTokenSubstring>)ReflectionHelper.GetResult(ctrl, "GetTokenSubstrings",
					inventory, tokens);
				Assert.AreEqual(2, validatedList.Count);
				Assert.AreEqual("! ", validatedList[0].Text);
				Assert.AreEqual("(", validatedList[1].Text);
			}
		}
Ejemplo n.º 10
0
		public void GetTokenSubstrings_NoValidator()
		{
			using (var ctrl = new CharContextCtrl())
			{
				ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
					null, null, null, null);

				var tokens = new List<ITextToken>();
				ITextToken token = new ScrCheckingToken();
				ReflectionHelper.SetField(token, "m_sText", "Mom. Dad!");
				tokens.Add(token);
				var inventory = new DummyScrInventory
													{
														m_references = new List<TextTokenSubstring>
															{ new TextTokenSubstring(token, 3, 2) }
													};
				var validatedList = (List<TextTokenSubstring>)ReflectionHelper.GetResult(ctrl, "GetTokenSubstrings",
					inventory, tokens);
				Assert.AreEqual(1, validatedList.Count);
				Assert.AreEqual(". ", validatedList[0].Text);
			}
		}
Ejemplo n.º 11
0
		public void NormalizeFileData_EnsureNFD()
		{
			using (var ctrl = new CharContextCtrl())
			{
				ctrl.Initialize(Cache, Cache.ServiceLocator.WritingSystems,
					null, null, null, null);

				// First string is the normalized order that ICU produces.
				// Second string is the normalized order that .Net produces.
				ReflectionHelper.SetField(ctrl, "m_fileData", new[] { "\u2074" });

				ReflectionHelper.CallMethod(ctrl, "NormalizeFileData");

				var results = (string[])ReflectionHelper.GetField(ctrl, "m_fileData");
				Assert.AreEqual(1, results.Length);
				Assert.AreEqual("\u2074", results[0], "Expect ICU-style normalization");
			}
		}