示例#1
0
        [InlineData("ลป๑", false, 0, 0, 0)] // 
        public unsafe void ParseCustomCultureThaiByteArrayToSbyte(string text, bool expectSuccess, int index, sbyte expectedValue, int expectedBytesConsumed)
        {
            sbyte parsedValue;
            int bytesConsumed;
            var thaiUtf8DigitsAndSymbols = new byte[][]
            {
                new byte[] { 0xe0, 0xb9, 0x90 }, new byte[] { 0xe0, 0xb9, 0x91 }, new byte[] { 0xe0, 0xb9, 0x92 },
                new byte[] { 0xe0, 0xb9, 0x93 }, new byte[] { 0xe0, 0xb9, 0x94 }, new byte[] { 0xe0, 0xb9, 0x95 }, new byte[] { 0xe0, 0xb9, 0x96 },
                new byte[] { 0xe0, 0xb9, 0x97 }, new byte[] { 0xe0, 0xb9, 0x98 }, new byte[] { 0xe0, 0xb9, 0x99 }, new byte[] { 0xE0, 0xB8, 0x88, 0xE0, 0xB8, 0x94 }, null,
                new byte[] { 0xE0, 0xB8, 0xAA, 0xE0, 0xB8, 0xB4, 0xE0, 0xB9, 0x88, 0xE0, 0xB8, 0x87, 0xE0, 0xB8, 0x97, 0xE0, 0xB8, 0xB5, 0xE0, 0xB9, 0x88, 0xE0, 0xB9, 0x83,
                    0xE0, 0xB8, 0xAB, 0xE0, 0xB8, 0x8D, 0xE0, 0xB9, 0x88, 0xE0, 0xB9, 0x82, 0xE0, 0xB8, 0x95, 0xE0, 0xB9, 0x80, 0xE0, 0xB8, 0xAB, 0xE0, 0xB8, 0xA5, 0xE0,
                    0xB8, 0xB7, 0xE0, 0xB8, 0xAD, 0xE0, 0xB9, 0x80, 0xE0, 0xB8, 0x81, 0xE0, 0xB8, 0xB4, 0xE0, 0xB8, 0x99 },
                new byte[] { 0xE0, 0xB8, 0xA5, 0xE0, 0xB8, 0x9A }, new byte[] { 43 }, new byte[] { 0xE0, 0xB9, 0x84, 0xE0, 0xB8, 0xA1, 0xE0, 0xB9, 0x88, 0xE0, 0xB9,
                    0x83, 0xE0, 0xB8, 0x8A, 0xE0, 0xB9, 0x88, 0xE0, 0xB8, 0x95, 0xE0, 0xB8, 0xB1, 0xE0, 0xB8, 0xA7, 0xE0, 0xB9, 0x80, 0xE0, 0xB8, 0xA5, 0xE0, 0xB8, 0x82 },
                new byte[] { 69 }, new byte[] { 101 },
            };
            var thaiUtf8ParsingTrie = new FormattingData.TrieNode[]
            {
                new FormattingData.TrieNode { valueOrNumChildren = 4, index = 0 },
                new FormattingData.TrieNode { valueOrNumChildren = 43, index = 5 },
                new FormattingData.TrieNode { valueOrNumChildren = 69, index = 6 },
                new FormattingData.TrieNode { valueOrNumChildren = 101, index = 7 },
                new FormattingData.TrieNode { valueOrNumChildren = 0xE0, index = 8 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 14 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 16 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 16 },
                new FormattingData.TrieNode { valueOrNumChildren = 2, index = 0 },
                new FormattingData.TrieNode { valueOrNumChildren = 0xB8, index = 11 },
                new FormattingData.TrieNode { valueOrNumChildren = 0xB9, index = 15 },
                new FormattingData.TrieNode { valueOrNumChildren = 3, index = 0 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x88, index = 27 },
                new FormattingData.TrieNode { valueOrNumChildren = 0xA5, index = 28 },
                new FormattingData.TrieNode { valueOrNumChildren = 0xAA, index = 29 },
                new FormattingData.TrieNode { valueOrNumChildren = 11, index = -1878877941 /* 0x9002990B */ },
                new FormattingData.TrieNode { valueOrNumChildren = 0x84, index = 30 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x90, index = 31 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x91, index = 32 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x92, index = 33 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x93, index = 34 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x94, index = 35 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x95, index = 36 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x96, index = 37 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x97, index = 38 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x98, index = 39 },
                new FormattingData.TrieNode { valueOrNumChildren = 0x99, index = 40 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 10 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 13 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 12 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 15 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 0 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 1 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 2 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 3 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 4 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 5 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 6 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 7 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 8 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 9 },
            };
            FormattingData fd = new FormattingData(thaiUtf8DigitsAndSymbols, thaiUtf8ParsingTrie, FormattingData.Encoding.Utf8);
            Format.Parsed nf = new Format.Parsed('R');
            bool result = InvariantParser.TryParse(UtfEncode(text, false), index, fd, nf, out parsedValue, out bytesConsumed);

            Assert.Equal(expectSuccess, result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedBytesConsumed, bytesConsumed);
        }
