1
0

Add tests

This commit is contained in:
Jeff 2024-12-03 15:33:26 -05:00
parent e660c0acfb
commit 372a438a7f

View File

@ -113,6 +113,126 @@ fn add_list_right() {
// fn add_range_right() { // fn add_range_right() {
// todo!("Add ranges") // todo!("Add ranges")
// } // }
//
#[test]
fn add_byte_and_character() {
let source = "0xff + 'a'";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Byte,
right_type: Type::Character,
position: Span(0, 10)
},
source,
})
);
}
#[test]
fn add_byte_and_integer() {
let source = "0xff + 1";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Byte,
right_type: Type::Integer,
position: Span(0, 8)
},
source,
})
);
}
#[test]
fn add_byte_and_string() {
let source = "0xff + \"hello\"";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Byte,
right_type: Type::String,
position: Span(0, 14)
},
source,
})
);
}
#[test]
fn add_character_and_byte() {
let source = "'a' + 0xff";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Character,
right_type: Type::Byte,
position: Span(0, 10)
},
source,
})
);
}
#[test]
fn add_character_and_float() {
let source = "'a' + 1.0";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Character,
right_type: Type::Float,
position: Span(0, 9)
},
source,
})
);
}
#[test]
fn add_character_and_integer() {
let source = "'a' + 1";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Character,
right_type: Type::Integer,
position: Span(0, 7)
},
source,
})
);
}
#[test]
fn add_float_and_byte() {
let source = "1.0 + 0xff";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Float,
right_type: Type::Byte,
position: Span(0, 10)
},
source,
})
);
}
#[test] #[test]
fn add_float_and_character() { fn add_float_and_character() {
@ -165,6 +285,23 @@ fn add_float_and_string() {
); );
} }
#[test]
fn add_integer_and_byte() {
let source = "1 + 0xff";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Integer,
right_type: Type::Byte,
position: Span(0, 8)
},
source,
})
);
}
#[test] #[test]
fn add_integer_and_character() { fn add_integer_and_character() {
let source = "1 + 'a'"; let source = "1 + 'a'";
@ -217,16 +354,16 @@ fn add_integer_and_string() {
} }
#[test] #[test]
fn add_string_and_character() { fn add_string_and_byte() {
let source = "\"hello\" + 'a'"; let source = "\"hello\" + 0xff";
assert_eq!( assert_eq!(
compile(source), compile(source),
Err(DustError::Compile { Err(DustError::Compile {
error: CompileError::CannotAddArguments { error: CompileError::CannotAddArguments {
left_type: Type::String, left_type: Type::String,
right_type: Type::Character, right_type: Type::Byte,
position: Span(0, 13) position: Span(0, 14)
}, },
source, source,
}) })
@ -266,37 +403,3 @@ fn add_string_and_integer() {
}) })
); );
} }
#[test]
fn add_character_and_float() {
let source = "'a' + 1.0";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Character,
right_type: Type::Float,
position: Span(0, 9)
},
source,
})
);
}
#[test]
fn add_character_and_integer() {
let source = "'a' + 1";
assert_eq!(
compile(source),
Err(DustError::Compile {
error: CompileError::CannotAddArguments {
left_type: Type::Character,
right_type: Type::Integer,
position: Span(0, 7)
},
source,
})
);
}