19
19
import java .util .Set ;
20
20
import org .junit .jupiter .api .Test ;
21
21
import org .mockito .Mockito ;
22
+ import org .sonar .python .semantic .ProjectLevelSymbolTable ;
22
23
import org .sonar .python .semantic .v2 .LazyTypesContext ;
24
+ import org .sonar .python .semantic .v2 .ProjectLevelTypeTable ;
23
25
24
26
import static org .assertj .core .api .Assertions .assertThat ;
25
27
import static org .mockito .Mockito .when ;
@@ -37,4 +39,23 @@ void lazyUnionTypeResolvesNestedLazyTypesWhenAccessed() {
37
39
UnionType unionType = (UnionType ) lazyUnionType .resolve ();
38
40
assertThat (unionType .candidates ()).containsExactlyInAnyOrder (INT_TYPE , FLOAT_TYPE );
39
41
}
42
+
43
+ @ Test
44
+ void flattened () {
45
+ LazyTypesContext lazyTypesContext = Mockito .spy (new LazyTypesContext (new ProjectLevelTypeTable (ProjectLevelSymbolTable .empty ())));
46
+
47
+ var lazyType1 = lazyTypeUnresolved ("lazy1" , lazyTypesContext );
48
+ var lazyType2 = lazyTypeUnresolved ("lazy2" , lazyTypesContext );
49
+ var lazyType3 = lazyTypeUnresolved ("lazy3" , lazyTypesContext );
50
+
51
+ var lazyUnionType1 = new LazyUnionType (Set .of (lazyType1 , lazyType2 , lazyType3 ));
52
+ var lazyUnionType2 = new LazyUnionType (Set .of (lazyType1 , lazyType2 , lazyType3 , lazyUnionType1 ));
53
+ assertThat (lazyUnionType2 .candidates ()).containsExactlyInAnyOrder (lazyType1 , lazyType2 , lazyType3 );
54
+ }
55
+
56
+ LazyType lazyTypeUnresolved (String name , LazyTypesContext lazyTypesContext ) {
57
+ var lazyType = lazyTypesContext .getOrCreateLazyType (name );
58
+ when (lazyTypesContext .resolveLazyType (lazyType )).thenReturn (new UnknownType .UnresolvedImportType (name ));
59
+ return lazyType ;
60
+ }
40
61
}
0 commit comments