public void AsUInt16Test()
        {
            // The hash code is the int32 representation of the first 4 bytes
            var objectId = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);

            Assert.Equal(0x914e, objectId.AsUInt16());
            Assert.Equal(0, GitObjectId.Empty.GetHashCode());
        }
        public void ParseHexArrayTest()
        {
            var objectId = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);

            Span <byte> value = stackalloc byte[20];

            objectId.CopyTo(value);
            Assert.True(value.SequenceEqual(this.shaAsByteArray.AsSpan()));
        }
        public void EqualsObjectIdTest()
        {
            var objectId  = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);
            var objectId2 = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);

            // Must be equal to itself
            Assert.True(objectId.Equals(objectId));
            Assert.True(objectId.Equals(objectId2));

            // Not equal to other object ids
            Assert.False(objectId.Equals(GitObjectId.Empty));
        }
Ejemplo n.º 4
0
        public void ParseHexTest()
        {
            var hex = Encoding.ASCII.GetBytes("b62ca2eb0a45dc42a4333a83b35cc3f70aac3cc9");

            byte[] expected = new byte[] { 0xb6, 0x2c, 0xa2, 0xeb, 0x0a, 0x45, 0xdc, 0x42, 0xa4, 0x33, 0x3a, 0x83, 0xb3, 0x5c, 0xc3, 0xf7, 0x0a, 0xac, 0x3c, 0xc9 };

            var hash = GitObjectId.ParseHex(hex);

            byte[] actual = new byte[20];
            hash.CopyTo(actual);

            Assert.True(actual.SequenceEqual(expected));
        }
        public void CopyToUtf16StringTest()
        {
            // Common use case: create the path to the object in the Git object store,
            // e.g. git/objects/[byte 0]/[bytes 1 - 19]
            byte[]      valueAsBytes = Encoding.Unicode.GetBytes("git/objects/00/01020304050607080910111213141516171819");
            Span <char> valueAsChars = MemoryMarshal.Cast <byte, char>(valueAsBytes);

            var objectId = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);

            objectId.CopyAsHex(0, 1, valueAsChars.Slice(12, 1 * 2));
            objectId.CopyAsHex(1, 19, valueAsChars.Slice(15, 19 * 2));

            var path = Encoding.Unicode.GetString(valueAsBytes);

            Assert.Equal("git/objects/4e/912736c27e40b389904d046dc63dc9f578117f", path);
        }
        public void EqualsObjectTest()
        {
            var objectId  = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);
            var objectId2 = GitObjectId.ParseHex(this.shaAsHexAsciiByteArray);

            // Must be equal to itself
            Assert.True(objectId.Equals((object)objectId));
            Assert.True(objectId.Equals((object)objectId2));

            // Not equal to null
            Assert.False(objectId.Equals(null));

            // Not equal to other representations of the object id
            Assert.False(objectId.Equals(this.shaAsHexAsciiByteArray));
            Assert.False(objectId.Equals(this.shaAsByteArray));
            Assert.False(objectId.Equals(shaAsHexString));

            // Not equal to other object ids
            Assert.False(objectId.Equals((object)GitObjectId.Empty));
        }