Example #1
0
        public void TraceFunction()
        {
            var list = new System.Collections.Generic.List <string>();

            using (NHunspellWrapper wrap = new NHunspellWrapper())
            {
                wrap.LogAction = (x, y) =>
                {
                    if (x == typeof(MockSpeller))
                    {
                        list.Add(y);
                    }
                };

                wrap.OverrideType = typeof(MockSpeller).AssemblyQualifiedName;
                wrap.Load(this.affixFile, this.dictFile);
                wrap.Spell("test");
                wrap.Add("test");
            }

            Assert.AreEqual(4, list.Count, string.Join(Environment.NewLine, list.ToArray()));
            Assert.IsTrue(list.Contains("Init"));
            Assert.IsTrue(list.Contains("Spell"));
            Assert.IsTrue(list.Contains("Add"));
            Assert.IsTrue(list.Contains("Free"));
        }
Example #2
0
 public void Construction()
 {
     // Load on construction
     using (NHunspellWrapper wrap = new NHunspellWrapper(this.affixFile, this.dictFile, typeof(MockSpeller).AssemblyQualifiedName))
     {
         Test(wrap);
     }
 }
Example #3
0
 public void Construction()
 {
     // Load on construction
     using (NHunspellWrapper wrap = new NHunspellWrapper(this.affixFile, this.dictFile, typeof(MockSpeller).AssemblyQualifiedName))
     {
         Test(wrap);
     }
 }
Example #4
0
 public void LoadPost()
 {
     // Load after construction
     using (NHunspellWrapper wrap = new NHunspellWrapper())
     {
         wrap.OverrideType = typeof(MockSpeller).AssemblyQualifiedName;
         wrap.Load(this.affixFile, this.dictFile);
         Test(wrap);
     }
 }
Example #5
0
 public void NotInitialized()
 {
     // Never load
     using (NHunspellWrapper wrap = new NHunspellWrapper())
     {
         wrap.OverrideType = typeof(MockSpeller).AssemblyQualifiedName;
         try
         {
             Test(wrap);
         }
         catch (InvalidOperationException inv)
         {
             if (!inv.Message.Contains("Speller not initialized"))
             {
                 throw;
             }
         }
     }
 }
Example #6
0
 public void InvalidType()
 {
     // Invalid type
     using (NHunspellWrapper wrap = new NHunspellWrapper())
     {
         wrap.OverrideType = "failure.type";
         try
         {
             wrap.Load(this.affixFile, this.dictFile);
             Test(wrap);
         }
         catch (ArgumentException argExp)
         {
             if (!argExp.Message.Contains("Invalid Hunspell instance type"))
             {
                 throw;
             }
         }
     }
 }
Example #7
0
 public void InvalidType()
 {
     // Invalid type
     using (NHunspellWrapper wrap = new NHunspellWrapper())
     {
         wrap.OverrideType = "failure.type";
         try
         {
             wrap.Load(this.affixFile, this.dictFile);
             Test(wrap);
         }
         catch (ArgumentException argExp)
         {
             if (!argExp.Message.Contains("Invalid Hunspell instance type"))
             {
                 throw;
             }
         }
     }
 }
Example #8
0
        /// <summary>
        /// Run the wrapper through some tests
        /// </summary>
        /// <param name='wrap'>Wrapper to test</param>
        private static void Test(NHunspellWrapper wrap)
        {
            if (wrap.Spell("notaword"))
            {
                Assert.Fail("notaword should not be considered spelled correctly");
            }

            // It was cached, no change
            wrap.Add("notaword");
            if (wrap.Spell("notaword"))
            {
                Assert.Fail("notaword should not be considered spelled correctly");
            }

            // Clearing the cache
            wrap.Clear();
            if (!wrap.Spell("notaword"))
            {
                Assert.Fail("notaword should be considered spelled correctly");
            }

            if (!wrap.Spell("word"))
            {
                Assert.Fail("word should be considered spelled correctly");
            }

            // Set as valid and test after
            wrap.Add("notaword2");
            if (!wrap.Spell("notaword2"))
            {
                Assert.Fail("notaword2 should be considered spelled correctly");
            }

            if (wrap.IsDisposed)
            {
                Assert.Fail("Wrapper shouldn't be disposed yet");
            }

            string test = string.Empty;

            wrap.LogAction = (x, y) => { test = "done"; };
            wrap.LogAction.Invoke(typeof(WrapperTests), "done");
            if (test != "done")
            {
                Assert.Fail("Unable to change logger, value was " + test);
            }

            test           = null;
            wrap.LogAction = null;
            wrap.LogAction.Invoke(typeof(WrapperTests), "done");
            if (test != null)
            {
                Assert.Fail("Value should not have been set");
            }

            if (wrap.Spell("flushCacheTest"))
            {
                Assert.Fail("flushCacheTest should not be considered spelled correctly");
            }

            if (wrap.DisableCache)
            {
                Assert.Fail("Cache should not be disabled");
            }

            // Limit the cache size, check the word is still not valid
            wrap.CacheSize = 1;
            wrap.Add("flushCacheTest");
            if (!wrap.Spell("flushCacheTest"))
            {
                Assert.Fail("flushCacheTest should be considered spelled correctly");
            }

            if (!wrap.DisableCache)
            {
                Assert.Fail("Cache should be disabled");
            }

            wrap.DisableCache = false;
            if (wrap.DisableCache)
            {
                Assert.Fail("Cache should not be disabled");
            }

            wrap.DisableCache = true;
            if (!wrap.DisableCache)
            {
                Assert.Fail("Cache should be disabled");
            }
        }
