From d35188abcb76f8b0fce041255a40e0cd5e94a083 Mon Sep 17 00:00:00 2001 From: collin Date: Wed, 2 Sep 2020 18:01:47 -0700 Subject: [PATCH] test mutable circuit variables --- .../tests/mutability/circuit_function_mut.leo | 9 +++++++ .../circuit_static_function_mut.leo | 9 +++++++ .../tests/mutability/circuit_variable_mut.leo | 11 +++++++++ compiler/tests/mutability/mod.rs | 24 +++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 compiler/tests/mutability/circuit_function_mut.leo create mode 100644 compiler/tests/mutability/circuit_static_function_mut.leo create mode 100644 compiler/tests/mutability/circuit_variable_mut.leo diff --git a/compiler/tests/mutability/circuit_function_mut.leo b/compiler/tests/mutability/circuit_function_mut.leo new file mode 100644 index 0000000000..eba1d02c0e --- /dev/null +++ b/compiler/tests/mutability/circuit_function_mut.leo @@ -0,0 +1,9 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + function bar() {} +} + +function main() { + let mut a = Foo { x: 1 }; + a.bar = 0; +} \ No newline at end of file diff --git a/compiler/tests/mutability/circuit_static_function_mut.leo b/compiler/tests/mutability/circuit_static_function_mut.leo new file mode 100644 index 0000000000..0717f51c44 --- /dev/null +++ b/compiler/tests/mutability/circuit_static_function_mut.leo @@ -0,0 +1,9 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + static function bar() {} +} + +function main() { + let mut a = Foo { x: 1 }; + a.bar = 0; +} \ No newline at end of file diff --git a/compiler/tests/mutability/circuit_variable_mut.leo b/compiler/tests/mutability/circuit_variable_mut.leo new file mode 100644 index 0000000000..f87668c48e --- /dev/null +++ b/compiler/tests/mutability/circuit_variable_mut.leo @@ -0,0 +1,11 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + mut x: u32 +} + +function main() { + let mut a = Foo { x: 1 }; + a.x = 0; + + console.assert(a.x == 0u32); +} \ No newline at end of file diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index 3c00bab145..ea380447bf 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -78,9 +78,33 @@ fn test_circuit_mut() { let bytes = include_bytes!("circuit_mut.leo"); let program = parse_program(bytes).unwrap(); + expect_compiler_error(program); +} + +#[test] +fn test_circuit_variable_mut() { + let bytes = include_bytes!("circuit_variable_mut.leo"); + let program = parse_program(bytes).unwrap(); + assert_satisfied(program); } +#[test] +fn test_circuit_function_mut() { + let bytes = include_bytes!("circuit_function_mut.leo"); + let program = parse_program(bytes).unwrap(); + + expect_compiler_error(program); +} + +#[test] +fn test_circuit_static_function_mut() { + let bytes = include_bytes!("circuit_static_function_mut.leo"); + let program = parse_program(bytes).unwrap(); + + expect_compiler_error(program); +} + #[test] fn test_function_input() { let bytes = include_bytes!("function_input.leo");