Skip to content

Commit 49a354b

Browse files
committed
chore(tests): checks function return type
1 parent af798c7 commit 49a354b

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/compiler/test_util.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ macro_rules! test_function {
135135
assert!(got_value == want, "assertion failed for `{}` case:\n got: {:?}\n wanted: {:?}", stringify!($case), got_value, want);
136136
let got_tdef = expression.type_def(&state);
137137
assert_eq!(got_tdef, $tdef);
138+
139+
if let Ok(got_value) = got_value {
140+
assert!($func.return_kind() & got_value.kind_id() > 0, "assertion failed for `{}` return type, got {}", stringify!($case), got_value.kind_str());
141+
}
138142
}
139143
err@Err(_) => {
140144
// Allow tests against compiler errors.

src/value/value.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ impl Value {
8181
}
8282
}
8383

84+
#[cfg(test)]
85+
pub const fn kind_id(&self) -> u16 {
86+
use crate::compiler::value::kind;
87+
match self {
88+
Self::Bytes(_) => kind::BYTES,
89+
Self::Regex(_) => kind::REGEX,
90+
Self::Timestamp(_) => kind::TIMESTAMP,
91+
Self::Integer(_) => kind::INTEGER,
92+
Self::Float(_) => kind::FLOAT,
93+
Self::Boolean(_) => kind::BOOLEAN,
94+
Self::Object(_) => kind::OBJECT,
95+
Self::Array(_) => kind::ARRAY,
96+
Self::Null => kind::NULL,
97+
}
98+
}
99+
84100
/// Merges `incoming` value into self.
85101
///
86102
/// Will concatenate `Bytes` and overwrite the rest value kinds.

0 commit comments

Comments
 (0)