Files
mist/mist-test/src/common/decl_test.mist
T

124 lines
2.0 KiB
Plaintext

pub module decl_test;
pub void test_let_basic()
{
let x = 42;
assert_eq!(x, 42);
}
pub void test_let_repeat()
{
let x, y = (42, 67);
assert_eq!(x, 42);
assert_eq!(y, 67);
}
pub void test_let_typed()
{
i32 x = 42;
assert_eq!(x, 42);
str& s = "hello";
assert_eq!(s, "hello");
bool b = true;
assert_eq!(b, true);
f64 f = 3.14;
assert_eq!(f, 3.14);
}
pub void test_let_repeat_typed()
{
i32 x, x1 = (42, 67);
assert_eq!(x, 42);
assert_eq!(x1, 67);
str& s, s1 = ("hello", "world");
assert_eq!(s, "hello");
assert_eq!(s1, "world");
bool b, b1 = (true, false);
assert_eq!(b, true);
assert_eq!(b1, false);
f64 f, f1 = (3.14, 5.5);
assert_eq!(f, 3.14);
assert_eq!(f1, 5.5);
(i32, f64) as a, b = (70, 1.4);
assert_eq!(a, 70);
assert_eq!(b, 1.4);
}
pub void test_let_mut()
{
let mut _x = 42;
_x = 100;
assert_eq!(_x, 100);
}
pub void test_let_tuple_destructure()
{
let (a, b) = (10, "hello");
assert_eq!(a, 10);
assert_eq!(b, "hello");
}
pub void test_let_nested_tuple()
{
let (a, (b, c)) = (1, (2, 3));
assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(c, 3);
}
pub void 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 void test_multiple_decls()
{
let a = 1;
let b = 2;
let c = 3;
assert_eq!(a + b + c, 6);
}
pub void test_let_with_type_and_init()
{
f64 x = 10.0;
assert_eq!(x, 10.0);
}
pub void test_string_literal()
{
let s = "hello, world!";
assert_eq!(s.len(), 13);
}
pub void test_let_bool()
{
let t = true;
let f = false;
assert_eq!(t, !f);
}
pub void run_tests()
{
test_let_basic();
test_let_repeat();
test_let_typed();
test_let_repeat_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();
}