public virtual void TestEmpty()
        {
            IntList map = RawParseUtils.LineMap(new byte[] {  }, 0, 0);

            NUnit.Framework.Assert.IsNotNull(map);
            NUnit.Framework.Assert.AreEqual(2, map.Size());
            NUnit.Framework.Assert.AreEqual(int.MinValue, map.Get(0));
            NUnit.Framework.Assert.AreEqual(0, map.Get(1));
        }
Esempio n. 2
0
        public virtual void TestFillTo100()
        {
            IntList i = new IntList();

            i.FillTo(100, int.MinValue);
            NUnit.Framework.Assert.AreEqual(100, i.Size());
            i.Add(3);
            NUnit.Framework.Assert.AreEqual(int.MinValue, i.Get(99));
            NUnit.Framework.Assert.AreEqual(3, i.Get(100));
        }
Esempio n. 3
0
        public virtual void TestToString()
        {
            IntList i = new IntList();

            i.Add(1);
            NUnit.Framework.Assert.AreEqual("[1]", i.ToString());
            i.Add(13);
            i.Add(5);
            NUnit.Framework.Assert.AreEqual("[1, 13, 5]", i.ToString());
        }
        public virtual void TestTwoLineNoLF()
        {
            byte[]  buf = Sharpen.Runtime.GetBytesForString("foo\nbar", "ISO-8859-1");
            IntList map = RawParseUtils.LineMap(buf, 0, buf.Length);

            NUnit.Framework.Assert.AreEqual(4, map.Size());
            NUnit.Framework.Assert.AreEqual(int.MinValue, map.Get(0));
            NUnit.Framework.Assert.AreEqual(0, map.Get(1));
            NUnit.Framework.Assert.AreEqual(4, map.Get(2));
            NUnit.Framework.Assert.AreEqual(buf.Length, map.Get(3));
        }
Esempio n. 5
0
		public virtual void TestEmpty_SpecificCapacity()
		{
			IntList i = new IntList(5);
			NUnit.Framework.Assert.AreEqual(0, i.Size());
			try
			{
				i.Get(0);
				NUnit.Framework.Assert.Fail("Accepted 0 index on empty list");
			}
			catch (IndexOutOfRangeException)
			{
				NUnit.Framework.Assert.IsTrue(true);
			}
		}
Esempio n. 6
0
        public virtual void TestEmpty_SpecificCapacity()
        {
            IntList i = new IntList(5);

            NUnit.Framework.Assert.AreEqual(0, i.Size());
            try
            {
                i.Get(0);
                NUnit.Framework.Assert.Fail("Accepted 0 index on empty list");
            }
            catch (IndexOutOfRangeException)
            {
                NUnit.Framework.Assert.IsTrue(true);
            }
        }
Esempio n. 7
0
        /// <summary>Index the region between <code>[ptr, end)</code> to find line starts.</summary>
        /// <remarks>
        /// Index the region between <code>[ptr, end)</code> to find line starts.
        /// <p>
        /// The returned list is 1 indexed. Index 0 contains
        /// <see cref="int.MinValue">int.MinValue</see>
        /// to pad the list out.
        /// <p>
        /// Using a 1 indexed list means that line numbers can be directly accessed
        /// from the list, so <code>list.get(1)</code> (aka get line 1) returns
        /// <code>ptr</code>.
        /// <p>
        /// The last element (index <code>map.size()-1</code>) always contains
        /// <code>end</code>.
        /// </remarks>
        /// <param name="buf">buffer to scan.</param>
        /// <param name="ptr">
        /// position within the buffer corresponding to the first byte of
        /// line 1.
        /// </param>
        /// <param name="end">1 past the end of the content within <code>buf</code>.</param>
        /// <returns>a line map indexing the start position of each line.</returns>
        public static IntList LineMap(byte[] buf, int ptr, int end)
        {
            // Experimentally derived from multiple source repositories
            // the average number of bytes/line is 36. Its a rough guess
            // to initially size our map close to the target.
            //
            IntList map = new IntList((end - ptr) / 36);

            map.FillTo(1, int.MinValue);
            for (; ptr < end; ptr = NextLF(buf, ptr))
            {
                map.Add(ptr);
            }
            map.Add(end);
            return(map);
        }
