mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 03:04:13 +03:00
add additional tests for import type checking
This commit is contained in:
parent
b4bcfe549a
commit
601ab09226
@ -1,8 +0,0 @@
|
||||
import bar.Bar as Baz;
|
||||
|
||||
circuit Bar {
|
||||
b: u32,
|
||||
}
|
||||
function main() {
|
||||
let b = Baz { b: 0u32 };
|
||||
}
|
9
symbol-table/tests/symbol_table/import_circuit_alias.leo
Normal file
9
symbol-table/tests/symbol_table/import_circuit_alias.leo
Normal file
@ -0,0 +1,9 @@
|
||||
import bar.Bar as Baz;
|
||||
|
||||
circuit Bar {
|
||||
r: bool,
|
||||
}
|
||||
function main() {
|
||||
let z = Baz { z: 0u32 };
|
||||
let r = Bar { r: true };
|
||||
}
|
10
symbol-table/tests/symbol_table/import_function_alias.leo
Normal file
10
symbol-table/tests/symbol_table/import_function_alias.leo
Normal file
@ -0,0 +1,10 @@
|
||||
import foo.foo as boo;
|
||||
|
||||
function foo() -> bool {
|
||||
return false
|
||||
}
|
||||
|
||||
function main() {
|
||||
let z: u8 = boo();
|
||||
let r: bool = foo();
|
||||
}
|
5
symbol-table/tests/symbol_table/import_star.leo
Normal file
5
symbol-table/tests/symbol_table/import_star.leo
Normal file
@ -0,0 +1,5 @@
|
||||
import foo.*;
|
||||
|
||||
function main() {
|
||||
let x: u8 = boo();
|
||||
}
|
5
symbol-table/tests/symbol_table/import_undefined.leo
Normal file
5
symbol-table/tests/symbol_table/import_undefined.leo
Normal file
@ -0,0 +1,5 @@
|
||||
import foo.boo;
|
||||
|
||||
function main() {
|
||||
let x: u8 = boo();
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
circuit Bar {
|
||||
b: u32
|
||||
z: u32
|
||||
}
|
3
symbol-table/tests/symbol_table/imports/foo.leo
Normal file
3
symbol-table/tests/symbol_table/imports/foo.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function foo() -> u8 {
|
||||
return 5u8
|
||||
}
|
@ -16,7 +16,9 @@
|
||||
|
||||
use crate::TestSymbolTable;
|
||||
|
||||
use leo_ast::Input;
|
||||
use leo_imports::ImportParser;
|
||||
use leo_symbol_table::{SymbolTable, SymbolTableError};
|
||||
|
||||
///
|
||||
/// Defines a circuit `Foo {}`.
|
||||
@ -76,9 +78,72 @@ fn test_undefined_circuit() {
|
||||
resolver.expect_pass_two_error();
|
||||
}
|
||||
|
||||
///
|
||||
/// Imports an undefined function `boo` from file foo.leo.
|
||||
///
|
||||
/// Expected output: SymbolTableError
|
||||
/// Message: Cannot find imported symbol `boo` in imported file ``
|
||||
///
|
||||
#[test]
|
||||
fn test_import_alias() {
|
||||
let program_string = include_str!("import_alias.leo");
|
||||
fn test_import_undefined() {
|
||||
let program_string = include_str!("import_undefined.leo");
|
||||
let import_string = include_str!("imports/foo.leo");
|
||||
|
||||
let program_table = TestSymbolTable::new(program_string);
|
||||
let import_table = TestSymbolTable::new(import_string);
|
||||
|
||||
let import_program = import_table.ast.into_repr();
|
||||
|
||||
let mut imports = ImportParser::default();
|
||||
imports.insert_import("foo".to_owned(), import_program);
|
||||
|
||||
// Create new symbol table.
|
||||
let static_check = &mut SymbolTable::default();
|
||||
|
||||
// Run pass one and expect an error.
|
||||
let error = static_check
|
||||
.check_names(&program_table.ast.into_repr(), &imports, &Input::new())
|
||||
.unwrap_err();
|
||||
|
||||
match error {
|
||||
SymbolTableError::Error(_) => {} // Ok
|
||||
error => panic!("Expected a symbol table error found `{}`", error),
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Imports all functions from file foo.leo.
|
||||
/// Calls function `foo` defined in foo.leo.
|
||||
///
|
||||
/// Expected output: Test Pass
|
||||
///
|
||||
#[test]
|
||||
fn test_import_star() {
|
||||
let program_string = include_str!("import_star.leo");
|
||||
let import_string = include_str!("imports/foo.leo");
|
||||
|
||||
let program_table = TestSymbolTable::new(program_string);
|
||||
let import_table = TestSymbolTable::new(import_string);
|
||||
|
||||
let import_program = import_table.ast.into_repr();
|
||||
|
||||
let mut imports = ImportParser::default();
|
||||
imports.insert_import("foo".to_owned(), import_program);
|
||||
|
||||
program_table.expect_success(imports);
|
||||
}
|
||||
|
||||
///
|
||||
/// Imports a circuit named `Bar` from file bar.leo.
|
||||
/// Renames `Bar` => `Baz`.
|
||||
/// Defines a circuit named `Bar` in main.leo.
|
||||
/// Instantiates circuits `Bar` and `Baz`.
|
||||
///
|
||||
/// Expected output: Test Pass
|
||||
///
|
||||
#[test]
|
||||
fn test_import_circuit_alias() {
|
||||
let program_string = include_str!("import_circuit_alias.leo");
|
||||
let import_string = include_str!("imports/bar.leo");
|
||||
|
||||
let program_table = TestSymbolTable::new(program_string);
|
||||
@ -91,3 +156,27 @@ fn test_import_alias() {
|
||||
|
||||
program_table.expect_success(imports);
|
||||
}
|
||||
|
||||
///
|
||||
/// Imports a function named `foo` from file foo.leo.
|
||||
/// Renames `foo` => `boo`.
|
||||
/// Defines a function named `foo` in main.leo.
|
||||
/// Calls functions `foo` and `boo`.
|
||||
///
|
||||
/// Expected output: Test Pass
|
||||
///
|
||||
#[test]
|
||||
fn test_import_function_alias() {
|
||||
let program_string = include_str!("import_function_alias.leo");
|
||||
let import_string = include_str!("imports/foo.leo");
|
||||
|
||||
let program_table = TestSymbolTable::new(program_string);
|
||||
let import_table = TestSymbolTable::new(import_string);
|
||||
|
||||
let import_program = import_table.ast.into_repr();
|
||||
|
||||
let mut imports = ImportParser::default();
|
||||
imports.insert_import("foo".to_owned(), import_program);
|
||||
|
||||
program_table.expect_success(imports);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user