Added testing! call kraken like so ./kraken --test ../path/to/test/name_of_test_without_extention This will make kraken compile and run name_of_test_without_extention.krak and compare the output it generates on stdout to name_of_test_without_extention.expected_results. If they pass, then it records the pass, if not, it records the failure and saves the intermediate files generated. It has revealed some bugs which I will fix in upcoming commits.

This commit is contained in:
Nathan Braswell
2014-05-20 22:21:07 -04:00
parent 39f945940d
commit 2566cbb67c
26 changed files with 430 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
3 9
6 18
Subtraction
3 9
-97 -61

View File

@@ -0,0 +1,64 @@
import io;
typedef Vec2 {
int x;
int y;
void print() {
print(x);
print(" ");
print(y);
}
Vec2 add(Vec2 other) {
Vec2 toReturn;
toReturn.x = x + other.x;
toReturn.y = y + other.y;
print();
return toReturn;
}
Vec2 subtract(Vec2 other) {
Vec2 toReturn;
toReturn.x = x - other.x;
toReturn.y = y - other.y;
print();
return toReturn;
}
Vec2 operator+(Vec2 other) {
return add(other);
}
};
Vec2 operator-(Vec2 lhs, Vec2 rhs) {
return lhs.subtract(rhs);
}
int main() {
Vec2 vector1;
Vec2 vector2;
vector1.x = 3;
vector1.y = 9;
vector2 = vector1;
/* NOTE COMMENT
Vec2 vector3;
vector3.x = vector1.x + vector2.x;
vector3.y = vector1.y + vector2.y;
vector2.print();
*/
Vec2 addition = vector1 + vector2;
print("\n");
addition.print();
print("\nSubtraction\n");
vector2.x = 100;
vector2.y = 70;
Vec2 subtraction = vector1 - vector2;
print("\n");
print(subtraction.x); print(" "); print(subtraction.y);
print("\n");
return 0;
}

View File

@@ -0,0 +1 @@
5

14
tests/RecursiveTest.krak Normal file
View File

@@ -0,0 +1,14 @@
import io;
int fibanacci(int num) {
if (num < 2)
return 1;
return fibanacci(num-1) + fibanacci(num-2);
}
int main() {
print(fibanacci(4));
print("\n");
return 0;
}

View File

@@ -0,0 +1 @@
22

View File

@@ -0,0 +1,14 @@
import io;
template <T>T addAndPrint(T a, T b) {
print(a+b);
return a+b;
}
int main() {
addAndPrint<int>(10,12);
print("\n");
return 0;
}

View File

@@ -0,0 +1,3 @@
11
Hello decent memory! Quite a nice feeling

27
tests/memTest.krak Normal file
View File

@@ -0,0 +1,27 @@
import mem;
import io;
typedef AnObject {
int a;
int b;
char* c;
void print() {
print(a+b);
print("\n");
print(c);
print("\n");
}
};
int main() {
AnObject* ptr = new<AnObject>();
ptr->a = 4;
ptr->b = 7;
ptr->c = "Hello decent memory! Quite a nice feeling\n";
ptr->print();
delete<AnObject>(ptr);
return 0;
}

View File

@@ -0,0 +1,2 @@
742
1337

View File

@@ -0,0 +1,29 @@
import io;
typedef firstObject {
int objectNum;
int other;
void print() {
print(other);
}
void printInd() {
print();
}
};
typedef Int int;
Int aliasNum;
int main() {
firstObject wooObject;
wooObject.objectNum = 7;
print(wooObject.objectNum);
firstObject* objPtr = &wooObject;
objPtr->objectNum = 42;
print(objPtr->objectNum);
print("\n");
objPtr->other = 1337;
objPtr->printInd();
print("\n");
}

View File

@@ -0,0 +1 @@
12

View File

@@ -0,0 +1,27 @@
import io;
typedef objectA {
int a;
};
typedef BigObject {
objectA a;
objectB b;
int add() {
return a.a + b.b;
}
};
typedef objectB {
int b;
};
int main() {
BigObject c;
c.a.a = 4;
c.b.b = 8;
print(c.add());
print("\n");
return 0;
}

View File

@@ -0,0 +1 @@
1919

View File

@@ -0,0 +1,14 @@
import io;
int addAndPrintInt(int a, int b) {
print(a+b);
return a+b;
}
int main() {
print(addAndPrintInt(7,12));
print("\n");
return 0;
}

View File

@@ -0,0 +1 @@
57

View File

@@ -0,0 +1,18 @@
import io;
typedef FirstObject {
int objectNum;
void PrintSelf(int a) {
print(objectNum);
print(a);
}
};
int main() {
FirstObject wooObject;
wooObject.objectNum = 5;
wooObject.PrintSelf(7);
print("\n");
return 0;
}

View File

@@ -0,0 +1,8 @@
a: 5
b: 7
1337
a: 9
b: Hello Templates!
Woooo nesting!
From another file! Whoh!
1919

52
tests/templateTest.krak Normal file
View File

@@ -0,0 +1,52 @@
import io;
import trivial_container;
typedef template <T> TemplateTest {
int a;
T b;
trivialContainer<T> c;
void print() {
print("a: ");
print(a);
print("\n");
print("b: ");
print(b);
print("\n");
c.print();
print("\n");
}
};
typedef MyInt int;
MyInt c;
template <T> T addAndPrint(T a, T b) {
print(a+b);
return a+b;
}
int main() {
TemplateTest<int> test;
TemplateTest<char*> test2;
test.a = 5;
test.b = 7;
test.c.data = 1337;
test2.a = 9;
test2.b = "Hello Templates!";
test2.c.data = "Woooo nesting!";
test.print();
test2.print();
trivialContainer<char*> testImport;
testImport.data = "From another file! Whoh!";
testImport.print();
print("\n");
print(addAndPrint<int>(7,12));
print("\n");
return 0;
}

View File

@@ -0,0 +1 @@
777

View File

@@ -0,0 +1,13 @@
import io;
import mem;
int main() {
int b;
int* a = &b;
a [ 0 ] = 7;
print(a [ 0 ] );
print(*a);
print(b);
print("\n");
return 0;
}