Fix formatter bugs
This commit is contained in:
@@ -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