mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Add some binop tests
This commit is contained in:
parent
72dc754c28
commit
80c0978ecb
1 changed files with 21 additions and 0 deletions
|
@ -254,6 +254,12 @@ const fn generate_display_table() -> [&'static str; 20] {
|
|||
mod tests {
|
||||
use super::{BinOp, ASSOCIATIVITIES, DISPLAY_STRINGS, PRECEDENCES};
|
||||
|
||||
fn index_is_binop_u8(iter: impl Iterator<Item = BinOp>, table_name: &'static str) {
|
||||
for (index, op) in iter.enumerate() {
|
||||
assert_eq!(op as usize, index);
|
||||
}
|
||||
}
|
||||
|
||||
fn no_duplicates(iter: impl Iterator<Item = BinOp> + Clone, table_name: &'static str) {
|
||||
for op_to_count in iter.clone() {
|
||||
let mut instances = 0;
|
||||
|
@ -269,6 +275,21 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indices_are_correct_in_precedences() {
|
||||
index_is_binop_u8(PRECEDENCES.iter().map(|(op, _)| *op), "PRECEDENCES")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indices_are_correct_in_associativities() {
|
||||
index_is_binop_u8(ASSOCIATIVITIES.iter().map(|(op, _)| *op), "ASSOCIATIVITIES")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indices_are_correct_in_display_string() {
|
||||
index_is_binop_u8(DISPLAY_STRINGS.iter().map(|(op, _)| *op), "DISPLAY_STRINGS")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_duplicates_in_precedences() {
|
||||
no_duplicates(PRECEDENCES.iter().map(|(op, _)| *op), "PRECEDENCES")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue