Updated type grammar #65
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
pub class Counter {
|
||||
pub i32 count;
|
||||
|
||||
pub constructor(i32 start) {
|
||||
self.count = start;
|
||||
}
|
||||
|
||||
pub void increment(self mut*) {
|
||||
self.count++;
|
||||
}
|
||||
|
||||
pub i32 get(self*) {
|
||||
self.count
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_class_create() {
|
||||
let c = Counter::new(0);
|
||||
assert_eq!(c.get(), 0);
|
||||
}
|
||||
|
||||
pub void test_class_method() {
|
||||
let mut c = Counter::new(5);
|
||||
c.increment();
|
||||
assert_eq!(c.get(), 6);
|
||||
}
|
||||
|
||||
pub void test_class_field_access() {
|
||||
let c = Counter::new(42);
|
||||
assert_eq!(c.count, 42);
|
||||
}
|
||||
|
||||
class NamedCounter : Counter {
|
||||
pub String name;
|
||||
|
||||
pub constructor(i32 start, String name) {
|
||||
self._super = Counter::new(start);
|
||||
|
||||
self.name = name;
|
||||
}
|
||||
|
||||
pub String get_name(self*) {
|
||||
self.name.clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub void test_class_inherit() {
|
||||
let nc = NamedCounter::new(10, "test".to_string());
|
||||
assert_eq!(nc.get_name(), "test");
|
||||
assert_eq!(nc.count, 10);
|
||||
}
|
||||
|
||||
pub void run_tests() {
|
||||
test_class_create();
|
||||
test_class_method();
|
||||
test_class_field_access();
|
||||
test_class_inherit();
|
||||
}
|
||||
Reference in New Issue
Block a user