예제 #1
0
    public static void RunConvTests(bool doMaybe)
    {
        RelAutoB db = new RelAutoB();

        var aBool   = false;
        var aInt    = 42;
        var aFloat  = 3.14159;
        var aDate   = new DateTime(2020, 4, 9);
        var aTime   = new DateTime(2020, 4, 11, 3, 15, 45);
        var aTuple  = (1000000007, "Hello world!", new DateTime(2018, 10, 19));
        var aRecord = (time : new DateTime(2017, 11, 24, 17, 33, 29),
                       label : "How long?",
                       maybe : (long?)null
                       );
        var aString      = "Imagine there's no heaven";
        var aEmployeeId  = 8;
        var aCustomerId  = "ANSDY";
        var aTaggedMaybe = "id(27955, 14)";
        var aMap         = new (long, long)[] {
예제 #2
0
    private static void RunBadArgsTests()
    {
        RelAutoB db = new RelAutoB();

        var zero = db.MyPolyMeth("\"Hi!\"", "0.0");
        var one  = db.MyPolyMeth("\"Hi!\"", "0");

        if (zero != 0 | one != 1)
        {
            Console.WriteLine("ERROR (1): my_poly_meth(), zero = {0}, one = {1}", zero, one);
            Environment.Exit(1);
        }
        // var two  = db.MyPolyMeth("red", "just(true)");

        try {
            db.MyPolyMeth("\"Hi!\"", "true");
            Console.WriteLine("ERROR (2): my_poly_meth(\"Hi!\", true)");
            Environment.Exit(1);
        }
        catch (Exception) {
            // This was expected
        }

        try {
            db.DoOptionalMaybe("just(\"Hello!\")", null);
            Console.WriteLine("ERROR (3): DoOptionalMaybe(just(\"Hello!\"), null)");
            Environment.Exit(1);
        }
        catch (Exception) {
            // This was expected
        }


        db.DoOptionalMaybe("just(2.71828)", "just(\"Hi!\")");
        double?maybeFloatValue  = db.MaybeFloatMembVar();
        string maybeStringValue = db.MaybeStringMembVar();

        if (maybeFloatValue != 2.71828)
        {
            Console.WriteLine(
                "MaybeFloatMembVar() ERROR (1): {0}, {1}",
                maybeFloatValue, maybeFloatValue - 2.1818
                );
            Environment.Exit(1);
        }
        if (maybeStringValue != "Hi!")
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (1): {0}", maybeStringValue);
            Environment.Exit(1);
        }

        db.DoOptionalMaybe(null, null);
        maybeFloatValue  = db.MaybeFloatMembVar();
        maybeStringValue = db.MaybeStringMembVar();
        if (maybeFloatValue != 2.71828)
        {
            Console.WriteLine(
                "MaybeFloatMembVar() ERROR (2): {0}, {1}",
                maybeFloatValue, maybeFloatValue - 2.1818
                );
            Environment.Exit(1);
        }
        if (maybeStringValue != "Hi!")
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (2): {0}", maybeStringValue);
            Environment.Exit(1);
        }

        db.DoOptionalMaybe("nothing", "just(\"Hi!\")");
        maybeFloatValue  = db.MaybeFloatMembVar();
        maybeStringValue = db.MaybeStringMembVar();
        if (maybeFloatValue != null)
        {
            Console.WriteLine("MaybeFloatMembVar() ERROR (3): {0}", maybeFloatValue);
            Environment.Exit(1);
        }
        if (maybeStringValue != "Hi!")
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (3): {0}", maybeStringValue);
            Environment.Exit(1);
        }

        db.DoOptionalMaybe("just(2.71828)", "nothing");
        maybeFloatValue  = db.MaybeFloatMembVar();
        maybeStringValue = db.MaybeStringMembVar();
        if (maybeFloatValue != 2.71828)
        {
            Console.WriteLine(
                "MaybeFloatMembVar() ERROR (4): {0}, {1}",
                maybeFloatValue, maybeFloatValue - 2.1818
                );
            Environment.Exit(1);
        }
        if (maybeStringValue != null)
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (4): {0}", maybeStringValue);
            Environment.Exit(1);
        }

        db.DoOptionalMaybe("nothing", "nothing");
        maybeFloatValue  = db.MaybeFloatMembVar();
        maybeStringValue = db.MaybeStringMembVar();
        if (maybeFloatValue != null)
        {
            Console.WriteLine("MaybeFloatMembVar() ERROR (5): {0}", maybeFloatValue);
            Environment.Exit(1);
        }
        if (maybeStringValue != null)
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (5): {0}", maybeStringValue);
            Environment.Exit(1);
        }

        db.DoOptionalMaybe(null, "just(\"Hi!\")");
        maybeFloatValue  = db.MaybeFloatMembVar();
        maybeStringValue = db.MaybeStringMembVar();
        if (maybeFloatValue != null)
        {
            Console.WriteLine("MaybeFloatMembVar() ERROR (6): {0}", maybeFloatValue);
            Environment.Exit(1);
        }
        if (maybeStringValue != "Hi!")
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (6): {0}", maybeStringValue);
            Environment.Exit(1);
        }

        db.DoOptionalMaybe("just(2.71828)", null);
        maybeFloatValue  = db.MaybeFloatMembVar();
        maybeStringValue = db.MaybeStringMembVar();
        if (maybeFloatValue != 2.71828)
        {
            Console.WriteLine(
                "MaybeFloatMembVar() ERROR (7): {0}, {1}",
                maybeFloatValue, maybeFloatValue - 2.1818
                );
            Environment.Exit(1);
        }
        if (maybeStringValue != "Hi!")
        {
            Console.WriteLine("MaybeStringMembVar() ERROR (7): {0}", maybeStringValue);
            Environment.Exit(1);
        }
    }