Ejemplo n.º 1
0
        public void Map16to32Test()
        {
            // Arrange
            var buf = new Utf32Buffer();

            // Act
            buf.Add(mixedString);

            // Assert
            for (int i = 0; i < mixedString.Length; i++)
            {
                char ch   = mixedString[i];
                var  ch32 = buf[buf.Utf16OffsetToUtf32Offset(i)];
                if (ch >= 0xD800 && ch <= 0xDFFF)
                {
                    var chL        = mixedString[i + 1];
                    var ch32actual = 0x10000 | ((ch - 0xD800) << 10) | (chL - 0xDC00);
                    Assert.Equal(ch32, ch32actual);
                    i++;
                }
                else if (ch == '\r' && mixedString[i + 1] == '\n')
                {
                    Assert.Equal('\n', ch32);
                    i++;
                }
                else
                {
                    Assert.Equal(ch, ch32);
                }
            }
        }
Ejemplo n.º 2
0
        public void DeleteTextEnd()
        {
            // Arrange
            var buf = new Utf32Buffer();

            // Act
            buf.Add("abxx🌐xxcd");
            buf.Delete(4, 5);

            // Assert
            Assert.Equal("abxx", buf.ToString());
        }
Ejemplo n.º 3
0
        public void ConvertToUtf16()
        {
            // Arrange
            var buf = new Utf32Buffer();

            // Act
            buf.Add(mixedString);
            var str2 = Utf32Utils.FromUtf32(buf.AsSlice());

            // Assert
            Assert.Equal(mixedString.Replace("\r", ""), str2);
        }
Ejemplo n.º 4
0
        public void InsertText()
        {
            // Arrange
            var buf  = new Utf32Buffer();
            var strA = "abcd";
            var strB = "xx🌐xx";

            // Act
            buf.Add(strA);
            buf.Insert(2, strB);

            // Assert
            Assert.Equal("abxx🌐xxcd", buf.ToString());
        }
Ejemplo n.º 5
0
        public void AddText()
        {
            // Arrange
            var buf = new Utf32Buffer();
            var str = "ab🌐cde";

            // Act
            buf.Add(str);

            // Assert
            Assert.Equal(7, str.Length);
            Assert.Equal(6, buf.Length);
            Assert.Equal(str, buf.ToString());
        }
Ejemplo n.º 6
0
        public void Map32to16Test()
        {
            // Arrange
            var buf = new Utf32Buffer();

            // Act
            buf.Add(mixedString);

            // Assert
            for (int i32 = 0; i32 < buf.Length; i32++)
            {
                var i16  = buf.Utf32OffsetToUtf16Offset(i32);
                var i32b = buf.Utf16OffsetToUtf32Offset(i16);
                Assert.Equal(i32, i32b);
            }
        }
Ejemplo n.º 7
0
        public void MapSurrogateToBase()
        {
            // Arrange
            var buf = new Utf32Buffer();

            // Act
            buf.Add(mixedString);

            // Assert
            for (int i = 0; i < mixedString.Length; i++)
            {
                char ch = mixedString[i];
                if ((ch >= 0xDC00 && ch <= 0xDFFF) || (ch == '\n' && mixedString[i - 1] == '\r'))
                {
                    int prior   = buf.Utf16OffsetToUtf32Offset(i - 1);
                    int current = buf.Utf16OffsetToUtf32Offset(i);
                    Assert.Equal(prior, current);
                }
            }
        }