Fixed test
This commit is contained in:
@@ -590,6 +590,7 @@ prefix = {
|
||||
bin_op = {
|
||||
"+="
|
||||
| "-="
|
||||
| "*="
|
||||
| "/="
|
||||
| "%="
|
||||
| "&="
|
||||
|
||||
@@ -4,16 +4,16 @@ pub void test_let_basic() {
|
||||
}
|
||||
|
||||
pub void test_let_typed() {
|
||||
Int x = 42;
|
||||
i32 x = 42;
|
||||
assert_eq!(x, 42);
|
||||
|
||||
String s = "hello";
|
||||
str* s = "hello";
|
||||
assert_eq!(s, "hello");
|
||||
|
||||
Bool b = true;
|
||||
bool b = true;
|
||||
assert_eq!(b, true);
|
||||
|
||||
Float f = 3.14;
|
||||
f64 f = 3.14;
|
||||
assert_eq!(f, 3.14);
|
||||
}
|
||||
|
||||
@@ -52,8 +52,8 @@ pub void test_multiple_decls() {
|
||||
}
|
||||
|
||||
pub void test_let_with_type_and_init() {
|
||||
Int x = 10;
|
||||
assert_eq!(x, 10);
|
||||
f64 x = 10.0;
|
||||
assert_eq!(x, 10.0);
|
||||
}
|
||||
|
||||
pub void test_string_literal() {
|
||||
|
||||
@@ -88,7 +88,7 @@ pub void test_as_cast() {
|
||||
}
|
||||
|
||||
pub void test_closure() {
|
||||
let add = fn(a, b) a + b;
|
||||
let add = fn(let a, let b) a + b;
|
||||
assert_eq!(add(2, 3), 5);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@ pub void test_var_decl() {
|
||||
let x = 42;
|
||||
assert_eq!(x, 42);
|
||||
|
||||
Int y = 10;
|
||||
i32 y = 10;
|
||||
assert_eq!(y, 10);
|
||||
|
||||
String name = "mist";
|
||||
str* name = "mist";
|
||||
assert_eq!(name, "mist");
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ pub void test_match_literal() {
|
||||
1 => { result = 10; }
|
||||
2 => { result = 20; }
|
||||
3 => { result = 30; }
|
||||
_ => panic!();
|
||||
}
|
||||
assert_eq!(result, 20);
|
||||
}
|
||||
@@ -120,6 +121,7 @@ pub void test_match_or_pattern() {
|
||||
match (x) {
|
||||
1 | 2 => { result = 100; }
|
||||
3 => { result = 200; }
|
||||
_ => panic!();
|
||||
}
|
||||
assert_eq!(result, 100);
|
||||
}
|
||||
|
||||
@@ -1,64 +1,55 @@
|
||||
pub void test_integer_type() {
|
||||
Int x = 42;
|
||||
i32 x = 42;
|
||||
assert_eq!(x, 42);
|
||||
}
|
||||
|
||||
pub void test_float_type() {
|
||||
Float x = 3.14;
|
||||
f64 x = 3.14;
|
||||
assert_eq!(x, 3.14);
|
||||
}
|
||||
|
||||
pub void test_bool_type() {
|
||||
Bool x = true;
|
||||
bool x = true;
|
||||
assert_eq!(x, true);
|
||||
|
||||
Bool y = false;
|
||||
bool y = false;
|
||||
assert_eq!(y, false);
|
||||
}
|
||||
|
||||
pub void test_string_type() {
|
||||
String s = "hello";
|
||||
str* s = "hello";
|
||||
assert_eq!(s, "hello");
|
||||
}
|
||||
|
||||
pub void test_tuple_type() {
|
||||
[Int, String] t = (42, "answer");
|
||||
[i32, str*] t = (42, "answer");
|
||||
assert_eq!(t.0, 42);
|
||||
assert_eq!(t.1, "answer");
|
||||
}
|
||||
|
||||
pub void test_ref_type() {
|
||||
Int x = 42;
|
||||
Int* r = &x;
|
||||
i32 x = 42;
|
||||
i32* r = &x;
|
||||
assert_eq!(*r, 42);
|
||||
}
|
||||
|
||||
pub void test_mut_ref_type() {
|
||||
let mut x = 42;
|
||||
Int mut* r = &mut x;
|
||||
i32 mut* r = &mut x;
|
||||
*r = 100;
|
||||
assert_eq!(x, 100);
|
||||
}
|
||||
|
||||
pub void test_void_type() {
|
||||
void nothing() {
|
||||
}
|
||||
nothing();
|
||||
pub void test_void_type() {}
|
||||
|
||||
i32 add(i32 a, i32 b) {
|
||||
a + b
|
||||
}
|
||||
|
||||
pub void test_fn_return_type() {
|
||||
Int add(Int a, Int b) {
|
||||
a + b
|
||||
}
|
||||
assert_eq!(add(3, 4), 7);
|
||||
}
|
||||
|
||||
pub void test_fn_return_void() {
|
||||
void do_nothing() {
|
||||
}
|
||||
do_nothing();
|
||||
}
|
||||
|
||||
pub void run_tests() {
|
||||
test_integer_type();
|
||||
test_float_type();
|
||||
@@ -69,5 +60,4 @@ pub void run_tests() {
|
||||
test_mut_ref_type();
|
||||
test_void_type();
|
||||
test_fn_return_type();
|
||||
test_fn_return_void();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Debuggable {
|
||||
Int value,
|
||||
i32 value,
|
||||
}
|
||||
|
||||
pub void test_derive_attribute() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
pub class Counter {
|
||||
pub Int count;
|
||||
pub i32 count;
|
||||
|
||||
pub constructor(Int start) {
|
||||
pub constructor(i32 start) {
|
||||
self.count = start;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ pub class Counter {
|
||||
self.count++;
|
||||
}
|
||||
|
||||
pub Int get(self*) -> Int {
|
||||
pub i32 get(self*) {
|
||||
self.count
|
||||
}
|
||||
}
|
||||
@@ -33,17 +33,17 @@ pub void test_class_field_access() {
|
||||
class NamedCounter : Counter {
|
||||
pub String name;
|
||||
|
||||
pub constructor(Int start, String name) {
|
||||
pub constructor(i32 start, String name) {
|
||||
self.name = name;
|
||||
}
|
||||
|
||||
pub String get_name(self*) -> String {
|
||||
self.name
|
||||
pub String get_name(self*) {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_class_inherit() {
|
||||
let nc = NamedCounter::new(10, "test");
|
||||
let nc = NamedCounter::new(10, "test".to_string());
|
||||
assert_eq!(nc.get_name(), "test");
|
||||
assert_eq!(nc.count, 10);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
enum OptionInt {
|
||||
None,
|
||||
Some(Int),
|
||||
Some[i32],
|
||||
}
|
||||
|
||||
pub void test_enum_named() {
|
||||
@@ -20,8 +20,8 @@ pub void test_enum_tuple() {
|
||||
}
|
||||
|
||||
enum Shape {
|
||||
Circle { Int radius },
|
||||
Rect { Int w, Int h },
|
||||
Circle { i32 radius },
|
||||
Rect { i32 w, i32 h },
|
||||
}
|
||||
|
||||
pub void test_enum_struct() {
|
||||
|
||||
@@ -1,52 +1,54 @@
|
||||
pub void test_basic_function() {
|
||||
void greet() {
|
||||
let x = 1;
|
||||
void greet() {
|
||||
let mut x = 1;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_basic_function() {
|
||||
greet();
|
||||
}
|
||||
|
||||
pub void test_fn_params() {
|
||||
Int add(Int a, Int b) {
|
||||
i32 add(i32 a, i32 b) {
|
||||
a + b
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_fn_params() {
|
||||
assert_eq!(add(2, 3), 5);
|
||||
}
|
||||
|
||||
pub void test_fn_return() -> Int {
|
||||
pub i32 test_fn_return() {
|
||||
42
|
||||
}
|
||||
|
||||
pub void test_fn_early_return() -> Int {
|
||||
pub i32 test_fn_early_return() {
|
||||
return 100;
|
||||
0
|
||||
}
|
||||
|
||||
pub void test_fn_mut_param(Int mut x) -> Int {
|
||||
pub i32 test_fn_mut_param(i32 mut x) {
|
||||
x = x + 10;
|
||||
x
|
||||
}
|
||||
|
||||
pub void test_method_call() {
|
||||
String s = "hello";
|
||||
str* s = "hello";
|
||||
assert_eq!(s.len(), 5);
|
||||
assert_eq!(s.to_uppercase(), "HELLO");
|
||||
}
|
||||
|
||||
pub void test_nested_fn_calls() {
|
||||
Int add(Int a, Int b) {
|
||||
a + b
|
||||
}
|
||||
Int triple(Int x) {
|
||||
i32 triple(i32 x) {
|
||||
add(x, add(x, x))
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_nested_fn_calls() {
|
||||
assert_eq!(triple(5), 15);
|
||||
}
|
||||
|
||||
i32 factorial(i32 n) {
|
||||
if (n <= 1) 1
|
||||
else (n) * (factorial(n - 1))
|
||||
}
|
||||
|
||||
pub void test_recursive_fn() {
|
||||
Int factorial(Int n) {
|
||||
if (n <= 1) { 1 } else { n * factorial(n - 1) }
|
||||
}
|
||||
assert_eq!(factorial(5), 120);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
struct Vector2 {
|
||||
Int x,
|
||||
Int y,
|
||||
i32 x,
|
||||
i32 y,
|
||||
}
|
||||
|
||||
impl Vector2 {
|
||||
pub Int magnitude(self*) -> Int {
|
||||
pub i32 magnitude(self*) {
|
||||
self.x * self.x + self.y * self.y
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
struct Point {
|
||||
Int x,
|
||||
Int y,
|
||||
i32 x,
|
||||
i32 y,
|
||||
}
|
||||
|
||||
pub void test_struct_create_access() {
|
||||
@@ -22,12 +22,12 @@ pub void test_struct_destructure() {
|
||||
assert_eq!(y, 4);
|
||||
}
|
||||
|
||||
pub void test_struct_nested() {
|
||||
struct Line {
|
||||
struct Line {
|
||||
Point start,
|
||||
Point end,
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_struct_nested() {
|
||||
let l = Line {
|
||||
start: Point { x: 0, y: 0 },
|
||||
end: Point { x: 5, y: 10 },
|
||||
|
||||
@@ -8,12 +8,12 @@ struct Dog {
|
||||
|
||||
impl Speak for Dog {
|
||||
String speak(self*) {
|
||||
"woof"
|
||||
"woof".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_trait_impl() {
|
||||
let d = Dog { name: "Rex" };
|
||||
let d = Dog { name: "Rex".to_string() };
|
||||
assert_eq!(d.speak(), "woof");
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ trait Greet : Speak {
|
||||
|
||||
impl Greet for Dog {
|
||||
String greet(self*) {
|
||||
"hello"
|
||||
"hello".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_trait_with_requirement() {
|
||||
let d = Dog { name: "Buddy" };
|
||||
let d = Dog { name: "Buddy".to_string() };
|
||||
assert_eq!(d.speak(), "woof");
|
||||
assert_eq!(d.greet(), "hello");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user