Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrated test cases to mocha tests.

  • Loading branch information...
commit 5b56f0ef12c88aa56fe93d2948727cba052f90d7 1 parent 80652b8
@mbebenita authored
View
6 src/tests/arrays.ljs
@@ -1,6 +0,0 @@
-struct Point {
- int x, y;
-}
-
-let int * a = new int [1024];
-let Point * b = new Point [1024];
View
74 src/tests/stack_arrays.ljs
@@ -1,74 +0,0 @@
-extern print;
-
-let passed = true;
-function assert(test, testStr) {
- if (test !== true) {
- print("ASSERTION FAILED: " + testStr);
- passed = false;
- }
-}
-
-struct ST {
- int x;
-};
-
-(function frame0() {
- let int arr[100];
- arr[0] = 5;
- arr[1] = 10;
- assert(*arr === 5, "dereferencing array");
- assert(arr[0] === 5, "access first element");
- assert(arr[1] === 10, "access second element");
-
- let ST s;
- assert(&s-arr === 100, "s is 100 offsets after arr");
-})();
-
-(function other_types() {
- let u8 arr[100];
- arr[0] = 5;
- arr[1] = 10;
- assert(*arr === 5, "dereferencing array");
- assert(arr[0] === 5, "access first element");
- assert(arr[1] === 10, "access second element");
-
- let float arr2[100];
- arr2[0] = 5;
- arr2[1] = 10;
- assert(*arr2 === 5, "dereferencing array");
- assert(arr2[0] === 5, "access first element");
- assert(arr2[1] === 10, "access second element");
-
- let ST s;
- assert(&s-arr === 126, "s is 126 offsets after arr");
-})();
-
-struct InlineArrayST {
- int arr[100];
-};
-
-(function structInlineTest() {
- let InlineArrayST s;
- s.arr[5] = 10;
-
- let ST s2;
- assert(&s2-&s === 100, "s2 is 100 offsets after s");
-})();
-
-struct InlineStructArrayST {
- InlineArrayST arr[100];
-};
-
-(function structInlineTestMeta() {
- let InlineStructArrayST s;
- s.arr[5].arr[5] = 5;
-
- let ST s2;
- assert(&s2-&s === 100*100, "s2 is 100*100 offsets after s");
-})();
-
-
-if (passed)
- print("SUCCESS");
-else
- print("FAILURE");
View
24 src/tests/struct-1.ljs
@@ -1,24 +0,0 @@
-extern print;
-
-struct S {
- union {
- int x;
- float y;
- } u;
- struct {
- int x;
- float y;
- } s;
- int x;
-};
-
-let S s;
-s.u.x = 5;
-s.s.x = 5;
-s.s.y = 3.14;
-s.x = 10;
-print(s.u.x);
-print(s.u.y);
-print(s.s.x);
-print(s.s.y);
-print(s.x);
View
25 src/tests/union-0.ljs
@@ -1,25 +0,0 @@
-extern print;
-
-union foo {
- int x;
- float y;
-};
-
-let foo u;
-u.x = 5;
-print(u.x);
-print(u.y);
-
-let foo *uStar = new foo;
-uStar->x = 5;
-print(uStar->x);
-print(uStar->y);
-
-struct bar {
- foo u;
-};
-
-let bar b;
-b.u.x = 5;
-print(b.u.x);
-print(b.u.y);
View
63 test/arrays-stack.ljs
@@ -0,0 +1,63 @@
+extern describe, it;
+
+struct ST {
+ int x;
+};
+
+struct InlineArrayST {
+ int arr[100];
+};
+
+struct InlineStructArrayST {
+ InlineArrayST arr[100];
+};
+
+describe('Arrays-Stack', function () {
+ it('allocates an int array on the stack', function () {
+ let int arr[100];
+ arr[0] = 5;
+ arr[1] = 10;
+
+ (*arr).should.equal(5);
+ (arr[0]).should.equal(5);
+ (arr[1]).should.equal(10);
+
+ let ST s;
+ (&s-arr).should.equal(100);
+ });
+
+ it('allocates an u8 array on the stack', function () {
+ let u8 arr[100];
+ arr[0] = 5;
+ arr[1] = 10;
+ (*arr).should.equal(5, "dereferencing array");
+ (arr[0]).should.equal(5, "access first element");
+ (arr[1]).should.equal(10, "access second element");
+
+ let float arr2[100];
+ arr2[0] = 5;
+ arr2[1] = 10;
+ (*arr2).should.equal(5);
+ (arr2[0]).should.equal(5);
+ (arr2[1]).should.equal(10);
+
+ let ST s;
+ (&s-arr).should.equal(126);
+ });
+
+ it('allocates a struct with an inline array', function () {
+ let InlineArrayST s;
+ s.arr[5] = 10;
+
+ let ST s2;
+ (&s2-&s).should.equal(100);
+ });
+
+ it('allocates a struct with an inline array of structs with arrays', function () {
+ let InlineStructArrayST s;
+ s.arr[5].arr[5] = 5;
+
+ let ST s2;
+ (&s2-&s).should.equal(100*100);
+ });
+});
View
5 test/array-0.ljs → test/arrays.ljs
@@ -1,9 +1,6 @@
extern describe, it;
-extern Number;
-let assert = require("assert");
-
-describe('Array 0', function() {
+describe('Arrays', function() {
function testElements(int * a, int length) {
for (let int i = 0; i < length; i++) {
a[i] = i;
View
60 test/structs.ljs
@@ -0,0 +1,60 @@
+extern describe, it;
+
+struct S {
+ union {
+ int x;
+ float y;
+ } u;
+ struct {
+ int x;
+ float y;
+ } s;
+ int x;
+};
+
+function floatIsEqual(a, b) {
+ let d = a - b;
+ if (d < 0) {
+ d *= -1;
+ }
+ return d < 0.001;
+}
+
+describe('Structs', function() {
+ it('allocates a struct with unions', function () {
+ let S s;
+ s.u.x = 5;
+ s.s.x = 5;
+ s.s.y = 3.14;
+ s.x = 10;
+
+ (s.u.x).should.equal(5);
+ (s.u.y).should.equal(7.006492321624085e-45);
+ (s.s.x).should.equal(5);
+ floatIsEqual(s.s.y, 3.14).should.be.true;
+ (s.x).should.equal(10);
+ });
+});
+
+union foo {
+ int x;
+ float y;
+};
+
+struct bar {
+ foo u;
+};
+
+describe('Structs', function() {
+ it('allocates an union', function () {
+ let foo u;
+ u.x = 5;
+ (u.x).should.equal(5);
+ (floatIsEqual(u.y, 7.006492321624085e-45)).should.be.true
+
+ let foo *uStar = new foo;
+ uStar->x = 5;
+ (uStar->x).should.equal(5);
+ (floatIsEqual(uStar->y, 7.006492321624085e-45)).should.be.true
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.