示例#2
0
        [InlineData("-129", false, 0, 0, 0)] // negative overflow test
        public unsafe void ParseCustomCultureByteArrayToSbyte(string text, bool expectSuccess, int index, sbyte expectedValue, int expectedBytesConsumed)
        {
            sbyte parsedValue;
            int bytesConsumed;
            var utf8digitsAndSymbols = new byte[][] {
                new byte[] { 48, },
                new byte[] { 49, },
                new byte[] { 50, },
                new byte[] { 51, },
                new byte[] { 52, },
                new byte[] { 53, },
                new byte[] { 54, },
                new byte[] { 55, },
                new byte[] { 56, },
                new byte[] { 57, }, // digit 9
                new byte[] { 46, }, // decimal separator
                null, // so that it is != to uft8DigitsAndSymbols
                new byte[] { 73, 110, 102, 105, 110, 105, 116, 121, },
                new byte[] { 45, }, // minus sign
                new byte[] { 43, }, // plus sign
                new byte[] { 78, 97, 78, }, // NaN
                new byte[] { 69, }, // E
            };
            var utf8ParsingTrie = new FormattingData.TrieNode[]
            {
                new FormattingData.TrieNode { valueOrNumChildren = 17, index = 0x3004390D },
                new FormattingData.TrieNode { valueOrNumChildren = 43, index = 18 },
                new FormattingData.TrieNode { valueOrNumChildren = 45, index = 19 },
                new FormattingData.TrieNode { valueOrNumChildren = 46, index = 20 },
                new FormattingData.TrieNode { valueOrNumChildren = 48, index = 21 },
                new FormattingData.TrieNode { valueOrNumChildren = 49, index = 22 },
                new FormattingData.TrieNode { valueOrNumChildren = 50, index = 23 },
                new FormattingData.TrieNode { valueOrNumChildren = 51, index = 24 },
                new FormattingData.TrieNode { valueOrNumChildren = 52, index = 25 },
                new FormattingData.TrieNode { valueOrNumChildren = 53, index = 26 },
                new FormattingData.TrieNode { valueOrNumChildren = 54, index = 27 },
                new FormattingData.TrieNode { valueOrNumChildren = 55, index = 28 },
                new FormattingData.TrieNode { valueOrNumChildren = 56, index = 29 },
                new FormattingData.TrieNode { valueOrNumChildren = 57, index = 30 },
                new FormattingData.TrieNode { valueOrNumChildren = 69, index = 31 },
                new FormattingData.TrieNode { valueOrNumChildren = 73, index = 32 },
                new FormattingData.TrieNode { valueOrNumChildren = 78, index = 33 },
                new FormattingData.TrieNode { valueOrNumChildren = 101, index = 34 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 14 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 13 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 10 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 0 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 1 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 2 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 3 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 4 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 5 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 6 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 7 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 8 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 9 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 16 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 12 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 15 },
                new FormattingData.TrieNode { valueOrNumChildren = 0, index = 16 },
            };

            FormattingData fd = new FormattingData(utf8digitsAndSymbols, utf8ParsingTrie, FormattingData.Encoding.Utf8);
            Format.Parsed nf = new Format.Parsed('R');
            bool result = InvariantParser.TryParse(UtfEncode(text, false), index, fd, nf, out parsedValue, out bytesConsumed);

            Assert.Equal(expectSuccess, result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedBytesConsumed, bytesConsumed);
        }