in src/EditorFeatures/CSharpTest/Classification/SyntacticClassifierTests.cs [2347:2996]
public async Task TestAllKeywords()
{
await TestAsync(
@"using System;
#region TaoRegion
namespace MyNamespace
{
abstract class Goo : Bar
{
bool goo = default(bool);
byte goo1;
char goo2;
const int goo3 = 999;
decimal goo4;
delegate void D();
double goo5;
enum MyEnum
{
one,
two,
three
};
event D MyEvent;
float goo6;
static int x;
long goo7;
sbyte goo8;
short goo9;
int goo10 = sizeof(int);
string goo11;
uint goo12;
ulong goo13;
volatile ushort goo14;
struct SomeStruct
{
}
protected virtual void someMethod()
{
}
public Goo(int i)
{
bool var = i is int;
try
{
while (true)
{
continue;
break;
}
switch (goo)
{
case true:
break;
default:
break;
}
}
catch (System.Exception)
{
}
finally
{
}
checked
{
int i2 = 10000;
i2++;
}
do
{
}
while (true);
if (false)
{
}
else
{
}
unsafe
{
fixed (int* p = &x)
{
}
char* buffer = stackalloc char[16];
}
for (int i1 = 0; i1 < 10; i1++)
{
}
System.Collections.ArrayList al = new System.Collections.ArrayList();
foreach (object o in al)
{
object o1 = o;
}
lock (this)
{
}
}
Goo method(Bar i, out int z)
{
z = 5;
return i as Goo;
}
public static explicit operator Goo(int i)
{
return new Baz(1);
}
public static implicit operator Goo(double x)
{
return new Baz(1);
}
public extern void doSomething();
internal void method2(object o)
{
if (o == null)
goto Output;
if (o is Baz)
return;
else
throw new System.Exception();
Output:
Console.WriteLine(""Finished"");
}
}
sealed class Baz : Goo
{
readonly int field;
public Baz(int i) : base(i)
{
}
public void someOtherMethod(ref int i, System.Type c)
{
int f = 1;
someOtherMethod(ref f, typeof(int));
}
protected override void someMethod()
{
unchecked
{
int i = 1;
i++;
}
}
private void method(params object[] args)
{
}
}
interface Bar
{
}
}
#endregion TaoRegion",
Keyword("using"),
Identifier("System"),
Punctuation.Semicolon,
PPKeyword("#"),
PPKeyword("region"),
PPText("TaoRegion"),
Keyword("namespace"),
Identifier("MyNamespace"),
Punctuation.OpenCurly,
Keyword("abstract"),
Keyword("class"),
Class("Goo"),
Punctuation.Colon,
Identifier("Bar"),
Punctuation.OpenCurly,
Keyword("bool"),
Identifier("goo"),
Operators.Equals,
Keyword("default"),
Punctuation.OpenParen,
Keyword("bool"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("byte"),
Identifier("goo1"),
Punctuation.Semicolon,
Keyword("char"),
Identifier("goo2"),
Punctuation.Semicolon,
Keyword("const"),
Keyword("int"),
Identifier("goo3"),
Operators.Equals,
Number("999"),
Punctuation.Semicolon,
Keyword("decimal"),
Identifier("goo4"),
Punctuation.Semicolon,
Keyword("delegate"),
Keyword("void"),
Delegate("D"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("double"),
Identifier("goo5"),
Punctuation.Semicolon,
Keyword("enum"),
Enum("MyEnum"),
Punctuation.OpenCurly,
Identifier("one"),
Punctuation.Comma,
Identifier("two"),
Punctuation.Comma,
Identifier("three"),
Punctuation.CloseCurly,
Punctuation.Semicolon,
Keyword("event"),
Identifier("D"),
Identifier("MyEvent"),
Punctuation.Semicolon,
Keyword("float"),
Identifier("goo6"),
Punctuation.Semicolon,
Keyword("static"),
Keyword("int"),
Identifier("x"),
Punctuation.Semicolon,
Keyword("long"),
Identifier("goo7"),
Punctuation.Semicolon,
Keyword("sbyte"),
Identifier("goo8"),
Punctuation.Semicolon,
Keyword("short"),
Identifier("goo9"),
Punctuation.Semicolon,
Keyword("int"),
Identifier("goo10"),
Operators.Equals,
Keyword("sizeof"),
Punctuation.OpenParen,
Keyword("int"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("string"),
Identifier("goo11"),
Punctuation.Semicolon,
Keyword("uint"),
Identifier("goo12"),
Punctuation.Semicolon,
Keyword("ulong"),
Identifier("goo13"),
Punctuation.Semicolon,
Keyword("volatile"),
Keyword("ushort"),
Identifier("goo14"),
Punctuation.Semicolon,
Keyword("struct"),
Struct("SomeStruct"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("protected"),
Keyword("virtual"),
Keyword("void"),
Identifier("someMethod"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("public"),
Identifier("Goo"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("i"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("bool"),
Identifier("var"),
Operators.Equals,
Identifier("i"),
Keyword("is"),
Keyword("int"),
Punctuation.Semicolon,
Keyword("try"),
Punctuation.OpenCurly,
Keyword("while"),
Punctuation.OpenParen,
Keyword("true"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("continue"),
Punctuation.Semicolon,
Keyword("break"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("switch"),
Punctuation.OpenParen,
Identifier("goo"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("case"),
Keyword("true"),
Punctuation.Colon,
Keyword("break"),
Punctuation.Semicolon,
Keyword("default"),
Punctuation.Colon,
Keyword("break"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Keyword("catch"),
Punctuation.OpenParen,
Identifier("System"),
Operators.Dot,
Identifier("Exception"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("finally"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("checked"),
Punctuation.OpenCurly,
Keyword("int"),
Identifier("i2"),
Operators.Equals,
Number("10000"),
Punctuation.Semicolon,
Identifier("i2"),
Operators.Text("++"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("do"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("while"),
Punctuation.OpenParen,
Keyword("true"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("if"),
Punctuation.OpenParen,
Keyword("false"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("else"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("unsafe"),
Punctuation.OpenCurly,
Keyword("fixed"),
Punctuation.OpenParen,
Keyword("int"),
Operators.Star,
Identifier("p"),
Operators.Equals,
Operators.Text("&"),
Identifier("x"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("char"),
Operators.Star,
Identifier("buffer"),
Operators.Equals,
Keyword("stackalloc"),
Keyword("char"),
Punctuation.OpenBracket,
Number("16"),
Punctuation.CloseBracket,
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("for"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("i1"),
Operators.Equals,
Number("0"),
Punctuation.Semicolon,
Identifier("i1"),
Operators.LessThan,
Number("10"),
Punctuation.Semicolon,
Identifier("i1"),
Operators.Text("++"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Identifier("System"),
Operators.Dot,
Identifier("Collections"),
Operators.Dot,
Identifier("ArrayList"),
Identifier("al"),
Operators.Equals,
Keyword("new"),
Identifier("System"),
Operators.Dot,
Identifier("Collections"),
Operators.Dot,
Identifier("ArrayList"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("foreach"),
Punctuation.OpenParen,
Keyword("object"),
Identifier("o"),
Keyword("in"),
Identifier("al"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("object"),
Identifier("o1"),
Operators.Equals,
Identifier("o"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("lock"),
Punctuation.OpenParen,
Keyword("this"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Identifier("Goo"),
Identifier("method"),
Punctuation.OpenParen,
Identifier("Bar"),
Identifier("i"),
Punctuation.Comma,
Keyword("out"),
Keyword("int"),
Identifier("z"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Identifier("z"),
Operators.Equals,
Number("5"),
Punctuation.Semicolon,
Keyword("return"),
Identifier("i"),
Keyword("as"),
Identifier("Goo"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("public"),
Keyword("static"),
Keyword("explicit"),
Keyword("operator"),
Identifier("Goo"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("i"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("return"),
Keyword("new"),
Identifier("Baz"),
Punctuation.OpenParen,
Number("1"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("public"),
Keyword("static"),
Keyword("implicit"),
Keyword("operator"),
Identifier("Goo"),
Punctuation.OpenParen,
Keyword("double"),
Identifier("x"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("return"),
Keyword("new"),
Identifier("Baz"),
Punctuation.OpenParen,
Number("1"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("public"),
Keyword("extern"),
Keyword("void"),
Identifier("doSomething"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("internal"),
Keyword("void"),
Identifier("method2"),
Punctuation.OpenParen,
Keyword("object"),
Identifier("o"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("if"),
Punctuation.OpenParen,
Identifier("o"),
Operators.DoubleEquals,
Keyword("null"),
Punctuation.CloseParen,
Keyword("goto"),
Identifier("Output"),
Punctuation.Semicolon,
Keyword("if"),
Punctuation.OpenParen,
Identifier("o"),
Keyword("is"),
Identifier("Baz"),
Punctuation.CloseParen,
Keyword("return"),
Punctuation.Semicolon,
Keyword("else"),
Keyword("throw"),
Keyword("new"),
Identifier("System"),
Operators.Dot,
Identifier("Exception"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
Identifier("Output"),
Punctuation.Colon,
Identifier("Console"),
Operators.Dot,
Identifier("WriteLine"),
Punctuation.OpenParen,
String(@"""Finished"""),
Punctuation.CloseParen,
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Keyword("sealed"),
Keyword("class"),
Class("Baz"),
Punctuation.Colon,
Identifier("Goo"),
Punctuation.OpenCurly,
Keyword("readonly"),
Keyword("int"),
Identifier("field"),
Punctuation.Semicolon,
Keyword("public"),
Identifier("Baz"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("i"),
Punctuation.CloseParen,
Punctuation.Colon,
Keyword("base"),
Punctuation.OpenParen,
Identifier("i"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Keyword("public"),
Keyword("void"),
Identifier("someOtherMethod"),
Punctuation.OpenParen,
Keyword("ref"),
Keyword("int"),
Identifier("i"),
Punctuation.Comma,
Identifier("System"),
Operators.Dot,
Identifier("Type"),
Identifier("c"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("int"),
Identifier("f"),
Operators.Equals,
Number("1"),
Punctuation.Semicolon,
Identifier("someOtherMethod"),
Punctuation.OpenParen,
Keyword("ref"),
Identifier("f"),
Punctuation.Comma,
Keyword("typeof"),
Punctuation.OpenParen,
Keyword("int"),
Punctuation.CloseParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("protected"),
Keyword("override"),
Keyword("void"),
Identifier("someMethod"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("unchecked"),
Punctuation.OpenCurly,
Keyword("int"),
Identifier("i"),
Operators.Equals,
Number("1"),
Punctuation.Semicolon,
Identifier("i"),
Operators.Text("++"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Keyword("private"),
Keyword("void"),
Identifier("method"),
Punctuation.OpenParen,
Keyword("params"),
Keyword("object"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("args"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Keyword("interface"),
Interface("Bar"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
PPKeyword("#"),
PPKeyword("endregion"),
PPText("TaoRegion"));
}