コード例 #1
0
        public void ZeroLengthSpanFromEmptyStringDoesNotStoreDataBuffer()
        {
            var span = new Utf8ByteSpan("");

            Assert.Equal(0, span.Length);
            Assert.Null(span.Data);
        }
コード例 #2
0
        public void ZeroLengthSpanDoesNotStoreDataBuffer()
        {
            var span = new Utf8ByteSpan(new byte[100], 1, 0);

            Assert.Equal(0, span.Length);
            Assert.Null(span.Data);
        }
コード例 #3
0
        public void SpanWithOffsetToString()
        {
            var s     = "olé";
            var bytes = Encoding.UTF8.GetBytes("zz" + s + "!");
            var span  = new Utf8ByteSpan(bytes, 2, bytes.Length - 3);

            Assert.Equal(s, span.GetString());
        }
コード例 #4
0
        public void SpanToString()
        {
            var s     = "olé";
            var bytes = Encoding.UTF8.GetBytes(s);
            var span  = new Utf8ByteSpan(bytes, 0, bytes.Length);

            Assert.Equal(s, span.GetString());
        }
コード例 #5
0
        public void ConstructorSetsSpanProperties()
        {
            var buf  = new byte[100];
            var span = new Utf8ByteSpan(buf, 1, 5);

            Assert.Same(buf, span.Data);
            Assert.Equal(1, span.Offset);
            Assert.Equal(5, span.Length);
        }
コード例 #6
0
        public void ConstructorFromString()
        {
            var s     = "olé";
            var bytes = Encoding.UTF8.GetBytes(s);
            var span  = new Utf8ByteSpan(s);

            Assert.Equal(s, Encoding.UTF8.GetString(span.Data));
            Assert.Equal(0, span.Offset);
            Assert.Equal(bytes.Length, span.Length);
        }
コード例 #7
0
        public void SpanEqualsSpan()
        {
            var span1 = new Utf8ByteSpan("abc");
            var span2 = new Utf8ByteSpan("abc");

            Assert.True(span1.Equals(span2));

            var span3 = new Utf8ByteSpan(Encoding.UTF8.GetBytes("zzabc!"), 2, 3);

            Assert.True(span1.Equals(span3));

            var span4 = new Utf8ByteSpan("abd");

            Assert.False(span1.Equals(span4));
        }
コード例 #8
0
        public void SpanEqualsStringWithMultiByteCharacters()
        {
            var s     = "olé";
            var bytes = Encoding.UTF8.GetBytes("zz" + s + "!");

            var span1 = new Utf8ByteSpan(s);

            Assert.True(span1.Equals(s));

            var span2 = new Utf8ByteSpan(bytes, 2, bytes.Length - 3);

            Assert.True(span2.Equals(s));

            var span3 = new Utf8ByteSpan("olè");

            Assert.False(span3.Equals(s));
        }