Fix formatter bugs
This commit is contained in:
@@ -8,13 +8,10 @@ pub void test_let_basic() {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -101,15 +101,22 @@ pub void test_block_expr() {
|
||||
}
|
||||
|
||||
pub void test_if_expr() {
|
||||
let x = if true { 1 } else { 2 };
|
||||
let x = if true {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
};
|
||||
assert_eq!(x, 1);
|
||||
|
||||
let y = if false { 1 } else { 2 };
|
||||
let y = if false {
|
||||
1
|
||||
} else {
|
||||
2
|
||||
};
|
||||
assert_eq!(y, 2);
|
||||
}
|
||||
|
||||
pub void test_range_expr() {
|
||||
let r = 0..5;
|
||||
let r = 0 .. 5;
|
||||
let mut count = 0;
|
||||
for i in r {
|
||||
count++;
|
||||
|
||||
@@ -3,10 +3,8 @@ pub module statement_test;
|
||||
pub void test_var_decl() {
|
||||
let x = 42;
|
||||
assert_eq!(x, 42);
|
||||
|
||||
i32 y = 10;
|
||||
assert_eq!(y, 10);
|
||||
|
||||
str& name = "mist";
|
||||
assert_eq!(name, "mist");
|
||||
}
|
||||
@@ -19,12 +17,10 @@ pub void test_var_decl_with_init() {
|
||||
|
||||
pub void test_if_statement() {
|
||||
let mut x = 0;
|
||||
|
||||
if true {
|
||||
x = 1;
|
||||
}
|
||||
assert_eq!(x, 1);
|
||||
|
||||
if false {
|
||||
x = 2;
|
||||
} else {
|
||||
@@ -35,7 +31,6 @@ pub void test_if_statement() {
|
||||
|
||||
pub void test_if_else_if() {
|
||||
let mut x = 0;
|
||||
|
||||
if x == 1 {
|
||||
x = 10;
|
||||
} else if x == 0 {
|
||||
@@ -48,7 +43,6 @@ pub void test_if_else_if() {
|
||||
|
||||
pub void test_while_loop() {
|
||||
let mut count = 0;
|
||||
|
||||
while count < 5 {
|
||||
count++;
|
||||
}
|
||||
@@ -57,8 +51,7 @@ pub void test_while_loop() {
|
||||
|
||||
pub void test_for_loop() {
|
||||
let mut sum = 0;
|
||||
|
||||
for i in 0..4 {
|
||||
for i in 0 .. 4 {
|
||||
sum += i;
|
||||
}
|
||||
assert_eq!(sum, 6);
|
||||
@@ -66,7 +59,6 @@ pub void test_for_loop() {
|
||||
|
||||
pub void test_loop_stmt() {
|
||||
let mut count = 0;
|
||||
|
||||
loop {
|
||||
count++;
|
||||
if count >= 3 {
|
||||
@@ -78,8 +70,7 @@ pub void test_loop_stmt() {
|
||||
|
||||
pub void test_break_continue() {
|
||||
let mut sum = 0;
|
||||
|
||||
for i in 0..10 {
|
||||
for i in 0 .. 10 {
|
||||
if i % 2 == 0 {
|
||||
continue;
|
||||
}
|
||||
@@ -106,12 +97,13 @@ pub void test_block_scope() {
|
||||
pub void test_match_literal() {
|
||||
let x = 2;
|
||||
let result;
|
||||
|
||||
match x {
|
||||
1 => { result = 10; }
|
||||
2 => result = 20;
|
||||
3 => result = 30,
|
||||
_ => panic!();
|
||||
1 => {
|
||||
result = 10;
|
||||
}
|
||||
2 => result = 20;,
|
||||
3 => result = 30;,
|
||||
_ => panic!();,
|
||||
}
|
||||
assert_eq!(result, 20);
|
||||
}
|
||||
@@ -119,11 +111,14 @@ pub void test_match_literal() {
|
||||
pub void test_match_or_pattern() {
|
||||
let x = 1;
|
||||
i32 result;
|
||||
|
||||
match x {
|
||||
1 | 2 => { result = 100; }
|
||||
3 => { result = 200; }
|
||||
_ => panic!();
|
||||
1 | 2 => {
|
||||
result = 100;
|
||||
}
|
||||
3 => {
|
||||
result = 200;
|
||||
}
|
||||
_ => panic!();,
|
||||
}
|
||||
assert_eq!(result, 100);
|
||||
}
|
||||
@@ -131,10 +126,13 @@ pub void test_match_or_pattern() {
|
||||
pub void test_match_default() {
|
||||
let x = 99;
|
||||
let result;
|
||||
|
||||
match x {
|
||||
1 => { result = 10; }
|
||||
y => { result = y; }
|
||||
1 => {
|
||||
result = 10;
|
||||
}
|
||||
y => {
|
||||
result = y;
|
||||
}
|
||||
}
|
||||
assert_eq!(result, 99);
|
||||
}
|
||||
@@ -142,7 +140,6 @@ pub void test_match_default() {
|
||||
pub void test_for_with_pattern_destructure() {
|
||||
let pairs = [(1, "a"), (2, "b")];
|
||||
let mut keys = 0;
|
||||
|
||||
for (k, _) in pairs {
|
||||
keys += k;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ pub void test_float_type() {
|
||||
pub void test_bool_type() {
|
||||
bool x = true;
|
||||
assert_eq!(x, true);
|
||||
|
||||
bool y = false;
|
||||
assert_eq!(y, false);
|
||||
}
|
||||
@@ -37,12 +36,13 @@ pub void test_ref_type() {
|
||||
|
||||
pub void test_mut_ref_type() {
|
||||
let mut x = 42;
|
||||
i32 mut& r = &mut x;
|
||||
i32 &mut r = &mut x;
|
||||
*r = 100;
|
||||
assert_eq!(x, 100);
|
||||
}
|
||||
|
||||
pub void test_void_type() {}
|
||||
pub void test_void_type() {
|
||||
}
|
||||
|
||||
i32 add(i32 a, i32 b) {
|
||||
a + b
|
||||
|
||||
@@ -6,7 +6,9 @@ pub struct Debuggable {
|
||||
}
|
||||
|
||||
pub void test_derive_attribute() {
|
||||
let d = Debuggable { value: 42 };
|
||||
let d = Debuggable {
|
||||
value: 42,
|
||||
};
|
||||
assert_eq!(d.value, 42);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +1,52 @@
|
||||
pub module class_test;
|
||||
|
||||
pub class Animal {
|
||||
|
||||
pub String name;
|
||||
|
||||
constructor() {
|
||||
self.name = "Rex".to_string();
|
||||
}
|
||||
|
||||
pub String speak(&self) {
|
||||
"Unknown".to_string()
|
||||
} pub void test_speak<'a>(&'a self) {
|
||||
}
|
||||
|
||||
pub void test_speak<'a>(&'a self) {
|
||||
assert_eq!(self.speak(), "Woof!");
|
||||
} pub void static_method() {
|
||||
}}
|
||||
}
|
||||
|
||||
pub void static_method() {
|
||||
}
|
||||
}
|
||||
|
||||
pub class Mammal : Animal {
|
||||
|
||||
constructor() {
|
||||
super = Super::new();
|
||||
}
|
||||
|
||||
pub void args_test(&self, i32 x, str& y) {
|
||||
assert_eq!(x, 10);
|
||||
assert_eq!(y, "hello");
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
pub class Dog : Mammal {
|
||||
|
||||
constructor() {
|
||||
super = Super::new();
|
||||
}
|
||||
|
||||
pub String speak(&self) override(Animal) {
|
||||
"Woof!".to_string()
|
||||
} implstd::fmt::Display {
|
||||
}
|
||||
|
||||
impl std::fmt::Display {
|
||||
Result<(), std::fmt::Error> fmt(&self, std::fmt::Formatter<'_>& mut f) {
|
||||
write!(f, "🐾 {}", self.name)
|
||||
} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub void run_tests() {
|
||||
@@ -38,4 +54,4 @@ pub void run_tests() {
|
||||
dawg.args_test(10, "hello");
|
||||
dawg.test_speak();
|
||||
assert_eq!(format!("{dawg}"), "🐾 Rex");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,35 +8,50 @@ enum OptionInt {
|
||||
pub void test_enum_named() {
|
||||
let x = OptionInt::None;
|
||||
match x {
|
||||
OptionInt::None => { assert_eq!(1, 1); }
|
||||
OptionInt::Some(_) => { assert_eq!(0, 1); }
|
||||
OptionInt::None => {
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
OptionInt::Some(_) => {
|
||||
assert_eq!(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_enum_tuple() {
|
||||
let x = OptionInt::Some(42);
|
||||
match x {
|
||||
OptionInt::None => { assert_eq!(0, 1); }
|
||||
OptionInt::Some(v) => { assert_eq!(v, 42); }
|
||||
OptionInt::None => {
|
||||
assert_eq!(0, 1);
|
||||
}
|
||||
OptionInt::Some(v) => {
|
||||
assert_eq!(v, 42);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Shape {
|
||||
Circle { i32 radius },
|
||||
Rect { i32 w, i32 h },
|
||||
Circle {i32 radius},
|
||||
Rect {i32 w, i32 h},
|
||||
}
|
||||
|
||||
pub void test_enum_struct() {
|
||||
let c = Shape::Circle { radius: 5 };
|
||||
let c = Shape::Circle{radius: 5, };
|
||||
match c {
|
||||
Shape::Circle { radius } => { assert_eq!(radius, 5); }
|
||||
Shape::Rect { .. } => { assert_eq!(0, 1); }
|
||||
Shape::Circle {radius} => {
|
||||
assert_eq!(radius, 5);
|
||||
}
|
||||
Shape::Rect {..} => {
|
||||
assert_eq!(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
let r = Shape::Rect { w: 3, h: 4 };
|
||||
let r = Shape::Rect{w: 3, h: 4, };
|
||||
match r {
|
||||
Shape::Circle { .. } => { assert_eq!(0, 1); }
|
||||
Shape::Rect { w, h } => { assert_eq!(w * h, 12); }
|
||||
Shape::Circle {..} => {
|
||||
assert_eq!(0, 1);
|
||||
}
|
||||
Shape::Rect {w, h} => {
|
||||
assert_eq!(w * h, 12);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +64,12 @@ enum Color {
|
||||
pub void test_enum_eq() {
|
||||
let c = Color::Red;
|
||||
match c {
|
||||
Color::Red => { assert_eq!(1, 1); }
|
||||
_ => { assert_eq!(0, 1); }
|
||||
Color::Red => {
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
_ => {
|
||||
assert_eq!(0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,11 @@ pub void test_nested_fn_calls() {
|
||||
}
|
||||
|
||||
i32 factorial(i32 n) {
|
||||
if n <= 1 { 1 }
|
||||
else { n * factorial(n - 1) }
|
||||
if n <= 1 {
|
||||
1
|
||||
} else {
|
||||
n * factorial(n - 1)
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_recursive_fn() {
|
||||
|
||||
@@ -12,7 +12,10 @@ impl Vector2 {
|
||||
}
|
||||
|
||||
pub void test_inherent_impl() {
|
||||
let v = Vector2 { x: 3, y: 4 };
|
||||
let v = Vector2 {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
assert_eq!(v.magnitude(), 25);
|
||||
}
|
||||
|
||||
@@ -27,7 +30,10 @@ impl Display for Vector2 {
|
||||
}
|
||||
|
||||
pub void test_trait_impl_block() {
|
||||
let v = Vector2 { x: 1, y: 2 };
|
||||
let v = Vector2 {
|
||||
x: 1,
|
||||
y: 2,
|
||||
};
|
||||
let s = v.display();
|
||||
assert_eq!(s.len() > 0, true);
|
||||
}
|
||||
@@ -42,8 +48,14 @@ impl Vector2 {
|
||||
}
|
||||
|
||||
pub void test_multiple_impls() {
|
||||
let a = Vector2 { x: 1, y: 2 };
|
||||
let b = Vector2 { x: 3, y: 4 };
|
||||
let a = Vector2 {
|
||||
x: 1,
|
||||
y: 2,
|
||||
};
|
||||
let b = Vector2 {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
let c = a.add(b);
|
||||
assert_eq!(c.x, 4);
|
||||
assert_eq!(c.y, 6);
|
||||
|
||||
@@ -6,20 +6,29 @@ struct Point {
|
||||
}
|
||||
|
||||
pub void test_struct_create_access() {
|
||||
let p = Point { x: 10, y: 20 };
|
||||
let p = Point {
|
||||
x: 10,
|
||||
y: 20,
|
||||
};
|
||||
assert_eq!(p.x, 10);
|
||||
assert_eq!(p.y, 20);
|
||||
}
|
||||
|
||||
pub void test_struct_mut_field() {
|
||||
let mut p = Point { x: 1, y: 2 };
|
||||
let mut p = Point {
|
||||
x: 1,
|
||||
y: 2,
|
||||
};
|
||||
p.x = 100;
|
||||
assert_eq!(p.x, 100);
|
||||
}
|
||||
|
||||
pub void test_struct_destructure() {
|
||||
let p = Point { x: 3, y: 4 };
|
||||
let Point { x, y } = p;
|
||||
let p = Point {
|
||||
x: 3,
|
||||
y: 4,
|
||||
};
|
||||
let Point {x, y} = p;
|
||||
assert_eq!(x, 3);
|
||||
assert_eq!(y, 4);
|
||||
}
|
||||
@@ -31,8 +40,14 @@ struct Line {
|
||||
|
||||
pub void test_struct_nested() {
|
||||
let l = Line {
|
||||
start: Point { x: 0, y: 0 },
|
||||
end: Point { x: 5, y: 10 },
|
||||
start: Point {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
end: Point {
|
||||
x: 5,
|
||||
y: 10,
|
||||
},
|
||||
};
|
||||
assert_eq!(l.start.x, 0);
|
||||
assert_eq!(l.end.y, 10);
|
||||
|
||||
@@ -25,12 +25,16 @@ impl Greet for Dog {
|
||||
}
|
||||
|
||||
pub void test_trait_impl() {
|
||||
let d = Dog { name: "Rex".to_string() };
|
||||
let d = Dog {
|
||||
name: "Rex".to_string(),
|
||||
};
|
||||
assert_eq!(d.speak(), "woof");
|
||||
}
|
||||
|
||||
pub void test_trait_with_requirement() {
|
||||
let d = Dog { name: "Buddy".to_string() };
|
||||
let d = Dog {
|
||||
name: "Buddy".to_string(),
|
||||
};
|
||||
assert_eq!(d.speak(), "woof");
|
||||
assert_eq!(d.greet(), "hello");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user