示例#1
0
        public virtual void TestCharSequenceInterface()
        {
            const string      s = "0123456789";
            CharTermAttribute t = new CharTermAttribute();

            t.Append(s);

            Assert.AreEqual(s.Length, t.Length);
            Assert.AreEqual("12", t.Subsequence(1, 3 - 1).ToString());     // LUCENENET: Corrected 2nd parameter of Subsequence
            Assert.AreEqual(s, t.Subsequence(0, s.Length - 0).ToString()); // LUCENENET: Corrected 2nd parameter of Subsequence

            Assert.IsTrue(Regex.IsMatch(t.ToString(), "01\\d+"));
            Assert.IsTrue(Regex.IsMatch(t.Subsequence(3, 5 - 3).ToString(), "34")); // LUCENENET: Corrected 2nd parameter of Subsequence

            Assert.AreEqual(s.Substring(3, 4), t.Subsequence(3, 7 - 3).ToString()); // LUCENENET: Corrected 2nd parameter of Subsequence

            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t[i] == s[i]);
            }

            // LUCENENET specific to test indexer
            for (int i = 0; i < s.Length; i++)
            {
                Assert.IsTrue(t[i] == s[i]);
            }
        }
示例#2
0
        public virtual void TestExceptions()
        {
            CharTermAttribute t = new CharTermAttribute();

            t.Append("test");
            Assert.AreEqual("test", t.ToString());

            try
            {
                var _ = t[-1];
                Assert.Fail("Should throw ArgumentOutOfRangeException");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                var _ = t[4];
                Assert.Fail("Should throw ArgumentOutOfRangeException");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                t.Subsequence(0, 5 - 0); // LUCENENET: Corrected 2nd parameter of Subsequence
                Assert.Fail("Should throw ArgumentOutOfRangeException");
            }
            catch (ArgumentOutOfRangeException)
            {
            }

            try
            {
                t.Subsequence(5, 0 - 5); // LUCENENET: Corrected 2nd parameter of Subsequence
                Assert.Fail("Should throw ArgumentOutOfRangeException");
            }
            catch (ArgumentOutOfRangeException)
            {
            }
        }