Exemple #1
0
 /// <summary>
 /// Copy the prototype token's fields into this one. Note: Payloads are shared. </summary>
 /// <param name="prototype"> source Token to copy fields from </param>
 public virtual void Reinit(Token prototype)
 {
     CopyBuffer(prototype.Buffer(), 0, prototype.Length);
     positionIncrement = prototype.positionIncrement;
     flags             = prototype.flags;
     startOffset       = prototype.startOffset;
     endOffset         = prototype.endOffset;
     type    = prototype.type;
     payload = prototype.payload;
 }
Exemple #2
0
        public virtual void TestResize()
        {
            Token t = new Token();

            char[] content = "hello".ToCharArray();
            t.CopyBuffer(content, 0, content.Length);
            for (int i = 0; i < 2000; i++)
            {
                t.ResizeBuffer(i);
                Assert.IsTrue(i <= t.Buffer().Length);
                Assert.AreEqual("hello", t.ToString());
            }
        }
Exemple #3
0
        public virtual void TestMixedStringArray()
        {
            Token t = new Token("hello", 0, 5);

            Assert.AreEqual(t.Length, 5);
            Assert.AreEqual(t.ToString(), "hello");
            t.SetEmpty().Append("hello2");
            Assert.AreEqual(t.Length, 6);
            Assert.AreEqual(t.ToString(), "hello2");
            t.CopyBuffer("hello3".ToCharArray(), 0, 6);
            Assert.AreEqual(t.ToString(), "hello3");

            char[] buffer = t.Buffer();
            buffer[1] = 'o';
            Assert.AreEqual(t.ToString(), "hollo3");
        }
Exemple #4
0
        public virtual void TestClone()
        {
            Token t = new Token(0, 5);

            char[] content = "hello".ToCharArray();
            t.CopyBuffer(content, 0, 5);
            char[] buf  = t.Buffer();
            Token  copy = AssertCloneIsEqual(t);

            Assert.AreEqual(t.ToString(), copy.ToString());
            Assert.AreNotSame(buf, copy.Buffer());

            BytesRef pl = new BytesRef(new sbyte[] { 1, 2, 3, 4 });

            t.Payload = pl;
            copy      = AssertCloneIsEqual(t);
            Assert.AreEqual(pl, copy.Payload);
            Assert.AreNotSame(pl, copy.Payload);
        }
Exemple #5
0
        public virtual void TestCtor()
        {
            Token t = new Token();

            char[] content = "hello".ToCharArray();
            t.CopyBuffer(content, 0, content.Length);
            Assert.AreNotSame(t.Buffer(), content);
            Assert.AreEqual(0, t.StartOffset());
            Assert.AreEqual(0, t.EndOffset());
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual("word", t.Type);
            Assert.AreEqual(0, t.Flags);

            t = new Token(6, 22);
            t.CopyBuffer(content, 0, content.Length);
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual(6, t.StartOffset());
            Assert.AreEqual(22, t.EndOffset());
            Assert.AreEqual("word", t.Type);
            Assert.AreEqual(0, t.Flags);

            t = new Token(6, 22, 7);
            t.CopyBuffer(content, 0, content.Length);
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual(6, t.StartOffset());
            Assert.AreEqual(22, t.EndOffset());
            Assert.AreEqual("word", t.Type);
            Assert.AreEqual(7, t.Flags);

            t = new Token(6, 22, "junk");
            t.CopyBuffer(content, 0, content.Length);
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual("hello", t.ToString());
            Assert.AreEqual(6, t.StartOffset());
            Assert.AreEqual(22, t.EndOffset());
            Assert.AreEqual("junk", t.Type);
            Assert.AreEqual(0, t.Flags);
        }