public void testMerge_HeadMaster() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headU = newRef("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref headR = newRef("HEAD", master); loose = toList(headU, master); resolved = toList(headR); RefMap map = new RefMap("", packed, loose, resolved); Assert.AreEqual(2, map.size()); Assert.IsFalse(map.isEmpty()); Assert.IsTrue(map.containsKey("refs/heads/master")); Assert.AreSame(master, map.get("refs/heads/master")); // resolved overrides loose given same name Assert.AreSame(headR, map.get("HEAD")); IteratorBase <global::GitSharp.Core.Ref> itr = map.values().iterator(); Assert.IsTrue(itr.hasNext()); Assert.AreSame(headR, itr.next()); Assert.IsTrue(itr.hasNext()); Assert.AreSame(master, itr.next()); Assert.IsFalse(itr.hasNext()); }
public void testClear() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); loose = toList(master); RefMap map = new RefMap("", packed, loose, resolved); Assert.AreSame(master, map.get("refs/heads/master")); map.clear(); Assert.IsNull(map.get("refs/heads/master")); Assert.IsTrue(map.isEmpty()); Assert.AreEqual(0, map.size()); }
public void testPut_CollapseResolved() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headU = newRef("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref headR = newRef("HEAD", master); global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE); loose = toList(headU, master); resolved = toList(headR); RefMap map = new RefMap("", packed, loose, resolved); Assert.IsNull(map.put(a.getName(), a)); Assert.AreSame(a, map.get(a.getName())); Assert.AreSame(headR, map.get("HEAD")); }
public void testEntryTypeSet() { global::GitSharp.Core.Ref refA_one = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref refA_two = newRef("refs/heads/A", ID_TWO); packed = toList(refA_one); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); Assert.AreSame(refA_one, map.get("A")); RefMap.Ent ent = map.entrySet().iterator().next(); Assert.AreEqual("A", ent.getKey()); Assert.AreSame(refA_one, ent.getValue()); Assert.AreSame(refA_one, ent.setValue(refA_two)); Assert.AreSame(refA_two, ent.getValue()); Assert.AreSame(refA_two, map.get("A")); Assert.AreEqual(1, map.size()); }
public void testPut_WithPrefix() { global::GitSharp.Core.Ref refA_one = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref refA_two = newRef("refs/heads/A", ID_TWO); packed = toList(refA_one); RefMap map = new RefMap("refs/heads/", packed, loose, resolved); Assert.AreSame(refA_one, map.get("A")); Assert.AreSame(refA_one, map.put("A", refA_two)); // map changed, but packed, loose did not Assert.AreSame(refA_two, map.get("A")); Assert.AreSame(refA_one, packed.get(0)); Assert.AreEqual(0, loose.size()); Assert.AreSame(refA_two, map.put("A", refA_one)); Assert.AreSame(refA_one, map.get("A")); }
public void testEmpty_NoPrefix1() { RefMap map = new RefMap("", packed, loose, resolved); Assert.IsTrue(map.isEmpty()); // before size was computed Assert.AreEqual(0, map.size()); Assert.IsTrue(map.isEmpty()); // after size was computed Assert.IsFalse(map.entrySet().iterator().hasNext()); Assert.IsFalse(map.keySet().iterator().hasNext()); Assert.IsFalse(map.containsKey("a")); Assert.IsNull(map.get("a")); }
public void testEmpty_NoPrefix2() { RefMap map = new RefMap(); Assert.IsTrue(map.isEmpty()); // before size was computed Assert.AreEqual(0, map.size()); Assert.IsTrue(map.isEmpty()); // after size was computed Assert.IsFalse(map.entrySet().iterator().hasNext()); Assert.IsFalse(map.keySet().iterator().hasNext()); Assert.IsFalse(map.containsKey("a")); Assert.IsNull(map.get("a")); }
public void testRemove() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headU = newRef("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref headR = newRef("HEAD", master); packed = toList(master); loose = toList(headU, master); resolved = toList(headR); RefMap map = new RefMap("", packed, loose, resolved); Assert.IsNull(map.remove("not.a.reference")); Assert.AreSame(master, map.remove("refs/heads/master")); Assert.IsNull(map.get("refs/heads/master")); Assert.AreSame(headR, map.remove("HEAD")); Assert.IsNull(map.get("HEAD")); Assert.IsTrue(map.isEmpty()); }
public void testMerge_WithPrefix() { global::GitSharp.Core.Ref a = newRef("refs/heads/A", ID_ONE); global::GitSharp.Core.Ref b = newRef("refs/heads/foo/bar/B", ID_TWO); global::GitSharp.Core.Ref c = newRef("refs/heads/foo/rab/C", ID_TWO); global::GitSharp.Core.Ref g = newRef("refs/heads/g", ID_ONE); packed = toList(a, b, c, g); RefMap map = new RefMap("refs/heads/foo/", packed, loose, resolved); Assert.AreEqual(2, map.size()); Assert.AreSame(b, map.get("bar/B")); Assert.AreSame(c, map.get("rab/C")); Assert.IsNull(map.get("refs/heads/foo/bar/B")); Assert.IsNull(map.get("refs/heads/A")); Assert.IsTrue(map.containsKey("bar/B")); Assert.IsTrue(map.containsKey("rab/C")); Assert.IsFalse(map.containsKey("refs/heads/foo/bar/B")); Assert.IsFalse(map.containsKey("refs/heads/A")); IteratorBase<RefMap.Ent> itr = map.entrySet().iterator(); RefMap.Ent ent; Assert.IsTrue(itr.hasNext()); ent = itr.next(); Assert.AreEqual("bar/B", ent.getKey()); Assert.AreSame(b, ent.getValue()); Assert.IsTrue(itr.hasNext()); ent = itr.next(); Assert.AreEqual("rab/C", ent.getKey()); Assert.AreSame(c, ent.getValue()); Assert.IsFalse(itr.hasNext()); }
public void testMerge_PackedLooseLoose() { global::GitSharp.Core.Ref refA = newRef("A", ID_ONE); global::GitSharp.Core.Ref refB_ONE = newRef("B", ID_ONE); global::GitSharp.Core.Ref refB_TWO = newRef("B", ID_TWO); global::GitSharp.Core.Ref refc = newRef("c", ID_ONE); packed = toList(refA, refB_ONE); loose = toList(refB_TWO, refc); RefMap map = new RefMap("", packed, loose, resolved); Assert.AreEqual(3, map.size()); Assert.IsFalse(map.isEmpty()); Assert.IsTrue(map.containsKey(refA.Name)); Assert.AreSame(refA, map.get(refA.Name)); // loose overrides packed given same name Assert.AreSame(refB_TWO, map.get(refB_ONE.Name)); var itr = map.values().iterator(); Assert.IsTrue(itr.hasNext()); Assert.AreSame(refA, itr.next()); Assert.IsTrue(itr.hasNext()); Assert.AreSame(refB_TWO, itr.next()); Assert.IsTrue(itr.hasNext()); Assert.AreSame(refc, itr.next()); Assert.IsFalse(itr.hasNext()); }
public void testMerge_HeadMaster() { global::GitSharp.Core.Ref master = newRef("refs/heads/master", ID_ONE); global::GitSharp.Core.Ref headU = newRef("HEAD", "refs/heads/master"); global::GitSharp.Core.Ref headR = newRef("HEAD", master); loose = toList(headU, master); resolved = toList(headR); RefMap map = new RefMap("", packed, loose, resolved); Assert.AreEqual(2, map.size()); Assert.IsFalse(map.isEmpty()); Assert.IsTrue(map.containsKey("refs/heads/master")); Assert.AreSame(master, map.get("refs/heads/master")); // resolved overrides loose given same name Assert.AreSame(headR, map.get("HEAD")); IteratorBase<global::GitSharp.Core.Ref> itr = map.values().iterator(); Assert.IsTrue(itr.hasNext()); Assert.AreSame(headR, itr.next()); Assert.IsTrue(itr.hasNext()); Assert.AreSame(master, itr.next()); Assert.IsFalse(itr.hasNext()); }