Example #1
0
        public void Decode_HandlesNegativeZero()
        {
            var encoded = Base64.Encode((byte)(StructureByte(0) | 0x1)).ToString();

            Assert.That(VlqDecoder.Decode(ref encoded), Is.EqualTo(0));
            Assert.That(encoded, Is.EqualTo(string.Empty));
        }
Example #2
0
        public void Decode_AmendsInputStringForUnprocessedTokens()
        {
            var encoded = "6rk2BxhsuC";

            Assert.That(VlqDecoder.Decode(ref encoded), Is.EqualTo(886973));
            Assert.That(encoded, Is.EqualTo("xhsuC"));
        }
Example #3
0
        public void Decode_HandlesMultiDigitPositiveValues()
        {
            // Example encoded value from http://qfox.nl/weblog/281
            var encoded = "6rk2B";

            Assert.That(VlqDecoder.Decode(ref encoded), Is.EqualTo(886973));
        }
Example #4
0
        public void Decode_HandlesSinglePositiveValues()
        {
            var encoded = Base64.Encode(StructureByte(12)).ToString();

            Assert.That(VlqDecoder.Decode(ref encoded), Is.EqualTo(12));
            Assert.That(encoded, Is.EqualTo(string.Empty));
        }
Example #5
0
 public MappingSegment(int generatedLineIndex, string encodedFields)
 {
     GeneratedLineIndex   = generatedLineIndex;
     GeneratedColumnIndex = VlqDecoder.Decode(ref encodedFields);
     SourcesIndex         = GetNextValue(ref encodedFields);
     SourceLineIndex      = GetNextValue(ref encodedFields);
     SourceColumnIndex    = GetNextValue(ref encodedFields);
     NamesIndex           = GetNextValue(ref encodedFields);
 }
Example #6
0
        public void Decode_HandlesMultiDigitNegativeValues()
        {
            var encoded = "xhsuC";

            Assert.That(VlqDecoder.Decode(ref encoded), Is.EqualTo(-1284120));
        }
Example #7
0
        public void Decode_ThrowsArgumentException_IfContinuationTokenButNoRemainingChars()
        {
            var encoded = Base64.Encode(63).ToString();

            Assert.Throws(typeof(ArgumentException), () => VlqDecoder.Decode(ref encoded));
        }
Example #8
0
        public void Decode_ThrowsArgumentException_IfNoCharsInInputString()
        {
            var empty = string.Empty;

            Assert.Throws(typeof(ArgumentException), () => VlqDecoder.Decode(ref empty));
        }
Example #9
0
 private static int?GetNextValue(ref string encoded)
 {
     return(encoded.Length == 0 ? null : (int?)VlqDecoder.Decode(ref encoded));
 }