fix tests
This commit is contained in:
parent
124788f3de
commit
12c4cd2a52
5 changed files with 157 additions and 221 deletions
|
@ -678,19 +678,12 @@ mod tests {
|
||||||
let file = File::open(path.clone()).unwrap();
|
let file = File::open(path.clone()).unwrap();
|
||||||
|
|
||||||
let mut reader = BufReader::new(file);
|
let mut reader = BufReader::new(file);
|
||||||
let location = path
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.to_path_buf()
|
|
||||||
.into_os_string()
|
|
||||||
.into_string()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut source = String::new();
|
let mut source = String::new();
|
||||||
reader.read_to_string(&mut source).unwrap();
|
reader.read_to_string(&mut source).unwrap();
|
||||||
|
|
||||||
let _: CompilationArtifacts<FieldPrime> =
|
let _: CompilationArtifacts<FieldPrime> =
|
||||||
compile(source, location, Some(&fs_resolve)).unwrap();
|
compile(source, path, Some(&fs_resolve)).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,20 +699,12 @@ mod tests {
|
||||||
|
|
||||||
let file = File::open(path.clone()).unwrap();
|
let file = File::open(path.clone()).unwrap();
|
||||||
|
|
||||||
let location = path
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.to_path_buf()
|
|
||||||
.into_os_string()
|
|
||||||
.into_string()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut reader = BufReader::new(file);
|
let mut reader = BufReader::new(file);
|
||||||
let mut source = String::new();
|
let mut source = String::new();
|
||||||
reader.read_to_string(&mut source).unwrap();
|
reader.read_to_string(&mut source).unwrap();
|
||||||
|
|
||||||
let artifacts: CompilationArtifacts<FieldPrime> =
|
let artifacts: CompilationArtifacts<FieldPrime> =
|
||||||
compile(source, location, Some(&fs_resolve)).unwrap();
|
compile(source, path, Some(&fs_resolve)).unwrap();
|
||||||
|
|
||||||
let _ = artifacts
|
let _ = artifacts
|
||||||
.prog()
|
.prog()
|
||||||
|
@ -741,20 +726,12 @@ mod tests {
|
||||||
|
|
||||||
let file = File::open(path.clone()).unwrap();
|
let file = File::open(path.clone()).unwrap();
|
||||||
|
|
||||||
let location = path
|
|
||||||
.parent()
|
|
||||||
.unwrap()
|
|
||||||
.to_path_buf()
|
|
||||||
.into_os_string()
|
|
||||||
.into_string()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut reader = BufReader::new(file);
|
let mut reader = BufReader::new(file);
|
||||||
let mut source = String::new();
|
let mut source = String::new();
|
||||||
reader.read_to_string(&mut source).unwrap();
|
reader.read_to_string(&mut source).unwrap();
|
||||||
|
|
||||||
let artifacts: CompilationArtifacts<FieldPrime> =
|
let artifacts: CompilationArtifacts<FieldPrime> =
|
||||||
compile(source, location, Some(&fs_resolve)).unwrap();
|
compile(source, path, Some(&fs_resolve)).unwrap();
|
||||||
|
|
||||||
let _ = artifacts
|
let _ = artifacts
|
||||||
.prog()
|
.prog()
|
||||||
|
|
|
@ -228,13 +228,10 @@ mod test {
|
||||||
return foo()
|
return foo()
|
||||||
"#
|
"#
|
||||||
.to_string();
|
.to_string();
|
||||||
let res: Result<CompilationArtifacts<FieldPrime>, CompileErrors> = compile(
|
let res: Result<CompilationArtifacts<FieldPrime>, CompileErrors> =
|
||||||
source,
|
compile(source, "./path/to/file".into(), None::<Resolve<io::Error>>);
|
||||||
String::from("./path/to/file"),
|
assert!(res.unwrap_err().0[0]
|
||||||
None::<Resolve<io::Error>>,
|
.value()
|
||||||
);
|
|
||||||
assert!(res
|
|
||||||
.unwrap_err()
|
|
||||||
.to_string()
|
.to_string()
|
||||||
.contains(&"Can't resolve import without a resolver"));
|
.contains(&"Can't resolve import without a resolver"));
|
||||||
}
|
}
|
||||||
|
@ -246,11 +243,8 @@ mod test {
|
||||||
return 1
|
return 1
|
||||||
"#
|
"#
|
||||||
.to_string();
|
.to_string();
|
||||||
let res: Result<CompilationArtifacts<FieldPrime>, CompileErrors> = compile(
|
let res: Result<CompilationArtifacts<FieldPrime>, CompileErrors> =
|
||||||
source,
|
compile(source, "./path/to/file".into(), None::<Resolve<io::Error>>);
|
||||||
String::from("./path/to/file"),
|
|
||||||
None::<Resolve<io::Error>>,
|
|
||||||
);
|
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,10 +261,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_with_no_alias() {
|
fn create_with_no_alias() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Import::new(None, "./foo/bar/baz.zok"),
|
Import::new(None, Path::new("./foo/bar/baz.zok")),
|
||||||
Import {
|
Import {
|
||||||
symbol: None,
|
symbol: None,
|
||||||
source: "./foo/bar/baz.zok",
|
source: Path::new("./foo/bar/baz.zok"),
|
||||||
alias: None,
|
alias: None,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -273,10 +273,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn create_with_alias() {
|
fn create_with_alias() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Import::new_with_alias(None, "./foo/bar/baz.zok", &"myalias"),
|
Import::new_with_alias(None, Path::new("./foo/bar/baz.zok"), &"myalias"),
|
||||||
Import {
|
Import {
|
||||||
symbol: None,
|
symbol: None,
|
||||||
source: "./foo/bar/baz.zok",
|
source: Path::new("./foo/bar/baz.zok"),
|
||||||
alias: Some("myalias"),
|
alias: Some("myalias"),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -2007,7 +2007,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn element_type_mismatch() {
|
fn element_type_mismatch() {
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
// [3, true]
|
// [3, true]
|
||||||
let a = Expression::InlineArray(vec![
|
let a = Expression::InlineArray(vec![
|
||||||
Expression::FieldConstant(FieldPrime::from(3)).mock().into(),
|
Expression::FieldConstant(FieldPrime::from(3)).mock().into(),
|
||||||
|
@ -2169,19 +2169,16 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(
|
let mut state = State::new(
|
||||||
vec![(String::from("foo"), foo), (String::from("bar"), bar)]
|
vec![("foo".into(), foo), ("bar".into(), bar)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
|
|
||||||
|
assert_eq!(checker.check_module(&"bar".into(), &mut state), Ok(()));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_module(&String::from("bar"), &mut state),
|
state.typed_modules.get(&"bar".to_string()),
|
||||||
Ok(())
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
state.typed_modules.get(&String::from("bar")),
|
|
||||||
Some(&TypedModule {
|
Some(&TypedModule {
|
||||||
functions: vec![(
|
functions: vec![(
|
||||||
FunctionKey::with_id("main").signature(Signature::new()),
|
FunctionKey::with_id("main").signature(Signature::new()),
|
||||||
|
@ -2221,13 +2218,14 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(MODULE_ID.to_string(), module)].into_iter().collect());
|
let mut state = State::new(vec![(MODULE_ID.into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker
|
checker
|
||||||
.check_module(&MODULE_ID.to_string(), &mut state)
|
.check_module(&MODULE_ID.into(), &mut state)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
.inner
|
||||||
.message,
|
.message,
|
||||||
"foo conflicts with another symbol"
|
"foo conflicts with another symbol"
|
||||||
);
|
);
|
||||||
|
@ -2258,13 +2256,10 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(MODULE_ID.to_string(), module)].into_iter().collect());
|
let mut state = State::new(vec![(MODULE_ID.into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(checker.check_module(&MODULE_ID.into(), &mut state), Ok(()));
|
||||||
checker.check_module(&MODULE_ID.to_string(), &mut state),
|
|
||||||
Ok(())
|
|
||||||
);
|
|
||||||
assert!(state
|
assert!(state
|
||||||
.typed_modules
|
.typed_modules
|
||||||
.get(&MODULE_ID.to_string())
|
.get(&MODULE_ID.to_string())
|
||||||
|
@ -2305,13 +2300,14 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(String::from("main"), module)].into_iter().collect());
|
let mut state = State::new(vec![("main".into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker
|
checker
|
||||||
.check_module(&String::from("main"), &mut state)
|
.check_module(&"main".into(), &mut state)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
.inner
|
||||||
.message,
|
.message,
|
||||||
"foo conflicts with another symbol"
|
"foo conflicts with another symbol"
|
||||||
);
|
);
|
||||||
|
@ -2341,13 +2337,14 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(String::from("main"), module)].into_iter().collect());
|
let mut state = State::new(vec![("main".into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker
|
checker
|
||||||
.check_module(&String::from("main"), &mut state)
|
.check_module(&"main".into(), &mut state)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
.inner
|
||||||
.message,
|
.message,
|
||||||
"foo conflicts with another symbol"
|
"foo conflicts with another symbol"
|
||||||
);
|
);
|
||||||
|
@ -2377,7 +2374,7 @@ mod tests {
|
||||||
SymbolDeclaration {
|
SymbolDeclaration {
|
||||||
id: "foo",
|
id: "foo",
|
||||||
symbol: Symbol::There(
|
symbol: Symbol::There(
|
||||||
SymbolImport::with_id_in_module("main", "bar".to_string()).mock(),
|
SymbolImport::with_id_in_module("main", "bar").mock(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
.mock(),
|
.mock(),
|
||||||
|
@ -2391,7 +2388,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(
|
let mut state = State::new(
|
||||||
vec![(MODULE_ID.to_string(), main), ("bar".to_string(), bar)]
|
vec![(MODULE_ID.into(), main), ("bar".into(), bar)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
|
@ -2399,8 +2396,9 @@ mod tests {
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker
|
checker
|
||||||
.check_module(&MODULE_ID.to_string(), &mut state)
|
.check_module(&MODULE_ID.into(), &mut state)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
.inner
|
||||||
.message,
|
.message,
|
||||||
"foo conflicts with another symbol"
|
"foo conflicts with another symbol"
|
||||||
);
|
);
|
||||||
|
@ -2432,7 +2430,7 @@ mod tests {
|
||||||
SymbolDeclaration {
|
SymbolDeclaration {
|
||||||
id: "foo",
|
id: "foo",
|
||||||
symbol: Symbol::There(
|
symbol: Symbol::There(
|
||||||
SymbolImport::with_id_in_module("main", "bar".to_string()).mock(),
|
SymbolImport::with_id_in_module("main", "bar").mock(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
.mock(),
|
.mock(),
|
||||||
|
@ -2441,7 +2439,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(
|
let mut state = State::new(
|
||||||
vec![(MODULE_ID.to_string(), main), ("bar".to_string(), bar)]
|
vec![(MODULE_ID.into(), main), ("bar".into(), bar)]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
|
@ -2449,8 +2447,9 @@ mod tests {
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker
|
checker
|
||||||
.check_module(&MODULE_ID.to_string(), &mut state)
|
.check_module(&MODULE_ID.into(), &mut state)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
.inner
|
||||||
.message,
|
.message,
|
||||||
"foo conflicts with another symbol"
|
"foo conflicts with another symbol"
|
||||||
);
|
);
|
||||||
|
@ -2480,14 +2479,14 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_statement(statement, &module_id, &types),
|
checker.check_statement(statement, &module_id, &types),
|
||||||
Err(vec![ErrorInner {
|
Err(vec![ErrorInner {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message: "Identifier \"b\" is undefined".to_string()
|
message: "Identifier \"b\" is undefined".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2503,7 +2502,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut scope = HashSet::new();
|
let mut scope = HashSet::new();
|
||||||
scope.insert(ScopedVariable {
|
scope.insert(ScopedVariable {
|
||||||
|
@ -2589,14 +2588,17 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(String::from("main"), module)].into_iter().collect());
|
let mut state = State::new(vec![("main".into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_module(&String::from("main"), &mut state),
|
checker.check_module(&"main".into(), &mut state),
|
||||||
Err(vec![ErrorInner {
|
Err(vec![Error {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
inner: ErrorInner {
|
||||||
message: "Identifier \"a\" is undefined".to_string()
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
|
message: "Identifier \"a\" is undefined".into()
|
||||||
|
},
|
||||||
|
module_id: "main".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2704,12 +2706,10 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(String::from("main"), module)].into_iter().collect());
|
let mut state = State::new(vec![("main".into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert!(checker
|
assert!(checker.check_module(&"main".into(), &mut state).is_ok());
|
||||||
.check_module(&String::from("main"), &mut state)
|
|
||||||
.is_ok());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -2746,14 +2746,14 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_function(foo, &module_id, &types),
|
checker.check_function(foo, &module_id, &types),
|
||||||
Err(vec![ErrorInner {
|
Err(vec![ErrorInner {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message: "Identifier \"i\" is undefined".to_string()
|
message: "Identifier \"i\" is undefined".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2821,7 +2821,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2870,7 +2870,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, functions);
|
let mut checker = new_with_args(HashSet::new(), 0, functions);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2879,7 +2879,7 @@ mod tests {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message:
|
message:
|
||||||
"Function definition for function foo with signature () -> (field) not found."
|
"Function definition for function foo with signature () -> (field) not found."
|
||||||
.to_string()
|
.into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2918,7 +2918,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, functions);
|
let mut checker = new_with_args(HashSet::new(), 0, functions);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2926,7 +2926,7 @@ mod tests {
|
||||||
Err(vec![ErrorInner {
|
Err(vec![ErrorInner {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message: "Function definition for function foo with signature () -> (_) not found."
|
message: "Function definition for function foo with signature () -> (_) not found."
|
||||||
.to_string()
|
.into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2959,7 +2959,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2969,7 +2969,7 @@ mod tests {
|
||||||
|
|
||||||
message:
|
message:
|
||||||
"Function definition for function foo with signature () -> (field) not found."
|
"Function definition for function foo with signature () -> (field) not found."
|
||||||
.to_string()
|
.into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3063,14 +3063,17 @@ mod tests {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut state = State::new(vec![(String::from("main"), module)].into_iter().collect());
|
let mut state = State::new(vec![("main".into(), module)].into_iter().collect());
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_module(&String::from("main"), &mut state),
|
checker.check_module(&"main".into(), &mut state),
|
||||||
Err(vec![ErrorInner {
|
Err(vec![Error {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
inner: ErrorInner {
|
||||||
message: "Identifier \"x\" is undefined".to_string()
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
|
message: "Identifier \"x\" is undefined".into()
|
||||||
|
},
|
||||||
|
module_id: "main".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3097,7 +3100,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -3106,7 +3109,7 @@ mod tests {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
|
|
||||||
message: "Function definition for function foo with signature () -> (_) not found."
|
message: "Function definition for function foo with signature () -> (_) not found."
|
||||||
.to_string()
|
.into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3141,14 +3144,14 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
let mut checker = new_with_args(HashSet::new(), 0, HashSet::new());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_function(bar, &module_id, &types),
|
checker.check_function(bar, &module_id, &types),
|
||||||
Err(vec![ErrorInner {
|
Err(vec![ErrorInner {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message: "Identifier \"a\" is undefined".to_string()
|
message: "Identifier \"a\" is undefined".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3246,7 +3249,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = new_with_args(HashSet::new(), 0, functions);
|
let mut checker = new_with_args(HashSet::new(), 0, functions);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -3326,18 +3329,19 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let program = Program {
|
let program = Program {
|
||||||
modules: vec![(String::from("main"), main_module)]
|
modules: vec![("main".into(), main_module)].into_iter().collect(),
|
||||||
.into_iter()
|
main: "main".into(),
|
||||||
.collect(),
|
|
||||||
main: String::from("main"),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_program(program),
|
checker.check_program(program),
|
||||||
Err(vec![ErrorInner {
|
Err(vec![Error {
|
||||||
pos: None,
|
inner: ErrorInner {
|
||||||
message: "Only one main function allowed, found 2".to_string()
|
pos: None,
|
||||||
|
message: "Only one main function allowed, found 2".into()
|
||||||
|
},
|
||||||
|
module_id: "main".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3350,7 +3354,7 @@ mod tests {
|
||||||
// should fail
|
// should fail
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
let _: Result<TypedStatement<FieldPrime>, Vec<ErrorInner>> = checker.check_statement(
|
let _: Result<TypedStatement<FieldPrime>, Vec<ErrorInner>> = checker.check_statement(
|
||||||
Statement::Declaration(
|
Statement::Declaration(
|
||||||
|
@ -3373,7 +3377,7 @@ mod tests {
|
||||||
s2_checked,
|
s2_checked,
|
||||||
Err(vec![ErrorInner {
|
Err(vec![ErrorInner {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message: "Duplicate declaration for variable named a".to_string()
|
message: "Duplicate declaration for variable named a".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3386,7 +3390,7 @@ mod tests {
|
||||||
// should fail
|
// should fail
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker = Checker::new();
|
let mut checker = Checker::new();
|
||||||
let _: Result<TypedStatement<FieldPrime>, Vec<ErrorInner>> = checker.check_statement(
|
let _: Result<TypedStatement<FieldPrime>, Vec<ErrorInner>> = checker.check_statement(
|
||||||
|
@ -3410,7 +3414,7 @@ mod tests {
|
||||||
s2_checked,
|
s2_checked,
|
||||||
Err(vec![ErrorInner {
|
Err(vec![ErrorInner {
|
||||||
pos: Some((Position::mock(), Position::mock())),
|
pos: Some((Position::mock(), Position::mock())),
|
||||||
message: "Duplicate declaration for variable named a".to_string()
|
message: "Duplicate declaration for variable named a".into()
|
||||||
}])
|
}])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3422,7 +3426,7 @@ mod tests {
|
||||||
fn create_module_with_foo(
|
fn create_module_with_foo(
|
||||||
s: StructType<'static>,
|
s: StructType<'static>,
|
||||||
) -> (Checker<'static>, State<'static, FieldPrime>) {
|
) -> (Checker<'static>, State<'static, FieldPrime>) {
|
||||||
let module_id = "".to_string();
|
let module_id: PathBuf = "".into();
|
||||||
|
|
||||||
let module: Module<FieldPrime> = Module {
|
let module: Module<FieldPrime> = Module {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
|
@ -3449,7 +3453,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_def() {
|
fn empty_def() {
|
||||||
// an empty struct should be allowed to be defined
|
// an empty struct should be allowed to be defined
|
||||||
let module_id = "".to_string();
|
let module_id = "".into();
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let declaration = StructType { fields: vec![] }.mock();
|
let declaration = StructType { fields: vec![] }.mock();
|
||||||
|
|
||||||
|
@ -3464,7 +3468,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn valid_def() {
|
fn valid_def() {
|
||||||
// a valid struct should be allowed to be defined
|
// a valid struct should be allowed to be defined
|
||||||
let module_id = "".to_string();
|
let module_id = "".into();
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let declaration = StructType {
|
let declaration = StructType {
|
||||||
fields: vec![
|
fields: vec![
|
||||||
|
@ -3483,8 +3487,8 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let expected_type = Type::Struct(vec![
|
let expected_type = Type::Struct(vec![
|
||||||
StructMember::new("foo".to_string(), Type::FieldElement),
|
StructMember::new("foo".into(), Type::FieldElement),
|
||||||
StructMember::new("bar".to_string(), Type::Boolean),
|
StructMember::new("bar".into(), Type::Boolean),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -3496,7 +3500,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn preserve_order() {
|
fn preserve_order() {
|
||||||
// two structs with inverted members are not equal
|
// two structs with inverted members are not equal
|
||||||
let module_id = "".to_string();
|
let module_id = "".into();
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
|
|
||||||
let declaration0 = StructType {
|
let declaration0 = StructType {
|
||||||
|
@ -3540,7 +3544,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn duplicate_member_def() {
|
fn duplicate_member_def() {
|
||||||
// definition of a struct with a duplicate member should be rejected
|
// definition of a struct with a duplicate member should be rejected
|
||||||
let module_id = "".to_string();
|
let module_id = "".into();
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
|
|
||||||
let declaration = StructType {
|
let declaration = StructType {
|
||||||
|
@ -3575,7 +3579,7 @@ mod tests {
|
||||||
// struct Foo = { foo: field }
|
// struct Foo = { foo: field }
|
||||||
// struct Bar = { foo: Foo }
|
// struct Bar = { foo: Foo }
|
||||||
|
|
||||||
let module_id = "".to_string();
|
let module_id: PathBuf = "".into();
|
||||||
|
|
||||||
let module: Module<FieldPrime> = Module {
|
let module: Module<FieldPrime> = Module {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
|
@ -3600,7 +3604,7 @@ mod tests {
|
||||||
StructType {
|
StructType {
|
||||||
fields: vec![StructField {
|
fields: vec![StructField {
|
||||||
id: "foo",
|
id: "foo",
|
||||||
ty: UnresolvedType::User("Foo".to_string()).mock(),
|
ty: UnresolvedType::User("Foo".into()).mock(),
|
||||||
}
|
}
|
||||||
.mock()],
|
.mock()],
|
||||||
}
|
}
|
||||||
|
@ -3617,16 +3621,13 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
state
|
state
|
||||||
.types
|
.types
|
||||||
.get(&"".to_string())
|
.get(&module_id)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.get(&"Bar".to_string())
|
.get(&"Bar".to_string())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
&Type::Struct(vec![StructMember::new(
|
&Type::Struct(vec![StructMember::new(
|
||||||
"foo".to_string(),
|
"foo".into(),
|
||||||
Type::Struct(vec![StructMember::new(
|
Type::Struct(vec![StructMember::new("foo".into(), Type::FieldElement)])
|
||||||
"foo".to_string(),
|
|
||||||
Type::FieldElement
|
|
||||||
)])
|
|
||||||
)])
|
)])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3637,7 +3638,7 @@ mod tests {
|
||||||
|
|
||||||
// struct Bar = { foo: Foo }
|
// struct Bar = { foo: Foo }
|
||||||
|
|
||||||
let module_id = "".to_string();
|
let module_id: PathBuf = "".into();
|
||||||
|
|
||||||
let module: Module<FieldPrime> = Module {
|
let module: Module<FieldPrime> = Module {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
|
@ -3647,7 +3648,7 @@ mod tests {
|
||||||
StructType {
|
StructType {
|
||||||
fields: vec![StructField {
|
fields: vec![StructField {
|
||||||
id: "foo",
|
id: "foo",
|
||||||
ty: UnresolvedType::User("Foo".to_string()).mock(),
|
ty: UnresolvedType::User("Foo".into()).mock(),
|
||||||
}
|
}
|
||||||
.mock()],
|
.mock()],
|
||||||
}
|
}
|
||||||
|
@ -3668,7 +3669,7 @@ mod tests {
|
||||||
|
|
||||||
// struct Foo = { foo: Foo }
|
// struct Foo = { foo: Foo }
|
||||||
|
|
||||||
let module_id = "".to_string();
|
let module_id: PathBuf = "".into();
|
||||||
|
|
||||||
let module: Module<FieldPrime> = Module {
|
let module: Module<FieldPrime> = Module {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
|
@ -3678,7 +3679,7 @@ mod tests {
|
||||||
StructType {
|
StructType {
|
||||||
fields: vec![StructField {
|
fields: vec![StructField {
|
||||||
id: "foo",
|
id: "foo",
|
||||||
ty: UnresolvedType::User("Foo".to_string()).mock(),
|
ty: UnresolvedType::User("Foo".into()).mock(),
|
||||||
}
|
}
|
||||||
.mock()],
|
.mock()],
|
||||||
}
|
}
|
||||||
|
@ -3700,7 +3701,7 @@ mod tests {
|
||||||
// struct Foo = { bar: Bar }
|
// struct Foo = { bar: Bar }
|
||||||
// struct Bar = { foo: Foo }
|
// struct Bar = { foo: Foo }
|
||||||
|
|
||||||
let module_id = "".to_string();
|
let module_id: PathBuf = "".into();
|
||||||
|
|
||||||
let module: Module<FieldPrime> = Module {
|
let module: Module<FieldPrime> = Module {
|
||||||
imports: vec![],
|
imports: vec![],
|
||||||
|
@ -3711,7 +3712,7 @@ mod tests {
|
||||||
StructType {
|
StructType {
|
||||||
fields: vec![StructField {
|
fields: vec![StructField {
|
||||||
id: "bar",
|
id: "bar",
|
||||||
ty: UnresolvedType::User("Bar".to_string()).mock(),
|
ty: UnresolvedType::User("Bar".into()).mock(),
|
||||||
}
|
}
|
||||||
.mock()],
|
.mock()],
|
||||||
}
|
}
|
||||||
|
@ -3725,7 +3726,7 @@ mod tests {
|
||||||
StructType {
|
StructType {
|
||||||
fields: vec![StructField {
|
fields: vec![StructField {
|
||||||
id: "foo",
|
id: "foo",
|
||||||
ty: UnresolvedType::User("Foo".to_string()).mock(),
|
ty: UnresolvedType::User("Foo".into()).mock(),
|
||||||
}
|
}
|
||||||
.mock()],
|
.mock()],
|
||||||
}
|
}
|
||||||
|
@ -3765,12 +3766,12 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_type(
|
checker.check_type(
|
||||||
UnresolvedType::User("Foo".to_string()).mock(),
|
UnresolvedType::User("Foo".into()).mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
),
|
),
|
||||||
Ok(Type::Struct(vec![StructMember::new(
|
Ok(Type::Struct(vec![StructMember::new(
|
||||||
"foo".to_string(),
|
"foo".into(),
|
||||||
Type::FieldElement
|
Type::FieldElement
|
||||||
)]))
|
)]))
|
||||||
);
|
);
|
||||||
|
@ -3778,8 +3779,8 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker
|
checker
|
||||||
.check_type(
|
.check_type(
|
||||||
UnresolvedType::User("Bar".to_string()).mock(),
|
UnresolvedType::User("Bar".into()).mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
)
|
)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
|
@ -3805,24 +3806,19 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_parameter(
|
checker.check_parameter(
|
||||||
absy::Parameter {
|
absy::Parameter {
|
||||||
id: absy::Variable::new(
|
id:
|
||||||
"a",
|
absy::Variable::new("a", UnresolvedType::User("Foo".into()).mock(),)
|
||||||
UnresolvedType::User("Foo".to_string()).mock(),
|
.mock(),
|
||||||
)
|
|
||||||
.mock(),
|
|
||||||
private: true,
|
private: true,
|
||||||
}
|
}
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types,
|
&state.types,
|
||||||
),
|
),
|
||||||
Ok(Parameter {
|
Ok(Parameter {
|
||||||
id: Variable::with_id_and_type(
|
id: Variable::with_id_and_type(
|
||||||
"a".into(),
|
"a".into(),
|
||||||
Type::Struct(vec![StructMember::new(
|
Type::Struct(vec![StructMember::new("foo".into(), Type::FieldElement)])
|
||||||
"foo".to_string(),
|
|
||||||
Type::FieldElement
|
|
||||||
)])
|
|
||||||
),
|
),
|
||||||
private: true
|
private: true
|
||||||
})
|
})
|
||||||
|
@ -3834,13 +3830,13 @@ mod tests {
|
||||||
absy::Parameter {
|
absy::Parameter {
|
||||||
id: absy::Variable::new(
|
id: absy::Variable::new(
|
||||||
"a",
|
"a",
|
||||||
UnresolvedType::User("Bar".to_string()).mock(),
|
UnresolvedType::User("Bar".into()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
private: true,
|
private: true,
|
||||||
}
|
}
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types,
|
&state.types,
|
||||||
)
|
)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
@ -3866,22 +3862,16 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_statement::<FieldPrime>(
|
checker.check_statement::<FieldPrime>(
|
||||||
Statement::Declaration(
|
Statement::Declaration(
|
||||||
absy::Variable::new(
|
absy::Variable::new("a", UnresolvedType::User("Foo".into()).mock(),)
|
||||||
"a",
|
.mock()
|
||||||
UnresolvedType::User("Foo".to_string()).mock(),
|
|
||||||
)
|
|
||||||
.mock()
|
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types,
|
&state.types,
|
||||||
),
|
),
|
||||||
Ok(TypedStatement::Declaration(Variable::with_id_and_type(
|
Ok(TypedStatement::Declaration(Variable::with_id_and_type(
|
||||||
"a".into(),
|
"a".into(),
|
||||||
Type::Struct(vec![StructMember::new(
|
Type::Struct(vec![StructMember::new("foo".into(), Type::FieldElement)])
|
||||||
"foo".to_string(),
|
|
||||||
Type::FieldElement
|
|
||||||
)])
|
|
||||||
)))
|
)))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3891,13 +3881,13 @@ mod tests {
|
||||||
absy::Parameter {
|
absy::Parameter {
|
||||||
id: absy::Variable::new(
|
id: absy::Variable::new(
|
||||||
"a",
|
"a",
|
||||||
UnresolvedType::User("Bar".to_string()).mock(),
|
UnresolvedType::User("Bar".into()).mock(),
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
private: true,
|
private: true,
|
||||||
}
|
}
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types,
|
&state.types,
|
||||||
)
|
)
|
||||||
.unwrap_err()[0]
|
.unwrap_err()[0]
|
||||||
|
@ -3930,7 +3920,7 @@ mod tests {
|
||||||
checker.check_expression(
|
checker.check_expression(
|
||||||
Expression::Member(
|
Expression::Member(
|
||||||
box Expression::InlineStruct(
|
box Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![(
|
vec![(
|
||||||
"foo",
|
"foo",
|
||||||
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
||||||
|
@ -3940,7 +3930,7 @@ mod tests {
|
||||||
"foo".into()
|
"foo".into()
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
),
|
),
|
||||||
Ok(FieldElementExpression::Member(
|
Ok(FieldElementExpression::Member(
|
||||||
|
@ -3948,11 +3938,8 @@ mod tests {
|
||||||
FieldPrime::from(42)
|
FieldPrime::from(42)
|
||||||
)
|
)
|
||||||
.into()])
|
.into()])
|
||||||
.annotate(vec![StructMember::new(
|
.annotate(vec![StructMember::new("foo".into(), Type::FieldElement)]),
|
||||||
"foo".to_string(),
|
"foo".into()
|
||||||
Type::FieldElement
|
|
||||||
)]),
|
|
||||||
"foo".to_string()
|
|
||||||
)
|
)
|
||||||
.into())
|
.into())
|
||||||
);
|
);
|
||||||
|
@ -3978,7 +3965,7 @@ mod tests {
|
||||||
.check_expression(
|
.check_expression(
|
||||||
Expression::Member(
|
Expression::Member(
|
||||||
box Expression::InlineStruct(
|
box Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![(
|
vec![(
|
||||||
"foo",
|
"foo",
|
||||||
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
||||||
|
@ -3988,7 +3975,7 @@ mod tests {
|
||||||
"bar".into()
|
"bar".into()
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
)
|
)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
|
@ -4018,14 +4005,14 @@ mod tests {
|
||||||
checker
|
checker
|
||||||
.check_expression(
|
.check_expression(
|
||||||
Expression::InlineStruct(
|
Expression::InlineStruct(
|
||||||
"Bar".to_string(),
|
"Bar".into(),
|
||||||
vec![(
|
vec![(
|
||||||
"foo",
|
"foo",
|
||||||
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
)
|
)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
|
@ -4059,7 +4046,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_expression(
|
checker.check_expression(
|
||||||
Expression::InlineStruct(
|
Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![
|
vec![
|
||||||
(
|
(
|
||||||
"foo",
|
"foo",
|
||||||
|
@ -4069,7 +4056,7 @@ mod tests {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
),
|
),
|
||||||
Ok(StructExpressionInner::Value(vec![
|
Ok(StructExpressionInner::Value(vec![
|
||||||
|
@ -4077,8 +4064,8 @@ mod tests {
|
||||||
BooleanExpression::Value(true).into()
|
BooleanExpression::Value(true).into()
|
||||||
])
|
])
|
||||||
.annotate(vec![
|
.annotate(vec![
|
||||||
StructMember::new("foo".to_string(), Type::FieldElement),
|
StructMember::new("foo".into(), Type::FieldElement),
|
||||||
StructMember::new("bar".to_string(), Type::Boolean)
|
StructMember::new("bar".into(), Type::Boolean)
|
||||||
])
|
])
|
||||||
.into())
|
.into())
|
||||||
);
|
);
|
||||||
|
@ -4109,7 +4096,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
checker.check_expression(
|
checker.check_expression(
|
||||||
Expression::InlineStruct(
|
Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![
|
vec![
|
||||||
("bar", Expression::BooleanConstant(true).mock()),
|
("bar", Expression::BooleanConstant(true).mock()),
|
||||||
(
|
(
|
||||||
|
@ -4119,7 +4106,7 @@ mod tests {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
),
|
),
|
||||||
Ok(StructExpressionInner::Value(vec![
|
Ok(StructExpressionInner::Value(vec![
|
||||||
|
@ -4127,8 +4114,8 @@ mod tests {
|
||||||
BooleanExpression::Value(true).into()
|
BooleanExpression::Value(true).into()
|
||||||
])
|
])
|
||||||
.annotate(vec![
|
.annotate(vec![
|
||||||
StructMember::new("foo".to_string(), Type::FieldElement),
|
StructMember::new("foo".into(), Type::FieldElement),
|
||||||
StructMember::new("bar".to_string(), Type::Boolean)
|
StructMember::new("bar".into(), Type::Boolean)
|
||||||
])
|
])
|
||||||
.into())
|
.into())
|
||||||
);
|
);
|
||||||
|
@ -4160,14 +4147,14 @@ mod tests {
|
||||||
checker
|
checker
|
||||||
.check_expression(
|
.check_expression(
|
||||||
Expression::InlineStruct(
|
Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![(
|
vec![(
|
||||||
"foo",
|
"foo",
|
||||||
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
Expression::FieldConstant(FieldPrime::from(42)).mock()
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
)
|
)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
|
@ -4204,7 +4191,7 @@ mod tests {
|
||||||
checker
|
checker
|
||||||
.check_expression(
|
.check_expression(
|
||||||
Expression::InlineStruct(
|
Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![(
|
vec![(
|
||||||
"baz",
|
"baz",
|
||||||
Expression::BooleanConstant(true).mock()
|
Expression::BooleanConstant(true).mock()
|
||||||
|
@ -4214,7 +4201,7 @@ mod tests {
|
||||||
)]
|
)]
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
).unwrap_err()
|
).unwrap_err()
|
||||||
.message,
|
.message,
|
||||||
|
@ -4225,7 +4212,7 @@ mod tests {
|
||||||
checker
|
checker
|
||||||
.check_expression(
|
.check_expression(
|
||||||
Expression::InlineStruct(
|
Expression::InlineStruct(
|
||||||
"Foo".to_string(),
|
"Foo".into(),
|
||||||
vec![
|
vec![
|
||||||
(
|
(
|
||||||
"bar",
|
"bar",
|
||||||
|
@ -4238,7 +4225,7 @@ mod tests {
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.mock(),
|
.mock(),
|
||||||
&MODULE_ID.to_string(),
|
&MODULE_ID.into(),
|
||||||
&state.types
|
&state.types
|
||||||
)
|
)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
|
@ -4258,7 +4245,7 @@ mod tests {
|
||||||
let a = Assignee::Identifier::<FieldPrime>("a").mock();
|
let a = Assignee::Identifier::<FieldPrime>("a").mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
let mut checker: Checker = Checker::new();
|
let mut checker: Checker = Checker::new();
|
||||||
checker
|
checker
|
||||||
.check_statement::<FieldPrime>(
|
.check_statement::<FieldPrime>(
|
||||||
|
@ -4292,7 +4279,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
|
|
||||||
let mut checker: Checker = Checker::new();
|
let mut checker: Checker = Checker::new();
|
||||||
checker
|
checker
|
||||||
|
@ -4341,7 +4328,7 @@ mod tests {
|
||||||
.mock();
|
.mock();
|
||||||
|
|
||||||
let types = HashMap::new();
|
let types = HashMap::new();
|
||||||
let module_id = String::from("");
|
let module_id = "".into();
|
||||||
let mut checker: Checker = Checker::new();
|
let mut checker: Checker = Checker::new();
|
||||||
checker
|
checker
|
||||||
.check_statement::<FieldPrime>(
|
.check_statement::<FieldPrime>(
|
||||||
|
|
|
@ -54,32 +54,31 @@ mod tests {
|
||||||
let file_path = folder.path().join("bar.zok");
|
let file_path = folder.path().join("bar.zok");
|
||||||
let mut file = File::create(file_path).unwrap();
|
let mut file = File::create(file_path).unwrap();
|
||||||
writeln!(file, "some code").unwrap();
|
writeln!(file, "some code").unwrap();
|
||||||
let (_, next_location) =
|
let (_, next_location) = resolve(folder.path().to_path_buf(), "./bar".into()).unwrap();
|
||||||
resolve(folder.path().to_str().unwrap().to_string(), "./bar".into()).unwrap();
|
assert_eq!(next_location, folder.path());
|
||||||
assert_eq!(next_location, folder.path().to_str().unwrap().to_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn non_existing_file() {
|
fn non_existing_file() {
|
||||||
let res = resolve(String::from("./src"), "./rubbish".into());
|
let res = resolve("./src".into(), "./rubbish".into());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn invalid_location() {
|
fn invalid_location() {
|
||||||
let res = resolve(String::from(",8!-$2abc"), "./foo".into());
|
let res = resolve(",8!-$2abc".into(), "./foo".into());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn not_a_file() {
|
fn not_a_file() {
|
||||||
let res = resolve(String::from("."), "./src/".into());
|
let res = resolve(".".into(), "./src/".into());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_parent() {
|
fn no_parent() {
|
||||||
let res = resolve(String::from("."), ".".into());
|
let res = resolve(".".into(), ".".into());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,14 +101,7 @@ mod tests {
|
||||||
// assign HOME folder to ZOKRATES_HOME
|
// assign HOME folder to ZOKRATES_HOME
|
||||||
std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path());
|
std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path());
|
||||||
|
|
||||||
let result = resolve(
|
let result = resolve(source_folder.path().to_path_buf(), "./bar.zok".into());
|
||||||
source_folder
|
|
||||||
.path()
|
|
||||||
.to_path_buf()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string(),
|
|
||||||
"./bar.zok".into(),
|
|
||||||
);
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
// the imported file should be the user's
|
// the imported file should be the user's
|
||||||
assert_eq!(result.unwrap().0, String::from("<user code>\n"));
|
assert_eq!(result.unwrap().0, String::from("<user code>\n"));
|
||||||
|
@ -134,14 +126,7 @@ mod tests {
|
||||||
// assign HOME folder to ZOKRATES_HOME
|
// assign HOME folder to ZOKRATES_HOME
|
||||||
std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path());
|
std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path());
|
||||||
|
|
||||||
let result = resolve(
|
let result = resolve(source_folder.path().to_path_buf(), "bar.zok".into());
|
||||||
source_folder
|
|
||||||
.path()
|
|
||||||
.to_path_buf()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string(),
|
|
||||||
"bar.zok".into(),
|
|
||||||
);
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
// the imported file should be the user's
|
// the imported file should be the user's
|
||||||
assert_eq!(result.unwrap().0, String::from("<stdlib code>\n"));
|
assert_eq!(result.unwrap().0, String::from("<stdlib code>\n"));
|
||||||
|
@ -158,14 +143,7 @@ mod tests {
|
||||||
let mut file = File::create(file_path).unwrap();
|
let mut file = File::create(file_path).unwrap();
|
||||||
writeln!(file, "<user code>").unwrap();
|
writeln!(file, "<user code>").unwrap();
|
||||||
|
|
||||||
let result = resolve(
|
let result = resolve(source_subfolder.path().to_path_buf(), "../bar.zok".into());
|
||||||
source_subfolder
|
|
||||||
.path()
|
|
||||||
.to_path_buf()
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string(),
|
|
||||||
"../bar.zok".into(),
|
|
||||||
);
|
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
// the imported file should be the user's
|
// the imported file should be the user's
|
||||||
assert_eq!(result.unwrap().0, String::from("<user code>\n"));
|
assert_eq!(result.unwrap().0, String::from("<user code>\n"));
|
||||||
|
@ -184,14 +162,14 @@ mod tests {
|
||||||
// assign HOME folder to ZOKRATES_HOME
|
// assign HOME folder to ZOKRATES_HOME
|
||||||
std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path());
|
std::env::set_var(ZOKRATES_HOME, zokrates_home_folder.path());
|
||||||
|
|
||||||
let result = resolve("/path/to/user/folder".to_string(), "./bar.zok".into());
|
let result = resolve("/path/to/user/folder".into(), "./bar.zok".into());
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn fail_if_not_found_in_std() {
|
fn fail_if_not_found_in_std() {
|
||||||
std::env::set_var(ZOKRATES_HOME, "");
|
std::env::set_var(ZOKRATES_HOME, "");
|
||||||
let result = resolve("/path/to/source".to_string(), "bar.zok".into());
|
let result = resolve("/path/to/source".into(), "bar.zok".into());
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +177,6 @@ mod tests {
|
||||||
#[should_panic]
|
#[should_panic]
|
||||||
fn panic_if_home_not_set() {
|
fn panic_if_home_not_set() {
|
||||||
std::env::remove_var(ZOKRATES_HOME);
|
std::env::remove_var(ZOKRATES_HOME);
|
||||||
let _ = resolve("/path/to/source".to_string(), "bar.zok".into());
|
let _ = resolve("/path/to/source".into(), "bar.zok".into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue