public void SingleLineCommentsAreDiscovered()
        {
            var expression = "var a = 1 + 3; // comment";
            var result     = new CSharpParser().Parse(expression);

            var aChunk = result.TextChunks.First(ch => ch.TextValue == "// comment");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(CodeType.Comment, aChunk.CodeType);
        }
Example #2
0
        public void IfIsIdentifiedAsKeyword()
        {
            var expression = "if (System.Console.ReadLine() == \"a\") { System.Console.WriteLine(\"Oh!\"); }";
            var result     = new CSharpParser().Parse(expression);

            var ifChunk = result.TextChunks.First(ch => ch.TextValue == "if");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Keyword, ifChunk.CodeType);
        }
Example #3
0
        public void NamespaceInUsingIsRecognized()
        {
            var expression = "using System.Collections.Generic;";
            var result     = new CSharpParser().Parse(expression);

            var namespaceChunk = result.TextChunks.First(ch => ch.TextValue == "Generic");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Namespace, namespaceChunk.CodeType);
            Assert.Equal("namespace System.Collections.Generic", namespaceChunk.TooltipValue);
        }
        public void SimpleMethodIsMarkedAsMethod()
        {
            var expression = "string.Join(\",\", new[]{\"a\", \"b\"})";
            var result     = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Join");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Method, intChunk.CodeType);
            Assert.Equal("string string.Join(string separator, params string[] value)", intChunk.TooltipValue);
        }
        public void OverloadResolutionWorks()
        {
            var expression = "string.Join(\",\", new[]{2, 5})";
            var result     = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Join");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Method, intChunk.CodeType);
            Assert.Equal("string string.Join<int>(string separator, System.Collections.Generic.IEnumerable<int> values)", intChunk.TooltipValue);
        }
Example #6
0
        public void InitializationTypeType()
        {
            var expression = "var a = new System.Int32();";
            var result     = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Int32");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(CodeType.Type, intChunk.CodeType);
            Assert.Equal("struct System.Int32", intChunk.TooltipValue);
        }
Example #7
0
        public void DeclarationGenericTypeType()
        {
            var expression = "System.Tuple<int, int> a = System.Tuple.Create(1, 1);";
            var result     = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Tuple");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(CodeType.Type, intChunk.CodeType);
            Assert.Equal("class System.Tuple", intChunk.TooltipValue);
        }
Example #8
0
        public void DeclarationPredefinedTypeType()
        {
            var expression = "int a = 1 + 3;";
            var result     = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "int");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(CodeType.Keyword, intChunk.CodeType);
            Assert.Equal("struct System.Int32", intChunk.TooltipValue);
        }
Example #9
0
        public void ItemPropertyOfTupleIsDiscovered()
        {
            var expression = "var t = System.Tuple.Create(1, 2, 3); System.Console.WriteLine(t.Item2);";
            var result     = new CSharpParser().Parse(expression);

            var propertyChunk = result.TextChunks.First(ch => ch.TextValue == "Item2");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Property, propertyChunk.CodeType);
            Assert.Equal("System.Tuple<int, int, int>.Item2", propertyChunk.TooltipValue);
        }
Example #10
0
        public void VariableMentionType()
        {
            var expression = "var a = 1 + 3; var b = a;";
            var result     = new CSharpParser().Parse(expression);

            var aMention = result.TextChunks.Where(ch => ch.TextValue == "a").Skip(1).First();

            ExpressionHelper.Check(expression, result);
            Assert.Equal(CodeType.Variable, aMention.CodeType);
            Assert.Equal("struct System.Int32", aMention.TooltipValue);
        }
Example #11
0
        public void VarType()
        {
            var expression = "var a = 1 + 3;";
            var result     = new CSharpParser().Parse(expression);

            var varChunk = result.TextChunks.First(ch => ch.TextValue == "var");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(CodeType.Keyword, varChunk.CodeType);
            Assert.Equal("struct System.Int32", varChunk.TooltipValue);
        }
Example #12
0
        public void ClassIsIdentifiedAsKeyword()
        {
            var expression = "public class Implementation {  }";
            var result     = new CSharpParser().Parse(expression);

            var publicChunk = result.TextChunks.First(ch => ch.TextValue == "public");
            var classChunk  = result.TextChunks.First(ch => ch.TextValue == "class");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Keyword, classChunk.CodeType);
            Assert.Equal(Common.CodeType.Keyword, publicChunk.CodeType);
        }
        public void GenericMethodCallIsRecognized()
        {
            var expression = @"

class Hello { public void Greet<T>() { } }

class Usage { public static void DoGreet() { new Hello().Greet<string>(); } }
";
            var result     = new CSharpParser().Parse(expression);

            var greetChunk = result.TextChunks.Last(ch => ch.TextValue == "Greet");

            ExpressionHelper.Check(expression, result);
            Assert.Equal(Common.CodeType.Method, greetChunk.CodeType);
        }