コード例 #1
0
        public void Utf16Test(string regex, int expectedLetterCount, bool caseSensitive, bool eof, int[] expectLetterIds, char[] testChars)
        {
            Debug.Assert(expectLetterIds.Length == testChars.Length);
            AlphabetBuilder <char> builder;

            Assert.Equal(expectedLetterCount, this.Test(regex, caseSensitive, new UnicodeUtf16Mapper(false, false), eof ? Utf16Chars.EOF : default(char?), Utf16Chars.ValidAll, out builder));
            var expression = AlphabetMapperEmitter <char> .CreateExpression(builder);

            this.output.WriteLine("");
            this.output.WriteLine("Expression:");
            this.output.WriteLine(expression.Body.ToString());
            var func = expression.Compile();

            Assert.Throws <InvalidOperationException>(() => func('\uFFFE'));
            if (eof)
            {
                Assert.Equal(new LetterId(0), func(Utf16Chars.EOF));
            }
            else
            {
                Assert.Throws <InvalidOperationException>(() => func(Utf16Chars.EOF));
            }
            for (var i = 0; i < testChars.Length; i++)
            {
                Assert.Equal(new LetterId(expectLetterIds[i]), func(testChars[i]));
            }
        }
コード例 #2
0
        public void Utf32Test(string regex, int expectedLetters, bool caseSensitive, bool eof, int[] expectLetterIds, int[] testChars)
        {
            AlphabetBuilder <Codepoint> builder;

            Assert.Equal(expectedLetters, this.Test(regex, caseSensitive, new UnicodeCodepointMapper(false, false), eof ? Codepoints.EOF : default(Codepoint?), Codepoints.Valid, out builder));
            var expression = AlphabetMapperEmitter <Codepoint> .CreateExpression(builder);

            this.output.WriteLine("");
            this.output.WriteLine("Expression:");
            this.output.WriteLine(expression.Body.ToString());
            var func = expression.Compile();

            Assert.Throws <InvalidOperationException>(() => func((Codepoint)'\uFFFE'));
            if (eof)
            {
                Assert.Equal(new LetterId(0), func(Codepoints.EOF));
            }
            else
            {
                Assert.Throws <InvalidOperationException>(() => func(Codepoints.EOF));
            }
            for (var i = 0; i < testChars.Length; i++)
            {
                Assert.Equal(new LetterId(expectLetterIds[i]), func((Codepoint)testChars[i]));
            }
        }