Skip to content

Commit 5449aa3

Browse files
committed
Add tests for cast expressions.
1 parent fd6c1a2 commit 5449aa3

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

tests/clang.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ fn test_definition(
7272
s.extend_from_slice(rest);
7373
}
7474
Some(Str(s))
75+
} else if expected == b"Cast" {
76+
str::from_utf8(value).ok().and_then(|s| {
77+
let (ty, value) = s.rsplit_once("_Int_")?;
78+
79+
let ty = ty.split("_").filter_map(|t| {
80+
if t == "const" || t == "signed" {
81+
None
82+
} else {
83+
Some(t.as_bytes().to_vec())
84+
}
85+
}).collect::<Vec<Vec<u8>>>();
86+
let int = bytes_to_int(value.as_bytes())?;
87+
88+
Some(Cast(ty, Box::new(int)))
89+
})
7590
} else if expected == b"Int" {
7691
bytes_to_int(value)
7792
} else if expected == b"Float" {

tests/input/int_signed.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@
33
#define Int_n9223372036854775808 -9223372036854775808
44

55
#define Fn_Int_n9(_3) _3*-3
6+
7+
#define Cast_short_Int_n6 (short) -6
8+
#define Cast_signed_short_Int_n6 (signed short) -6
9+
#define Cast_const_short_Int_n6 (const short) -6
10+
#define Cast_const_signed_short_Int_n6 (const signed short) -6
11+
12+
#define Cast_int_Int_n6 (int) -6
13+
#define Cast_signed_int_Int_n6 (signed int) -6
14+
#define Cast_const_int_Int_n6 (const int) -6
15+
#define Cast_const_signed_int_Int_n6 (const signed int) -6
16+
17+
#define Cast_long_Int_n6 (long) -6
18+
#define Cast_signed_long_Int_n6 (signed long) -6
19+
#define Cast_const_long_Int_n6 (const long) -6
20+
#define Cast_const_signed_long_Int_n6 (const signed long) -6
21+
22+
#define Cast_long_long_Int_n6 (long long) -6
23+
#define Cast_signed_long_long_Int_n6 (signed long long) -6
24+
#define Cast_const_long_long_Int_n6 (const long long) -6
25+
#define Cast_const_signed_long_long_Int_n6 (const signed long long) -6

tests/input/int_unsigned.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,15 @@
2828

2929
#define Fn_Int_9(_3) _3*3
3030
#define Fn_Int_unused_arg_3(x_unused_0) 3
31+
32+
#define Cast_unsigned_short_Int_6 (unsigned short) 6
33+
#define Cast_const_unsigned_short_Int_6 (const unsigned short) 6
34+
35+
#define Cast_unsigned_int_Int_6 (unsigned int) 6
36+
#define Cast_const_unsigned_int_Int_6 (const unsigned int) 6
37+
38+
#define Cast_unsigned_long_Int_6 (unsigned long) 6
39+
#define Cast_const_unsigned_long_Int_6 (const unsigned long) 6
40+
41+
#define Cast_unsigned_long_long_Int_6 (unsigned long long) 6
42+
#define Cast_const_unsigned_long_long_Int_6 (const unsigned long long) 6

0 commit comments

Comments
 (0)