コード例 #1
0
def test_call_missing_return_expression():
    assert_error(
        """
        function f() -> int;
        main {
            /*!*/ call f(); /*!*/
        }
    """, Diagnostic.Messages.CALL_NO_RETURN_EXPRESSION, "f", "int")
コード例 #2
0
def test_call_argument_wrong_type():
    assert_error(
        """
        function f(int[] a);
        main {
            call f(/*!*/ 0 /*!*/);
        }
    """, Diagnostic.Messages.CALL_WRONG_ARGS_TYPE, "a", "f", "int[]", "int")
コード例 #3
0
def test_call_not_defined():
    assert_error(
        """
        function f();
        main {
            /*!*/ call g(); /*!*/
        }
    """, Diagnostic.Messages.FUNCTION_NOT_DECLARED, "g")
コード例 #4
0
def test_call_extra_arguments():
    assert_error(
        """
        function f();
        main {
            /*!*/ call f(0, 1); /*!*/
        }
    """, Diagnostic.Messages.CALL_WRONG_ARGS_NUMBER, "f", 0, 2)
コード例 #5
0
def test_call_missing_arguments():
    assert_error(
        """
        function f(int a, int b);
        main {
            /*!*/ call f(0); /*!*/
        }
    """, Diagnostic.Messages.CALL_WRONG_ARGS_NUMBER, "f", 2, 1)
コード例 #6
0
def test_call_return_expression_wrong_type():
    assert_error(
        """
        function f() -> int;
        main {
            var int[] a;
            call f() -> /*!*/ a /*!*/;
        }
    """, Diagnostic.Messages.CALL_WRONG_RETURN_EXPRESSION, "f", "int", "int[]")
コード例 #7
0
def test_call_extra_return_expression():
    assert_error(
        """
        function f();
        main {
            var int a;
            call f() -> /*!*/ a /*!*/;
        }
    """, Diagnostic.Messages.FUNCTION_DOES_NOT_RETURN_VALUE, "f")
コード例 #8
0
def test_missing_local_flush():
    assert_error(
        """
        main {
            var int a;
            write 5;
            read a;
        }
    """, Diagnostic.Messages.MISSING_FLUSH)
コード例 #9
0
def test_missing_flush_for_2():
    assert_error(
        """
        main {
            var int a;

            for (i : 5) {
                read a;
                write 4;
            }
        }
    """, Diagnostic.Messages.MISSING_FLUSH)
コード例 #10
0
def test_missing_flush_init():
    assert_error(
        """
        init {
            write 4;
        }
        
        main {
            var int a;
            read a;
        }
    """, Diagnostic.Messages.MISSING_FLUSH)
コード例 #11
0
def test_missing_flush_for_3():
    assert_error(
        """
        main {
            var int a, b;

            for (i : 5) {
                flush;
                read a;
                write 4;
            }
            read b;
        }
    """, Diagnostic.Messages.MISSING_FLUSH)
コード例 #12
0
def test_missing_flush_if():
    assert_error(
        """
        main {
            var int a, b;
            read a;
            if (a) {
                flush;
            } else {
                write 4;
            }
            
            read b;
        }
    """, Diagnostic.Messages.MISSING_FLUSH)
コード例 #13
0
def test_callback_accept_scalars():
    assert_error(
        """
        callback f(int a, /*!*/ int[] b /*!*/) {}
        main {}
    """, Diagnostic.Messages.CALLBACK_PARAMETERS_MUST_BE_SCALARS)
コード例 #14
0
def test_function_returns_scalar():
    assert_error(
        """
        function f() -> /*!*/ int[] /*!*/ ;
        main {}
    """, Diagnostic.Messages.RETURN_TYPE_MUST_BE_SCALAR)
コード例 #15
0
def test_callback_returns_scalar():
    assert_error("""
        callback f(int a) -> /*!*/ int[] /*!*/ {}  
        main {}
    """, "return type must be a scalar")