Esempio n. 8
0
        public virtual void TestClear()
        {
            IntList i = new IntList();
            int     n = 5;

            for (int v = 0; v < n; v++)
            {
                i.Add(10 + v);
            }
            NUnit.Framework.Assert.AreEqual(n, i.Size());
            i.Clear();
            NUnit.Framework.Assert.AreEqual(0, i.Size());
            try
            {
                i.Get(0);
                NUnit.Framework.Assert.Fail("Accepted 0 index on empty list");
            }
            catch (IndexOutOfRangeException)
            {
                NUnit.Framework.Assert.IsTrue(true);
            }
        }
Esempio n. 9
0
        public virtual void TestSet()
        {
            IntList i = new IntList();

            i.Add(1);
            NUnit.Framework.Assert.AreEqual(1, i.Size());
            NUnit.Framework.Assert.AreEqual(1, i.Get(0));
            i.Set(0, 5);
            NUnit.Framework.Assert.AreEqual(5, i.Get(0));
            try
            {
                i.Set(5, 5);
                NUnit.Framework.Assert.Fail("accepted set of 5 beyond end of list");
            }
            catch (IndexOutOfRangeException)
            {
                NUnit.Framework.Assert.IsTrue(true);
            }
            i.Set(1, 2);
            NUnit.Framework.Assert.AreEqual(2, i.Size());
            NUnit.Framework.Assert.AreEqual(2, i.Get(1));
        }
Esempio n. 10
0
        public virtual void TestAdd_SmallGroup()
        {
            IntList i = new IntList();
            int     n = 5;

            for (int v = 0; v < n; v++)
            {
                i.Add(10 + v);
            }
            NUnit.Framework.Assert.AreEqual(n, i.Size());
            for (int v_1 = 0; v_1 < n; v_1++)
            {
                NUnit.Framework.Assert.AreEqual(10 + v_1, i.Get(v_1));
            }
            try
            {
                i.Get(n);
                NUnit.Framework.Assert.Fail("Accepted out of bound index on list");
            }
            catch (IndexOutOfRangeException)
            {
                NUnit.Framework.Assert.IsTrue(true);
            }
        }
Esempio n. 11
0
 /// <summary>Create a new sequence from an existing content char array.</summary>
 /// <remarks>
 /// Create a new sequence from an existing content char array.
 /// <p/>
 /// The entire array (indexes 0 through length-1) is used as the content.
 /// </remarks>
 /// <param name="input">
 /// the content array. The array is never modified, so passing
 /// through cached arrays is safe.
 /// </param>
 public Text(string input)
 {
     Content = input;
     _lines = LineMap(0, Content.Length);
 }
Esempio n. 12
0
		public virtual void TestFillTo0()
		{
			IntList i = new IntList();
			i.FillTo(0, int.MinValue);
			NUnit.Framework.Assert.AreEqual(0, i.Size());
		}
Esempio n. 13
0
		public virtual void TestAdd_ZeroCapacity()
		{
			IntList i = new IntList(0);
			NUnit.Framework.Assert.AreEqual(0, i.Size());
			i.Add(1);
			NUnit.Framework.Assert.AreEqual(1, i.Get(0));
		}
Esempio n. 14
0
		/// <summary>Index the region between <code>[ptr, end)</code> to find line starts.</summary>
		/// <remarks>
		/// Index the region between <code>[ptr, end)</code> to find line starts.
		/// <p>
		/// The returned list is 1 indexed. Index 0 contains
		/// <see cref="int.MinValue">int.MinValue</see>
		/// to pad the list out.
		/// <p>
		/// Using a 1 indexed list means that line numbers can be directly accessed
		/// from the list, so <code>list.get(1)</code> (aka get line 1) returns
		/// <code>ptr</code>.
		/// <p>
		/// The last element (index <code>map.size()-1</code>) always contains
		/// <code>end</code>.
		/// </remarks>
		/// <param name="buf">buffer to scan.</param>
		/// <param name="ptr">
		/// position within the buffer corresponding to the first byte of
		/// line 1.
		/// </param>
		/// <param name="end">1 past the end of the content within <code>buf</code>.</param>
		/// <returns>a line map indexing the start position of each line.</returns>
		public static IntList LineMap(byte[] buf, int ptr, int end)
		{
			// Experimentally derived from multiple source repositories
			// the average number of bytes/line is 36. Its a rough guess
			// to initially size our map close to the target.
			//
			IntList map = new IntList((end - ptr) / 36);
			map.FillTo(1, int.MinValue);
			for (; ptr < end; ptr = NextLF(buf, ptr))
			{
				map.Add(ptr);
			}
			map.Add(end);
			return map;
		}
