示例#1
0
        public void CS1009ERR_IllegalEscape()
        {
            var test = @"
namespace x
{
    public class a
    {
        public static void f(int i, char j)
        {
            string a = ""\m"";    // CS1009
        }
        public static void Main()
        {
        }
    }
}
";

            ParserErrorMessageTests.ParseAndValidate(test, Diagnostic(ErrorCode.ERR_IllegalEscape, @"\m"));
        }
示例#2
0
        public void CS1021ERR_IntOverflow()
        {
            var test =
                @"#line 12345678901234567890
class C
{
    const int x = -123456789012345678901234567890;
}";

            ParserErrorMessageTests.ParseAndValidate(test,
                                                     // (1,7): error CS1021: Integral constant is too large
                                                     // #line 12345678901234567890
                                                     Diagnostic(ErrorCode.ERR_IntOverflow, ""),
                                                     // (1,7): error CS1576: The line number specified for #line directive is missing or invalid
                                                     // #line 12345678901234567890
                                                     Diagnostic(ErrorCode.ERR_InvalidLineNumber, "12345678901234567890"),
                                                     // (4,20): error CS1021: Integral constant is too large
                                                     //     const int x = -123456789012345678901234567890;
                                                     Diagnostic(ErrorCode.ERR_IntOverflow, ""));
        }
        public void DisabledRegion_Diagnostics()
        {
            var source = @"
#if false
#region
#endif
class C { }
";

            // CONSIDER: it would be nicer not to double-report this.
            // (It's happening because the #endif doesn't pop the region
            // off the directive stack, so it's still there when we clean
            // up.)
            // NOTE: we deliberately suppress the "missing endif" that
            // dev10 would have reported - we only report the first error
            // when unwinding the stack.
            ParserErrorMessageTests.ParseAndValidate(source,
                                                     Diagnostic(ErrorCode.ERR_EndRegionDirectiveExpected, "#endif"),
                                                     Diagnostic(ErrorCode.ERR_EndRegionDirectiveExpected, ""));
        }
示例#4
0
        public void DisabledPragma_Diagnostics()
        {
            var source =
                @"
#if false
#pragma
#pragma warning
#pragma warning disable ""something""
#pragma warning disable 0
#pragma warning disable -1
#pragma checksum
#pragma checksum ""file""
#pragma checksum ""file"" ""guid""
#pragma checksum ""file"" ""guid"" ""bytes""
#endif
#pragma
#pragma warning
#pragma warning disable ""something2""
#pragma warning disable 1
#pragma warning disable -2
#pragma checksum
#pragma checksum ""file""
#pragma checksum ""file"" ""guid""
#pragma checksum ""file"" ""guid"" ""bytes""
class C { }
";

            ParserErrorMessageTests.ParseAndValidate(
                source,
                Diagnostic(ErrorCode.WRN_IllegalPragma, ""),
                Diagnostic(ErrorCode.WRN_IllegalPPWarning, ""),
                Diagnostic(ErrorCode.WRN_IdentifierOrNumericLiteralExpected, "\"something2\""),
                Diagnostic(ErrorCode.WRN_IdentifierOrNumericLiteralExpected, "-"),
                Diagnostic(ErrorCode.WRN_IllegalPPChecksum, ""),
                Diagnostic(ErrorCode.WRN_IllegalPPChecksum, ""),
                Diagnostic(ErrorCode.WRN_IllegalPPChecksum, @"""guid"""),
                Diagnostic(ErrorCode.WRN_IllegalPPChecksum, ""),
                Diagnostic(ErrorCode.WRN_IllegalPPChecksum, @"""guid"""),
                Diagnostic(ErrorCode.WRN_IllegalPPChecksum, @"""bytes""")
                );
        }
示例#5
0
        public void CS0078WRN_LowercaseEllSuffix()
        {
            var test = @"
class Test
{
    public static int Main()
    {
        long l = 25l;   // CS0078
        ulong n1 = 1lu;   // CS0078
        ulong n2 = 10lU;   // CS0078
        System.Console.WriteLine(""{0}+{1}+{2}"", l, n1, n2);
        return 0;
    }
}
";

            ParserErrorMessageTests.ParseAndValidate(test,
                                                     Diagnostic(ErrorCode.WRN_LowercaseEllSuffix, "l"),
                                                     Diagnostic(ErrorCode.WRN_LowercaseEllSuffix, "l"),
                                                     Diagnostic(ErrorCode.WRN_LowercaseEllSuffix, "l"));
        }
示例#6
0
        public void CS1056ERR_UnexpectedCharacter_EscapedBackslash()
        {
            var test =
                @"using S\u005Cu0065 = System;
class A
{
int x = 0;
}
";

            ParserErrorMessageTests.ParseAndValidate(
                test, // (1,8): error CS1002: ; expected
                // using S\u005Cu0065 = System;
                Diagnostic(ErrorCode.ERR_SemicolonExpected, @"\u005C").WithLocation(1, 8),
                // (1,8): error CS1056: Unexpected character '\u005C'
                // using S\u005Cu0065 = System;
                Diagnostic(ErrorCode.ERR_UnexpectedCharacter, "")
                .WithArguments(@"\u005C")
                .WithLocation(1, 8)
                );
        }
