Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evanbenadler committed Dec 29, 2020
1 parent 0621e4f commit 838b330
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
File renamed without changes.
52 changes: 52 additions & 0 deletions test/oop/access_modifiers.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class animal {
public int a;
protected int b;
private int c;

public animal init(int a, int b, int c) {
self(a, b, c);
}
public int get_c() { return this.c; }
public void set_c(int x) {this.c = x; }

private void baz(){}
protected void bar(){ this.baz(); }
public void foo(){}
};

class dog : animal {
public int d;
private int e;

public dog init(int a, int b, int c, int d, int e) {
super(a, b, c);
self(d, e);
}
public int get_b() { return this.b; }
public void set_b(int x) {this.b = x; }
public int get_e() { return this.e; }
public void set_e(int x) {this.e = x; }

private void f1(){}
public void f2(){ this.foo(); this.bar(); this.f1(); }
};

void main () {
dog my_dog = new_dog(1,2,3,4,5);

int x = 0;
x = my_dog.a;
x = my_dog.d;
x = my_dog.get_b();
x = my_dog.get_c();
x = my_dog.get_e();

my_dog.a = 0;
my_dog.d = 0;
my_dog.set_b(0);
my_dog.set_c(0);
my_dog.set_e(0);

my_dog.foo();
my_dog.f2();
}
15 changes: 15 additions & 0 deletions test/oop/fn_input_output.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class d {
public int a;

public d init(int a) {
self(a);
}
};

void foo(d x) {}
d bar() { return new_d(5); }

void main() {
d my_d = bar();
foo(my_d);
}
44 changes: 44 additions & 0 deletions test/oop/highly_chained.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class c1 {
public int a;
public c1 init(int x) {
self(x);
}
};
class c2 : c1 {
public int b;
public c2 init(int x1, int x2) {
super(x1);
self(x2);
}
};
class c3 : c2 {
public int c;
public c3 init(int x1, int x2, int x3) {
super(x1, x2);
self(x3);
}
};
class c4 : c3 {
public int d;
public c4 init(int x1, int x2, int x3, int x4) {
super(x1, x2, x3);
self(x4);
}
};
class c5 : c4 {
public int e;
public c5 init(int x1, int x2, int x3, int x4, int x5) {
super(x1, x2, x3, x4);
self(x5);
}
};

void main() {
c5 c = new_c5(1,2,3,4,5);
int x = 0;
x = c.a;
x = c.b;
x = c.c;
x = c.d;
x = c.e;
}
21 changes: 21 additions & 0 deletions test/oop/obj_fields.lgl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class human {
public int x;
public int y;
public human init(int a, int b){
self(a,b);
}
};

class dog {
public human owner;
public dog init(human h) {
self(h);
}
};

void main() {
human h = new_human(5,6);
dog d = new_dog(h);
int t = d.owner.x;
d.owner.y = t;
}

0 comments on commit 838b330

Please sign in to comment.