add tests for mutable circuit variables using self keyword

This commit is contained in:
collin 2020-09-07 13:47:50 -07:00
parent a04160a09e
commit 17784ffb23
9 changed files with 173 additions and 0 deletions

View File

@ -134,6 +134,71 @@ fn test_member_static_function_undefined() {
expect_fail(program)
}
// Mutability
#[test]
fn test_mutate_function_fail() {
let bytes = include_bytes!("mut_function_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_mutate_self_variable() {
let bytes = include_bytes!("mut_self_variable.leo");
let program = parse_program(bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_mutate_self_variable_fail() {
let bytes = include_bytes!("mut_self_variable_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_mutate_self_function_fail() {
let bytes = include_bytes!("mut_self_function_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_mutate_self_static_function_fail() {
let bytes = include_bytes!("mut_self_static_function_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_mutate_static_function_fail() {
let bytes = include_bytes!("mut_static_function_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_mutate_variable() {
let bytes = include_bytes!("mut_variable.leo");
let program = parse_program(bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_mutate_variable_fail() {
let bytes = include_bytes!("mut_variable_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
// Self
#[test]
fn test_self_member_pass() {

View File

@ -0,0 +1,9 @@
circuit Foo {
function bar() {}
}
function main() {
let mut f = Foo { a: 0u8 };
f.bar = 1u8;
}

View File

@ -0,0 +1,15 @@
circuit Foo {
a: u8,
function bar() {}
function set_a(new: u8) {
self.bar = new;
}
}
function main() {
let mut f = Foo { a: 0u8 };
f.set_a(1u8);
}

View File

@ -0,0 +1,15 @@
circuit Foo {
a: u8,
static function bar() {}
function set_a(new: u8) {
self.bar = new;
}
}
function main() {
let mut f = Foo { a: 0u8 };
f.set_a(1u8);
}

View File

@ -0,0 +1,21 @@
circuit Foo {
mut a: u8,
function set_a(new: u8) {
self.a = new;
}
}
function main() {
let mut f = Foo { a: 0u8 };
console.assert(f.a == 0u8);
f.set_a(1u8);
console.assert(f.a == 1u8);
f.set_a(2u8);
console.assert(f.a == 2u8);
}

View File

@ -0,0 +1,13 @@
circuit Foo {
a: u8,
function set_a(new: u8) {
self.a = new;
}
}
function main() {
let mut f = Foo { a: 0u8 };
f.set_a(1u8);
}

View File

@ -0,0 +1,9 @@
circuit Foo {
static function bar() {}
}
function main() {
let mut f = Foo { a: 0u8 };
f.bar = 1u8;
}

View File

@ -0,0 +1,17 @@
circuit Foo {
mut a: u8,
}
function main() {
let mut f = Foo { a: 0u8 };
console.assert(f.a == 0u8);
f.a = 1u8;
console.assert(f.a == 1u8);
f.a = 2u8;
console.assert(f.a == 2u8);
}

View File

@ -0,0 +1,9 @@
circuit Foo {
a: u8,
}
function main() {
let mut f = Foo { a: 0u8 };
f.a = 1u8;
}