@@ -6,12 +6,42 @@ use Nette\PhpGenerator\Type;
6
6
use Tester \Assert ;
7
7
require __DIR__ . '/../bootstrap.php ' ;
8
8
9
+ // Nullable
10
+ Assert::same ('?int ' , Type::nullable (Type::Int));
11
+ Assert::same ('int ' , Type::nullable (Type::Int, nullable: false ));
9
12
10
- Assert::same ('A|string ' , Type::union (A::class, Type::String));
13
+ Assert::same ('?int ' , Type::nullable ('?int ' ));
14
+ Assert::same ('int ' , Type::nullable ('?int ' , nullable: false ));
15
+
16
+ // TODO:
17
+ Assert::same ('null ' , Type::nullable ('null ' ));
18
+ Assert::same ('... ' , Type::nullable ('null ' , nullable: false ));
19
+ Assert::same ('mixed ' , Type::nullable ('mixed ' ));
20
+ Assert::same ('... ' , Type::nullable ('mixed ' , nullable: false ));
21
+
22
+
23
+ Assert::same ('int|float|string|null ' , Type::nullable ('int|float|string ' ));
24
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|string ' , nullable: false ));
25
+
26
+ Assert::same ('NULL|int|float|string ' , Type::nullable ('NULL|int|float|string ' ));
27
+ Assert::same ('int|float|string ' , Type::nullable ('NULL|int|float|string ' , nullable: false ));
11
28
12
- Assert::same ('?A ' , Type::nullable (A::class));
13
- Assert::same ('?A ' , Type::nullable (A::class));
14
- Assert::same ('A ' , Type::nullable (A::class, nullable: false ));
29
+ Assert::same ('int|float|string|null ' , Type::nullable ('int|float|string|null ' ));
30
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|string|null ' , nullable: false ));
31
+
32
+ Assert::same ('int|float|null|string ' , Type::nullable ('int|float|null|string ' ));
33
+ Assert::same ('int|float|string ' , Type::nullable ('int|float|null|string ' , nullable: false ));
34
+
35
+ Assert::exception (
36
+ fn () => Type::nullable ('Foo&Bar ' ),
37
+ Nette \InvalidArgumentException::class,
38
+ 'Intersection types cannot be nullable. ' ,
39
+ );
40
+ Assert::same ('Foo&Bar ' , Type::nullable ('Foo&Bar ' , nullable: false ));
41
+
42
+
43
+ // Union
44
+ Assert::same ('A|string ' , Type::union (A::class, Type::String));
15
45
16
- Assert:: same ( ' ?A ' , Type:: nullable ( ' ?A ' ));
17
- Assert::same ('A ' , Type::nullable ( ' ?A ' , nullable: false ));
46
+ // Intersection
47
+ Assert::same ('A&string ' , Type::intersection (A::class, Type::String ));
0 commit comments