2
2
3
3
import static org .junit .jupiter .api .Assertions .assertEquals ;
4
4
import static org .junit .jupiter .api .Assertions .assertNotNull ;
5
+ import static org .junit .jupiter .api .Assertions .fail ;
5
6
6
7
import org .junit .jupiter .api .Test ;
7
8
8
9
import convex .core .ErrorCodes ;
9
10
import convex .core .data .ACell ;
11
+ import convex .core .data .Address ;
10
12
import convex .core .data .Strings ;
11
13
import convex .core .data .Symbol ;
12
14
import convex .core .data .prim .CVMChar ;
15
+ import convex .core .data .type .AType ;
16
+
17
+ import static convex .test .Assertions .*;
13
18
14
19
public class CastTest extends ACVMTest {
15
20
16
21
static final String [] casts = new String [] {"double" ,"int" , "long" , "boolean" ,"blob" ,"address" , "str" ,"name" ,"symbol" ,"keyword" ,"char" };
17
22
static final String [] vals = new String [] {"##Inf" ,"1e308" ,"0.0" , "-0.0" , "999999999999999999999999999" , "9223372036854775807" , "1" ,"0" ,"-1" ,"0xcafebabe1234567890" ,"0x41" ,"0x" ,"\\ c" ,"\\ u0474" , "\" hello\" " ,"\" \" " ,"#12" ,":foo" ,"'baz" ,"true" ,"false" ,"nil" };
18
23
24
+ @ Test
25
+ public void testRoundTrips () {
26
+ assertCVMEquals (1L ,eval ("(long (address 1))" ));
27
+ assertCVMEquals (Address .ZERO ,eval ("(address (blob #0))" ));
28
+ }
29
+
19
30
@ Test
20
31
public void testAllCasts () {
21
32
for (String c : casts ) {
@@ -25,7 +36,12 @@ public void testAllCasts() {
25
36
if (ctx .isError ()) {
26
37
ACell code =ctx .getErrorCode ();
27
38
if (ErrorCodes .ARGUMENT .equals (code )) {
28
- // anything to test?
39
+ // the default value should be in range
40
+ AType type =RT .getType (Reader .read (v ));
41
+ Context nctx =step ("(" +c +" " +RT .print (type .defaultValue ())+")" );
42
+ if (nctx .isError ()) {
43
+ fail ("ARGUMENT fallback not working in: " +cmd );
44
+ }
29
45
} else {
30
46
assertEquals (ErrorCodes .CAST ,code ,()->"Unexpected " +code +" in " +cmd );
31
47
}
0 commit comments