public void ReadsDictionaries() { var reader = ReaderTests.GetReader("d3:foo3:bar3:bari-5ee"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartDictionary, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string key)); Assert.Equal("foo", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string value)); Assert.Equal("bar", value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out key)); Assert.Equal("bar", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out int intValue)); Assert.Equal(-5, intValue); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }
public void ReadsNestedDictionaryContent() { var reader = ReaderTests.GetReader("d3:food3:bari3eee"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartDictionary, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string key)); Assert.Equal("foo", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartDictionary, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out key)); Assert.Equal("bar", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out int intValue)); Assert.Equal(3, intValue); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }
public void ReadsNestedListContent() { var reader = ReaderTests.GetReader("li1eli2ei22el5:Helloei4e6: worldei5ee"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out int value)); Assert.Equal(1, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out value)); Assert.Equal(2, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out value)); Assert.Equal(22, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string stringValue)); Assert.Equal("Hello", stringValue); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out value)); Assert.Equal(4, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out stringValue)); Assert.Equal(" world", stringValue); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out value)); Assert.Equal(5, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }
public void ReadsStrings(string value) { var reader = ReaderTests.GetReader($"{Encoding.UTF8.GetByteCount(value)}:{value}"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string readValue)); Assert.Equal(value, readValue); }
public void ReadsEmptyDictionaries() { var reader = ReaderTests.GetReader("de"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartDictionary, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }
public void ReadsEmptyList() { var reader = ReaderTests.GetReader("le"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }
public void ReadsNestedDictionariesAndLists() { var reader = ReaderTests.GetReader("d4: foold4:bar leeiee0:0:e"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartDictionary, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string key)); Assert.Equal(" foo", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartDictionary, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out key)); Assert.Equal("bar ", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out int intValue)); Assert.Equal(0, intValue); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out key)); Assert.Equal("", key); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.String, reader.TokenType); Assert.True(reader.TryGet(out string value)); Assert.Equal("", value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }
private static Utf8BEncodingReader GetNumberReader(string number) { string bencoded = 'i' + number + 'e'; var reader = ReaderTests.GetReader(bencoded); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.Equal(number, Encoding.UTF8.GetString(reader.ValueSpan)); return(reader); }
public void ReadsList() { var reader = ReaderTests.GetReader("li1ei-2ee"); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.StartList, reader.TokenType); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out int value)); Assert.Equal(1, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.Integer, reader.TokenType); Assert.True(reader.TryGet(out value)); Assert.Equal(-2, value); Assert.True(reader.Read()); Assert.Equal(BEncodingTokenType.End, reader.TokenType); }