コード例 #1
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_string_statement():
    src = """
    // The string constant 'returns itself' when executed, 
    // when this is not printed or assigned to a variable nothing happens.
    func main() { "String type"; }
    """
    run_source(src)
コード例 #2
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_init_array():
    src = """
    func main() {
        var a: array[100];
    }
    """
    run_source(src)
コード例 #3
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_invalid_type():
    src = """
    func test(a: number) { }
    func main() { test("String type"); }
    """
    with pytest.raises(interpreter.InvalidTypeException):
        run_source(src)
コード例 #4
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_assign_void_var():
    src = """
    func main() {
        var a: void = 3;
    }
    """
    with pytest.raises(interpreter.IllegalTypeException):
        run_source(src)
コード例 #5
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_string_literal_typing():
    src = """
    func main() {
        var a: number = "1\";
    }
    """
    with pytest.raises(interpreter.InvalidTypeException):
        run_source(src)
コード例 #6
0
def run_capture_stdout(src: str):
    captured_output = ""

    def stdout_cap(x):
        nonlocal captured_output
        captured_output = captured_output + x

    run_source(src, stdout=stdout_cap)
    return captured_output
コード例 #7
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_str_index_out_of_range():
    src = """
    func main() {
        var a: string = "Hello World";
        println(a[50]);
    }
    """
    with pytest.raises(interpreter.IndexOutOfBoundsException):
        run_source(src)
コード例 #8
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_invalid_implicit_return():
    src = """
    func main() {
        var a = 1;
        a;
        return a;
    }
    """
    with pytest.raises(interpreter.InvalidImplicitReturnException):
        run_source(src)
コード例 #9
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_duplicate_func():
    src = """
    func a(n: number) { }
    func a(n: number) { }

    func main() {
        a(4);
    }
    """
    with pytest.raises(interpreter.SmickelRuntimeException):
        run_source(src)
コード例 #10
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_invalid_implicit_string_return():
    src = """
    func hello(): string {
        "Hello";
        "World";
    }

    func main() {
        println(hello());
    }
    """
    with pytest.raises(interpreter.InvalidImplicitReturnException):
        run_source(src)
コード例 #11
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_invalid_implicit_func_return():
    src = """
    func odd(n: number): bool {
        if(n == 0) { false; }
        even(n - 1);
        even(n - 1);
    }

    func even(n: number): bool {
    if (n == 0) { true; }
        // We even support rust-like implicit returns.
        odd(n - 1)
    }

    func main() {
        odd(5);
    }
    """
    with pytest.raises(interpreter.InvalidImplicitReturnException):
        run_source(src)
コード例 #12
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_var_assignment():
    src = "func main() { var a = 1; }"
    run_source(src)
コード例 #13
0
ファイル: test_extra.py プロジェクト: Fusion86/HU-ATP
def test_comparison_statement():
    src = """
    // Or conditions.
    func main() { true == false; }
    """
    run_source(src)
コード例 #14
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_undefined_variable():
    src = "func main() { println(a); }"
    with pytest.raises(interpreter.UndefinedVariableException):
        run_source(src)
コード例 #15
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_main_void():
    src = "func main(): void { }"
    run_source(src)
コード例 #16
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_main_number_no_return():
    src = "func main(): number { }"
    with pytest.raises(interpreter.InvalidTypeException):
        run_source(src)
コード例 #17
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_return_type():
    src = 'func main(): string { return "Hello"; }'
    run_source(src)
コード例 #18
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_invalid_return_type():
    src = 'func main(): number { return "Hello"; }'
    with pytest.raises(interpreter.InvalidTypeException):
        run_source(src)
コード例 #19
0
ファイル: test_extra.py プロジェクト: Fusion86/HU-ATP
def test_arithmetic_statement():
    src = """
    // Or arithmetic statements.
    func main() { 2 + 4; }
    """
    run_source(src)
コード例 #20
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_number_statement():
    src = """
    // The same is true for numbers.
    func main() { 1; }
    """
    run_source(src)
コード例 #21
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_bool_statement():
    src = """
    // Or bools.
    func main() { true; }
    """
    run_source(src)
コード例 #22
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_return_bool_var():
    src = """
    func main() { var a: bool = true; return a; }
    """
    run_source(src)
コード例 #23
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_return_bool_literal():
    src = """
    func main() { return true; }
    """
    run_source(src)
コード例 #24
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_exit_code():
    src = "func main() { return 1; }"
    res = run_source(src)
    assert res == 1
コード例 #25
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_exit_value():
    src = 'func main() { return "Hello"; }'
    res = run_source(src)
    assert res == "Hello"
コード例 #26
0
ファイル: test_interpreter.py プロジェクト: Fusion86/HU-ATP
def test_empty():
    src = ""
    with pytest.raises(interpreter.EntrypointNotFoundException):
        run_source(src)
コード例 #27
0
ファイル: test_extra.py プロジェクト: Fusion86/HU-ATP
def test_var_assignment_arithmetic():
    src = "func main() { var a = 1 + 4; }"
    run_source(src)