Exemple #1
0
        public void testFindContainsGet()
        {
            RefList <global::GitSharp.Core.Ref> list = toList(REF_A, REF_B, REF_c);

            Assert.AreEqual(0, list.find("A"));
            Assert.AreEqual(1, list.find("B"));
            Assert.AreEqual(2, list.find("c"));

            Assert.AreEqual(-1, list.find("0"));
            Assert.AreEqual(-2, list.find("AB"));
            Assert.AreEqual(-3, list.find("a"));
            Assert.AreEqual(-4, list.find("z"));

            Assert.AreSame(REF_A, list.get("A"));
            Assert.AreSame(REF_B, list.get("B"));
            Assert.AreSame(REF_c, list.get("c"));
            Assert.IsNull(list.get("AB"));
            Assert.IsNull(list.get("z"));

            Assert.IsTrue(list.contains("A"));
            Assert.IsTrue(list.contains("B"));
            Assert.IsTrue(list.contains("c"));
            Assert.IsFalse(list.contains("AB"));
            Assert.IsFalse(list.contains("z"));
        }
Exemple #2
0
        public void testEmptyBuilder()
        {
            RefList <global::GitSharp.Core.Ref> list = new RefList <global::GitSharp.Core.Ref> .Builder <global::GitSharp.Core.Ref>().toRefList();

            Assert.AreEqual(0, list.size());
            Assert.IsFalse(list.iterator().hasNext());
            Assert.AreEqual(-1, list.find("a"));
            Assert.AreEqual(-1, list.find("z"));
            Assert.IsFalse(list.contains("a"));
            Assert.IsNull(list.get("a"));
            Assert.IsTrue(list.asList().Count == 0);
            Assert.AreEqual("[]", list.ToString());

            // default array capacity should be 16, with no bounds checking.
            Assert.IsNull(list.get(16 - 1));
            try
            {
                list.get(16);
                Assert.Fail("default RefList should have 16 element array");
            }
            catch (IndexOutOfRangeException)
            {
                // expected
            }
        }
Exemple #3
0
        public void testEmpty()
        {
            RefList <global::GitSharp.Core.Ref> list = RefList <global::GitSharp.Core.Ref> .emptyList();

            Assert.AreEqual(0, list.size());
            Assert.IsTrue(list.isEmpty());
            Assert.IsFalse(list.iterator().hasNext());
            Assert.AreEqual(-1, list.find("a"));
            Assert.AreEqual(-1, list.find("z"));
            Assert.IsFalse(list.contains("a"));
            Assert.IsNull(list.get("a"));
            try
            {
                list.get(0);
                Assert.Fail("RefList.emptyList should have 0 element array");
            }
            catch (IndexOutOfRangeException)
            {
                // expected
            }
        }
        public override bool isNameConflicting(string name)
        {
            RefList <Ref>      packed = getPackedRefs();
            RefList <LooseRef> loose  = getLooseRefs();

            // Cannot be nested within an existing reference.
            int lastSlash = name.LastIndexOf('/');

            while (0 < lastSlash)
            {
                string needle = name.Slice(0, lastSlash);
                if (loose.contains(needle) || packed.contains(needle))
                {
                    return(true);
                }
                lastSlash = name.LastIndexOf('/', lastSlash - 1);
            }

            // Cannot be the container of an existing reference.
            string prefix = name + '/';
            int    idx;

            idx = -(packed.find(prefix) + 1);
            if (idx < packed.size() && packed.get(idx).getName().StartsWith(prefix))
            {
                return(true);
            }

            idx = -(loose.find(prefix) + 1);
            if (idx < loose.size() && loose.get(idx).getName().StartsWith(prefix))
            {
                return(true);
            }

            return(false);
        }
Exemple #5
0
        public void testEmptyBuilder()
        {
            RefList<global::GitSharp.Core.Ref> list = new RefList<global::GitSharp.Core.Ref>.Builder<global::GitSharp.Core.Ref>().toRefList();
            Assert.AreEqual(0, list.size());
            Assert.IsFalse(list.iterator().hasNext());
            Assert.AreEqual(-1, list.find("a"));
            Assert.AreEqual(-1, list.find("z"));
            Assert.IsFalse(list.contains("a"));
            Assert.IsNull(list.get("a"));
            Assert.IsTrue(list.asList().Count == 0);
            Assert.AreEqual("[]", list.ToString());

            // default array capacity should be 16, with no bounds checking.
            Assert.IsNull(list.get(16 - 1));
            try
            {
                list.get(16);
                Assert.Fail("default RefList should have 16 element array");
            }
            catch (IndexOutOfRangeException err)
            {
                // expected
            }
        }