()
| 3120 | |
| 3121 | #[test] |
| 3122 | fn signature() { |
| 3123 | let sig = Parser::new("()system_v").parse_signature().unwrap(); |
| 3124 | assert_eq!(sig.params.len(), 0); |
| 3125 | assert_eq!(sig.returns.len(), 0); |
| 3126 | assert_eq!(sig.call_conv, CallConv::SystemV); |
| 3127 | |
| 3128 | let sig2 = |
| 3129 | Parser::new("(i8 uext, f16, f32, f64, f128, i32 sret) -> i32 sext, f64 system_v") |
| 3130 | .parse_signature() |
| 3131 | .unwrap(); |
| 3132 | assert_eq!( |
| 3133 | sig2.to_string(), |
| 3134 | "(i8 uext, f16, f32, f64, f128, i32 sret) -> i32 sext, f64 system_v" |
| 3135 | ); |
| 3136 | assert_eq!(sig2.call_conv, CallConv::SystemV); |
| 3137 | |
| 3138 | // Old-style signature without a calling convention. |
| 3139 | assert_eq!( |
| 3140 | Parser::new("()").parse_signature().unwrap().to_string(), |
| 3141 | "() fast" |
| 3142 | ); |
| 3143 | assert_eq!( |
| 3144 | Parser::new("() notacc") |
| 3145 | .parse_signature() |
| 3146 | .unwrap_err() |
| 3147 | .to_string(), |
| 3148 | "1: unknown calling convention: notacc" |
| 3149 | ); |
| 3150 | |
| 3151 | // `void` is not recognized as a type by the lexer. It should not appear in files. |
| 3152 | assert_eq!( |
| 3153 | Parser::new("() -> void") |
| 3154 | .parse_signature() |
| 3155 | .unwrap_err() |
| 3156 | .to_string(), |
| 3157 | "1: expected parameter type" |
| 3158 | ); |
| 3159 | assert_eq!( |
| 3160 | Parser::new("i8 -> i8") |
| 3161 | .parse_signature() |
| 3162 | .unwrap_err() |
| 3163 | .to_string(), |
| 3164 | "1: expected function signature: ( args... )" |
| 3165 | ); |
| 3166 | assert_eq!( |
| 3167 | Parser::new("(i8 -> i8") |
| 3168 | .parse_signature() |
| 3169 | .unwrap_err() |
| 3170 | .to_string(), |
| 3171 | "1: expected ')' after function arguments" |
| 3172 | ); |
| 3173 | } |
| 3174 | |
| 3175 | #[test] |
| 3176 | fn stack_slot_decl() { |
nothing calls this directly
no test coverage detected