Skip to content

Commit 6ba52f8

Browse files
authored
Merge pull request #50 from The3rdMega/feature/test-infastructure
Feature/test infastructure (Resposta ao Issue "Review the implementation of the Testing Infrastructure")
2 parents 3135447 + 7a5671e commit 6ba52f8

File tree

9 files changed

+1639
-20
lines changed

9 files changed

+1639
-20
lines changed

Cargo.lock

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2021"
77
nom = "7.0"
88
approx = "0.5.1"
99
once_cell = "1.10"
10+
indexmap = "2.2"

src/environment/environment.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::ir::ast::Function;
22
use crate::ir::ast::Name;
33
use crate::ir::ast::ValueConstructor;
4+
use indexmap::IndexMap;
45
use std::collections::HashMap;
56
use std::collections::LinkedList;
67

@@ -9,6 +10,7 @@ pub struct Scope<A> {
910
pub variables: HashMap<Name, (bool, A)>,
1011
pub functions: HashMap<Name, Function>,
1112
pub adts: HashMap<Name, Vec<ValueConstructor>>,
13+
pub tests: IndexMap<Name, Function>,
1214
}
1315

1416
impl<A: Clone> Scope<A> {
@@ -17,6 +19,7 @@ impl<A: Clone> Scope<A> {
1719
variables: HashMap::new(),
1820
functions: HashMap::new(),
1921
adts: HashMap::new(),
22+
tests: IndexMap::new(), //TODO: Apresentar Mudança no Environment
2023
}
2124
}
2225

@@ -30,6 +33,11 @@ impl<A: Clone> Scope<A> {
3033
return ();
3134
}
3235

36+
fn map_test(&mut self, test: Function) -> () {
37+
self.tests.insert(test.name.clone(), test);
38+
return ();
39+
}
40+
3341
fn map_adt(&mut self, name: Name, adt: Vec<ValueConstructor>) -> () {
3442
self.adts.insert(name.clone(), adt);
3543
return ();
@@ -45,6 +53,10 @@ impl<A: Clone> Scope<A> {
4553
self.functions.get(name)
4654
}
4755

56+
fn lookup_test(&self, name: &Name) -> Option<&Function> {
57+
self.tests.get(name)
58+
}
59+
4860
fn lookup_adt(&self, name: &Name) -> Option<&Vec<ValueConstructor>> {
4961
self.adts.get(name)
5062
}
@@ -78,6 +90,13 @@ impl<A: Clone> Environment<A> {
7890
}
7991
}
8092

93+
pub fn map_test(&mut self, test: Function) -> () {
94+
match self.stack.front_mut() {
95+
None => self.globals.map_test(test),
96+
Some(top) => top.map_test(test),
97+
}
98+
}
99+
81100
pub fn map_adt(&mut self, name: Name, cons: Vec<ValueConstructor>) -> () {
82101
match self.stack.front_mut() {
83102
None => self.globals.map_adt(name, cons),
@@ -103,6 +122,28 @@ impl<A: Clone> Environment<A> {
103122
self.globals.lookup_function(name)
104123
}
105124

125+
pub fn lookup_test(&self, name: &Name) -> Option<&Function> {
126+
for scope in self.stack.iter() {
127+
if let Some(test) = scope.lookup_test(name) {
128+
return Some(test);
129+
}
130+
}
131+
self.globals.lookup_test(name)
132+
}
133+
134+
pub fn get_all_tests(&self) -> Vec<Function> {
135+
let mut tests = Vec::new();
136+
for scope in self.stack.iter() {
137+
for test in scope.tests.values() {
138+
tests.push(test.clone());
139+
}
140+
}
141+
for test in self.globals.tests.values() {
142+
tests.push(test.clone());
143+
}
144+
tests
145+
}
146+
106147
pub fn lookup_adt(&self, name: &Name) -> Option<&Vec<ValueConstructor>> {
107148
for scope in self.stack.iter() {
108149
if let Some(cons) = scope.lookup_adt(name) {
@@ -147,6 +188,22 @@ impl<A: Clone> Environment<A> {
147188
}
148189
}
149190

191+
pub struct TestResult {
192+
pub name: Name,
193+
pub result: bool,
194+
pub error: Option<String>,
195+
}
196+
197+
impl TestResult {
198+
pub fn new(name: Name, result: bool, error: Option<String>) -> Self {
199+
TestResult {
200+
name,
201+
result,
202+
error,
203+
}
204+
}
205+
}
206+
150207
#[cfg(test)]
151208
mod tests {
152209
use super::*;

0 commit comments

Comments
 (0)