Example #9
0
        /// <summary>
        /// The entry-point class for this application.
        /// </summary>
        /// <param name='args'>Command-line arguments</param>
        public static void Main(string[] args)
        {
            bool error = false;

            if (args == null || args.Length != 2)
            {
                Console.WriteLine("Arguments for testing not sent. The arguments are full paths to the aff and dict files (in that order)");
                error = true;
            }
            else
            {
                try
                {
                    // Load on construction
                    using (NHunspellWrapper wrap = new NHunspellWrapper(args[0], args[1]))
                    {
                        Test(wrap);
                    }

                    // Load after construction
                    using (NHunspellWrapper wrap = new NHunspellWrapper())
                    {
                        wrap.Load(args[0], args[1]);
                        Test(wrap);
                    }

                    // Never load
                    using (NHunspellWrapper wrap = new NHunspellWrapper())
                    {
                        try
                        {
                            Test(wrap);
                        }
                        catch (InvalidOperationException inv)
                        {
                            if (!inv.Message.Contains("Speller not initialized"))
                            {
                                throw;
                            }
                        }
                    }

                    // Invalid type
                    using (NHunspellWrapper wrap = new NHunspellWrapper())
                    {
                        wrap.OverrideType = "failure.type";
                        try
                        {
                            wrap.Load(args[0], args[1]);
                            Test(wrap);
                        }
                        catch (ArgumentException argExp)
                        {
                            if (!argExp.Message.Contains("Invalid Hunspell instance type"))
                            {
                                throw;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    error = true;
                }
            }

            if (error)
            {
                System.Environment.Exit(1);
            }
        }
Example #10
0
 public void LoadPost()
 {
     // Load after construction
     using (NHunspellWrapper wrap = new NHunspellWrapper())
     {
         wrap.OverrideType = typeof(MockSpeller).AssemblyQualifiedName;
         wrap.Load(this.affixFile, this.dictFile);
         Test(wrap);
     }
 }
Example #11
0
        /// <summary>
        /// Run the wrapper through some tests
        /// </summary>
        /// <param name='wrap'>Wrapper to test</param>
        private static void Test(NHunspellWrapper wrap)
        {
            if (wrap.Spell("notaword"))
            {
                Assert.Fail("notaword should not be considered spelled correctly");
            }

            // It was cached, no change
            wrap.Add("notaword");
            if (wrap.Spell("notaword"))
            {
                Assert.Fail("notaword should not be considered spelled correctly");
            }

            // Clearing the cache
            wrap.Clear();
            if (!wrap.Spell("notaword"))
            {
                Assert.Fail("notaword should be considered spelled correctly");
            }

            if (!wrap.Spell("word"))
            {
                Assert.Fail("word should be considered spelled correctly");
            }

            // Set as valid and test after
            wrap.Add("notaword2");
            if (!wrap.Spell("notaword2"))
            {
                Assert.Fail("notaword2 should be considered spelled correctly");
            }

            if (wrap.IsDisposed)
            {
                Assert.Fail("Wrapper shouldn't be disposed yet");
            }

            string test = string.Empty;
            wrap.LogAction = (x, y) => { test = "done"; };
            wrap.LogAction.Invoke(typeof(WrapperTests), "done");
            if (test != "done")
            {
                Assert.Fail("Unable to change logger, value was " + test);
            }

            test = null;
            wrap.LogAction = null;
            wrap.LogAction.Invoke(typeof(WrapperTests), "done");
            if (test != null)
            {
                Assert.Fail("Value should not have been set");
            }

            if (wrap.Spell("flushCacheTest"))
            {
                Assert.Fail("flushCacheTest should not be considered spelled correctly");
            }

            if (wrap.DisableCache)
            {
                Assert.Fail("Cache should not be disabled");
            }

            // Limit the cache size, check the word is still not valid
            wrap.CacheSize = 1;
            wrap.Add("flushCacheTest");
            if (!wrap.Spell("flushCacheTest"))
            {
                Assert.Fail("flushCacheTest should be considered spelled correctly");
            }

            if (!wrap.DisableCache)
            {
                Assert.Fail("Cache should be disabled");
            }

            wrap.DisableCache = false;
            if (wrap.DisableCache)
            {
                Assert.Fail("Cache should not be disabled");
            }

            wrap.DisableCache = true;
            if (!wrap.DisableCache)
            {
                Assert.Fail("Cache should be disabled");
            }
        }
Example #12
0
        public void TraceFunctionAttached()
        {
            var list = new System.Collections.Generic.List<string>();
            Log log = (x, y) =>
            {
                if (x == typeof(MockSpeller))
                {
                    list.Add(y);
                }
            };

            using (NHunspellWrapper wrap = new NHunspellWrapper(this.affixFile, this.dictFile, typeof(MockSpeller).AssemblyQualifiedName, log))
            {
                wrap.Spell("test");
                wrap.Add("test");
            }

            Assert.AreEqual(4, list.Count, string.Join(Environment.NewLine, list.ToArray()));
            Assert.IsTrue(list.Contains("Init"));
            Assert.IsTrue(list.Contains("Spell"));
            Assert.IsTrue(list.Contains("Add"));
            Assert.IsTrue(list.Contains("Free"));
        }
Example #13
0
 public void NotInitialized()
 {
     // Never load
     using (NHunspellWrapper wrap = new NHunspellWrapper())
     {
         wrap.OverrideType = typeof(MockSpeller).AssemblyQualifiedName;
         try
         {
             Test(wrap);
         }
         catch (InvalidOperationException inv)
         {
             if (!inv.Message.Contains("Speller not initialized"))
             {
                 throw;
             }
         }
     }
 }