Esempio n. 15
0
		public virtual void TestToString()
		{
			IntList i = new IntList();
			i.Add(1);
			NUnit.Framework.Assert.AreEqual("[1]", i.ToString());
			i.Add(13);
			i.Add(5);
			NUnit.Framework.Assert.AreEqual("[1, 13, 5]", i.ToString());
		}
Esempio n. 16
0
		public virtual void TestSet()
		{
			IntList i = new IntList();
			i.Add(1);
			NUnit.Framework.Assert.AreEqual(1, i.Size());
			NUnit.Framework.Assert.AreEqual(1, i.Get(0));
			i.Set(0, 5);
			NUnit.Framework.Assert.AreEqual(5, i.Get(0));
			try
			{
				i.Set(5, 5);
				NUnit.Framework.Assert.Fail("accepted set of 5 beyond end of list");
			}
			catch (IndexOutOfRangeException)
			{
				NUnit.Framework.Assert.IsTrue(true);
			}
			i.Set(1, 2);
			NUnit.Framework.Assert.AreEqual(2, i.Size());
			NUnit.Framework.Assert.AreEqual(2, i.Get(1));
		}
Esempio n. 17
0
		public virtual void TestClear()
		{
			IntList i = new IntList();
			int n = 5;
			for (int v = 0; v < n; v++)
			{
				i.Add(10 + v);
			}
			NUnit.Framework.Assert.AreEqual(n, i.Size());
			i.Clear();
			NUnit.Framework.Assert.AreEqual(0, i.Size());
			try
			{
				i.Get(0);
				NUnit.Framework.Assert.Fail("Accepted 0 index on empty list");
			}
			catch (IndexOutOfRangeException)
			{
				NUnit.Framework.Assert.IsTrue(true);
			}
		}
Esempio n. 18
0
		public virtual void TestFillTo100()
		{
			IntList i = new IntList();
			i.FillTo(100, int.MinValue);
			NUnit.Framework.Assert.AreEqual(100, i.Size());
			i.Add(3);
			NUnit.Framework.Assert.AreEqual(int.MinValue, i.Get(99));
			NUnit.Framework.Assert.AreEqual(3, i.Get(100));
		}
Esempio n. 19
0
		/// <summary>Create a new sequence from an existing content byte array.</summary>
		/// <remarks>
		/// Create a new sequence from an existing content byte array.
		/// <p>
		/// The entire array (indexes 0 through length-1) is used as the content.
		/// </remarks>
		/// <param name="input">
		/// the content array. The array is never modified, so passing
		/// through cached arrays is safe.
		/// </param>
		public RawText(byte[] input)
		{
			content = input;
			lines = RawParseUtils.LineMap(content, 0, content.Length);
		}
Esempio n. 20
0
		public virtual void TestAdd_SmallGroup()
		{
			IntList i = new IntList();
			int n = 5;
			for (int v = 0; v < n; v++)
			{
				i.Add(10 + v);
			}
			NUnit.Framework.Assert.AreEqual(n, i.Size());
			for (int v_1 = 0; v_1 < n; v_1++)
			{
				NUnit.Framework.Assert.AreEqual(10 + v_1, i.Get(v_1));
			}
			try
			{
				i.Get(n);
				NUnit.Framework.Assert.Fail("Accepted out of bound index on list");
			}
			catch (IndexOutOfRangeException)
			{
				NUnit.Framework.Assert.IsTrue(true);
			}
		}