1
1
#![ allow( non_snake_case) ]
2
2
3
+ use expect_test:: { Expect , expect} ;
4
+
3
5
use crate :: test_util:: assert_same;
4
6
use chalk_integration:: db:: ChalkDatabase ;
5
7
use chalk_integration:: interner:: ChalkIr ;
@@ -17,7 +19,7 @@ mod bench;
17
19
mod coherence;
18
20
mod wf_lowering;
19
21
20
- pub fn assert_result ( mut result : Option < Solution < ChalkIr > > , expected : & str , interner : ChalkIr ) {
22
+ fn format_solution ( mut result : Option < Solution < ChalkIr > > , interner : ChalkIr ) -> String {
21
23
// sort constraints, since the different solvers may output them in different order
22
24
match & mut result {
23
25
Some ( Solution :: Unique ( solution) ) => {
@@ -27,23 +29,31 @@ pub fn assert_result(mut result: Option<Solution<ChalkIr>>, expected: &str, inte
27
29
}
28
30
_ => { }
29
31
}
30
- let result = match result {
32
+ match result {
31
33
Some ( v) => format ! ( "{}" , v. display( ChalkIr ) ) ,
32
34
None => format ! ( "No possible solution" ) ,
33
- } ;
35
+ }
36
+ }
37
+
38
+ pub fn assert_result ( result : Option < Solution < ChalkIr > > , expected : & Expect , interner : ChalkIr ) {
39
+ let result = format_solution ( result, interner) ;
40
+ expected. assert_eq ( & result) ;
41
+ }
34
42
43
+ pub fn assert_result_str ( result : Option < Solution < ChalkIr > > , expected : & str , interner : ChalkIr ) {
44
+ let result = format_solution ( result, interner) ;
35
45
assert_same ( & result, expected) ;
36
46
}
37
47
38
48
// different goals
39
49
#[ derive( Clone ) ]
40
- pub enum TestGoal {
50
+ pub enum TestGoal < T = Expect > {
41
51
// solver should produce same aggregated single solution
42
- Aggregated ( & ' static str ) ,
52
+ Aggregated ( T ) ,
43
53
// solver should produce exactly multiple solutions
44
- All ( Vec < & ' static str > ) ,
54
+ All ( Vec < T > ) ,
45
55
// solver should produce first same multiple solutions
46
- First ( Vec < & ' static str > ) ,
56
+ First ( Vec < T > ) ,
47
57
}
48
58
49
59
macro_rules! test {
@@ -267,7 +277,7 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>, co
267
277
268
278
println ! ( "using solver: {:?}" , solver_choice) ;
269
279
let peeled_goal = goal. into_peeled_goal ( db. interner ( ) ) ;
270
- match expected {
280
+ match & expected {
271
281
TestGoal :: Aggregated ( expected) => {
272
282
let result = db. solve ( & peeled_goal) ;
273
283
assert_result ( result, expected, db. interner ( ) ) ;
@@ -278,13 +288,11 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>, co
278
288
db. solve_multiple( & peeled_goal, & mut |result, next_result| {
279
289
match expected. next( ) {
280
290
Some ( expected) => {
281
- assert_same(
282
- & format!(
283
- "{}" ,
284
- result. as_ref( ) . map( |v| v. display( ChalkIr ) )
285
- ) ,
286
- expected,
291
+ let actual = format!(
292
+ "{}" ,
293
+ result. as_ref( ) . map( |v| v. display( ChalkIr ) )
287
294
) ;
295
+ expected. assert_eq( & actual)
288
296
}
289
297
None => {
290
298
assert!( !next_result, "Unexpected next solution" ) ;
@@ -304,10 +312,9 @@ fn solve_goal(program_text: &str, goals: Vec<(&str, SolverChoice, TestGoal)>, co
304
312
. next ( )
305
313
{
306
314
Some ( solution) => {
307
- assert_same (
308
- & format ! ( "{}" , result. as_ref( ) . map( |v| v. display( ChalkIr ) ) ) ,
309
- solution,
310
- ) ;
315
+ let actual =
316
+ format ! ( "{}" , result. as_ref( ) . map( |v| v. display( ChalkIr ) ) ) ;
317
+ solution. assert_eq ( & actual) ;
311
318
if !next_result {
312
319
assert ! (
313
320
expected. next( ) . is_none( ) ,
0 commit comments