コード例 #1
0
        public void ReturnParenthesizedNullLitteral()
        {
            var code = @"
public Type f()
{
    return (null);
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #2
0
ファイル: MlirExportTest.cs プロジェクト: touzas/sonar-dotnet
        public void AssignmentInBinaryOperator()
        {
            var code = @"
void f(int a, int b)
{
    a = (b = 2) + 1;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #3
0
        public void MethodGroup()
        {
            var code = @"
public static Func<string, bool> CreateFilter()
{
    return string.IsNullOrEmpty;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #4
0
ファイル: MlirExportTest.cs プロジェクト: touzas/sonar-dotnet
        public void IgnoreParenthesesInAssignment()
        {
            var code = @"
void f(int a, int b)
{
    a = (b = 2);
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #5
0
        public void SimpleLambdaExpression()
        {
            var code = @"
public System.Linq.Expressions.Expression<Func<int, int>> F()
{
    return x => 2*x;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #6
0
        public void ParenthesizedLambdaExpression()
        {
            var code = @"
Action f()
{
    return () => Y();
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #7
0
        public void UnnamedFunctionParameter()
        {
            var code = @"
int Func(int, int, int i)
{
    return 2*i;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #8
0
        public void ParamsKeyword()
        {
            var code = @"
public void f(params int[] args)
        {
        }
";


            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #9
0
        public void ChainingAssignments()
        {
            var code = @"
void f(int i)
{
    int j = i = 0;
    i = j = 10;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #10
0
        public void UnknownMethodOnMultipleLines()
        {
            var code = @"
void f(int i, int j)
{
    g(i,
    j);
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #11
0
        public void ArrayAssignment()
        {
            var code = @"
void f()
{
    int[] array = new int[5];
    array[0] = 2;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #12
0
        public void AnonymousObjectCreation()
        {
            var code = @"
public int f()
{
    var v = new { a = 108, m = ""Hello"" };
    return v.a;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #13
0
        public void Goto()
        {
            var code = @"
void f()
{
    goto Label;
Label:
    return;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #14
0
        public void AsyncFunction()
        {
            var code = @"
class A {
    async System.Threading.Tasks.Task<int> FuncAsync()
    {
        return 3;
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #15
0
ファイル: MlirExportTest.cs プロジェクト: touzas/sonar-dotnet
        public void CommentsWithNewLine()
        {
            var code = @"
void f()
{
    new A() { i = 3 }; // Noncompliant
//          ^^^^^^^^^
    new A() { i = 4 };
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #16
0
        public void ForWithoutCondition()
        {
            var code = @"
void f(int i)
{
    for (;;)
    {
        i = i + 1;
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #17
0
        public void Enum()
        {
            var code = @"
using System;

public enum Color { Red, Green, Blue };
private enum Color { Red, Green, Blue };

class A {
    private Color WorkWithEnum(int i, Color col)
    {
        if (col == Color.Blue && i == (int)col)
        {
            Color c = Color.Blue;
            return c;
        }
        else
        {
            return Color.Red;
        }
    }
    private Color WorkWithUnaccessibleEnum(int i, Color col)
    {
        if (col == Color.Blue && i == (int)col)
        {
            Color c = Color.Blue;
            return c;
        }
        else
        {
            return Color.Red;
        }
    }
    private ConsoleColor WorkWithExternalEnum(int i, ConsoleColor col)
    {
        if (col == ConsoleColor.Blue && i == (int)col)
        {
            Color c = ConsoleColor.Blue;
            return c;
        }
        else
        {
            return ConsoleColor.Red;
        }
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #18
0
        public void MixingUintAndNeg()
        {
            var code = @"
void f() {
  int j = -10u;
}

void g() {
  int someInt = -2147483648;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #19
0
ファイル: MlirExportTest.cs プロジェクト: touzas/sonar-dotnet
        public void UnsafeClass()
        {
            var code = @"
unsafe class C {
  int f()
  {
    int j = 1;
    return j+1;
  }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #20
0
        public void Namespace()
        {
            var code = @"
namespace Tests
{
    public static void f()
    {
        Tests.g();
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #21
0
ファイル: MlirExportTest.cs プロジェクト: touzas/sonar-dotnet
        public void NonASCIIEncodings()
        {
            var code = @"
public void 你好() { }

public void Łódź() { }

public void AsciiThen你好ThenAsciiAgain() { }

public int Łódźअनुلمرadım(int 你好) { return 2 * 你好; }
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #22
0
        public void UnknownConstant()
        {
            var code = @"
class A
{
        private const object NullConst = null;

        void f()
        {
            NullConst.ToString();
        }
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #23
0
        public void ParenthesizedExpressions()
        {
            var code = @"
public void f(int i, int j)
{
    var k = ((i) + j);
    if (((k) == 0))
    {
        (i = k);
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #24
0
ファイル: MlirExportTest.cs プロジェクト: touzas/sonar-dotnet
        public void InfiniteLoop()
        {
            var code = @"
int InfiniteLoop(int i) {
    while (true) {
        if (++i == 42) {
            return i;
        }
    }
    // No return here
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #25
0
        public void AssignmentInComparison()
        {
            var code = @"
int f(int a, int b)
{
    if ((a = 3) < (b = 2))
    {
        return 0;
    }
    return 1;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #26
0
        public void NestedFunction()
        {
            var code = @"
void f()
{
    var s = g();
    int g()
    {
        return 0;
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #27
0
        public void UnaryNeg()
        {
            var code = @"
public bool neg()
{
    int i = -12;
    int j = -i;
    if (i + j == 0) {
        return true;
    }
    return false;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #28
0
        public void BooleanConstant()
        {
            var code = @"
public class A
{
    internal const bool myBool = true;

    void f()
    {
        var b = myBool;
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #29
0
        public void UnaryPlus()
        {
            var code = @"
public bool plus()
{
    int i = +12;
    int j = +i;
    if (i - j == 0) {
        return true;
    }
    return false;
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }
コード例 #30
0
        public void UseOfConstantClassField()
        {
            var code = @"
public class A
{
    const int a = 0;

    public int getA()
    {
        return a;
    }
}
";

            MlirTestUtilities.ValidateCodeGeneration(code, TestContext.TestName);
        }