示例#7
0
        public void CS1012ERR_TooManyCharsInConst()
        {
            var test =
                @"
namespace x
{
    public class b : c
    {
        char a = 'xx';    
        public static void Main()
        {
        }    
    }
}
";

            ParserErrorMessageTests.ParseAndValidate(
                test,
                Diagnostic(ErrorCode.ERR_TooManyCharsInConst, "")
                );
        }
        public void CS1015ERR_TypeExpected()
        {
            var test = @"
public class C
{
    public static void Main()
    {
        const int i = 0;
        const const double d = 0;
        const const const long l = 0;
        const readonly readonly readonly const double r = 0;
    }    
}
";

            ParserErrorMessageTests.ParseAndValidate(test,
                                                     // (7,15): error CS1031: Type expected
                                                     //         const const double d = 0;
                                                     Diagnostic(ErrorCode.ERR_TypeExpected, "const").WithArguments("const").WithLocation(7, 15),
                                                     // (8,15): error CS1031: Type expected
                                                     //         const const const long l = 0;
                                                     Diagnostic(ErrorCode.ERR_TypeExpected, "const").WithArguments("const").WithLocation(8, 15),
                                                     // (8,21): error CS1031: Type expected
                                                     //         const const const long l = 0;
                                                     Diagnostic(ErrorCode.ERR_TypeExpected, "const").WithArguments("const").WithLocation(8, 21),
                                                     // (9,15): error CS0106: The modifier 'readonly' is not valid for this item
                                                     //         const readonly readonly readonly const double r = 0;
                                                     Diagnostic(ErrorCode.ERR_BadMemberFlag, "readonly").WithArguments("readonly").WithLocation(9, 15),
                                                     // (9,24): error CS0106: The modifier 'readonly' is not valid for this item
                                                     //         const readonly readonly readonly const double r = 0;
                                                     Diagnostic(ErrorCode.ERR_BadMemberFlag, "readonly").WithArguments("readonly").WithLocation(9, 24),
                                                     // (9,33): error CS0106: The modifier 'readonly' is not valid for this item
                                                     //         const readonly readonly readonly const double r = 0;
                                                     Diagnostic(ErrorCode.ERR_BadMemberFlag, "readonly").WithArguments("readonly").WithLocation(9, 33),
                                                     // (9,42): error CS1031: Type expected
                                                     //         const readonly readonly readonly const double r = 0;
                                                     Diagnostic(ErrorCode.ERR_TypeExpected, "const").WithArguments("const").WithLocation(9, 42)
                                                     );
        }
示例#9
0
        public void CS0594ERR_FloatOverflow()
        {
            var test =
                @"class C
{
    const double d1 = -1e1000d;
    const double d2 = 1e-1000d;
    const float f1 = -2e100f;
    const float f2 = 2e-100f;
    const decimal m1 = -3e100m;
    const decimal m2 = 3e-100m;
}";

            ParserErrorMessageTests.ParseAndValidate(test,
                                                     // (3,24): error CS0594: Floating-point constant is outside the range of type 'double'
                                                     //     const double d1 = -1e1000d;
                                                     Diagnostic(ErrorCode.ERR_FloatOverflow, "").WithArguments("double"),
                                                     // (5,23): error CS0594: Floating-point constant is outside the range of type 'float'
                                                     //     const float f1 = -2e100f;
                                                     Diagnostic(ErrorCode.ERR_FloatOverflow, "").WithArguments("float"),
                                                     // (7,25): error CS0594: Floating-point constant is outside the range of type 'decimal'
                                                     //     const decimal m1 = -3e100m;
                                                     Diagnostic(ErrorCode.ERR_FloatOverflow, "3e100m").WithArguments("decimal"));
        }
示例#10
0
        public void FloatLexicalError()
        {
            var test =
                @"class C
{
    const double d1 = 0endOfDirective.Span;
}";

            // The precise errors don't matter so much as the fact that the compiler should not crash.
            ParserErrorMessageTests.ParseAndValidate(test,
                                                     // (3,23): error CS0595: Invalid real literal
                                                     //     const double d1 = 0endOfDirective.Span;
                                                     Diagnostic(ErrorCode.ERR_InvalidReal, "").WithLocation(3, 23),
                                                     // (3,25): error CS1002: ; expected
                                                     //     const double d1 = 0endOfDirective.Span;
                                                     Diagnostic(ErrorCode.ERR_SemicolonExpected, "ndOfDirective").WithLocation(3, 25),
                                                     // (3,43): error CS1519: Invalid token ';' in class, struct, or interface member declaration
                                                     //     const double d1 = 0endOfDirective.Span;
                                                     Diagnostic(ErrorCode.ERR_InvalidMemberDecl, ";").WithArguments(";").WithLocation(3, 43),
                                                     // (3,43): error CS1519: Invalid token ';' in class, struct, or interface member declaration
                                                     //     const double d1 = 0endOfDirective.Span;
                                                     Diagnostic(ErrorCode.ERR_InvalidMemberDecl, ";").WithArguments(";").WithLocation(3, 43)
                                                     );
        }
        public void DisabledPragma_Diagnostics()
        {
            var source = @"
#if false
#pragma
#pragma warning
#pragma warning disable foo
#pragma warning disable 0
#pragma checksum
#pragma checksum ""file""
#pragma checksum ""file"" ""guid""
#pragma checksum ""file"" ""guid"" ""bytes""
#endif
#pragma
#pragma warning
#pragma warning disable foo
#pragma warning disable 0
#pragma checksum
#pragma checksum ""file""
#pragma checksum ""file"" ""guid""
#pragma checksum ""file"" ""guid"" ""bytes""
class C { }
";

            ParserErrorMessageTests.ParseAndValidate(source,
                                                     Diagnostic(ErrorCode.WRN_IllegalPragma, ""),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPWarning, ""),
                                                     Diagnostic(ErrorCode.WRN_StringOrNumericLiteralExpected, "foo"),
                                                     Diagnostic(ErrorCode.WRN_BadWarningNumber, "0").WithArguments("0"),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPChecksum, ""),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPChecksum, ""),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPChecksum, @"""guid"""),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPChecksum, ""),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPChecksum, @"""guid"""),
                                                     Diagnostic(ErrorCode.WRN_IllegalPPChecksum, @"""bytes"""));
        }