Updated test #64
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
pub fn test_let_basic() {
|
||||
let x = 42;
|
||||
assert_eq!(x, 42);
|
||||
}
|
||||
|
||||
pub fn test_let_typed() {
|
||||
let x i32 = 42;
|
||||
assert_eq!(x, 42);
|
||||
|
||||
let s *str = "hello";
|
||||
assert_eq!(s, "hello");
|
||||
|
||||
let b bool = true;
|
||||
assert_eq!(b, true);
|
||||
|
||||
let f f64 = 3.14;
|
||||
assert_eq!(f, 3.14);
|
||||
}
|
||||
|
||||
pub fn test_let_mut() {
|
||||
let mut _x = 42;
|
||||
_x = 100;
|
||||
assert_eq!(_x, 100);
|
||||
}
|
||||
|
||||
pub fn test_let_tuple_destructure() {
|
||||
let [a, b] = (10, "hello");
|
||||
assert_eq!(a, 10);
|
||||
assert_eq!(b, "hello");
|
||||
}
|
||||
|
||||
pub fn test_let_nested_tuple() {
|
||||
let [a, [b, c]] = (1, (2, 3));
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
|
||||
pub fn test_let_pattern_irrefutable() {
|
||||
let x = 5;
|
||||
let [y, z] = (1, 2);
|
||||
assert_eq!(x, 5);
|
||||
assert_eq!(y, 1);
|
||||
assert_eq!(z, 2);
|
||||
}
|
||||
|
||||
pub fn test_multiple_decls() {
|
||||
let a = 1;
|
||||
let b = 2;
|
||||
let c = 3;
|
||||
assert_eq!(a + b + c, 6);
|
||||
}
|
||||
|
||||
pub fn test_let_with_type_and_init() {
|
||||
let x f64 = 10.0;
|
||||
assert_eq!(x, 10.0);
|
||||
}
|
||||
|
||||
pub fn test_string_literal() {
|
||||
let s = "hello, world!";
|
||||
assert_eq!(s.len(), 13);
|
||||
}
|
||||
|
||||
pub fn test_let_bool() {
|
||||
let t = true;
|
||||
let f = false;
|
||||
assert_eq!(t, !f);
|
||||
}
|
||||
|
||||
pub fn run_tests() {
|
||||
test_let_basic();
|
||||
test_let_typed();
|
||||
test_let_mut();
|
||||
test_let_tuple_destructure();
|
||||
test_let_nested_tuple();
|
||||
test_let_pattern_irrefutable();
|
||||
test_multiple_decls();
|
||||
test_let_with_type_and_init();
|
||||
test_string_literal();
|
||||
test_let_bool();
|
||||
}
|
||||
Reference in New Issue
Block a user