Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (56 sloc) 1.34 KB
let assert = require("assert");
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;
assert (*arr === 5);
assert (arr[0] === 5);
assert (arr[1] === 10);
let ST s;
assert (&s - arr === 100);
});
it('allocates an u8 array on the stack', function () {
let u8 arr[100];
arr[2] = 5;
assert (arr[2] === 5);
});
it('allocates an u8 array on the stack', function () {
let u8 arr[100];
arr[0] = 5;
arr[1] = 10;
assert (*arr === 5);
assert (arr[0] === 5);
assert (arr[1] === 10);
let float arr2[100];
arr2[0] = 5;
arr2[1] = 10;
assert (*arr2 === 5);
assert (arr2[0] === 5);
assert (arr2[1] === 10);
let ST s;
assert (&s - (ST *)(arr) === 126);
});
it('allocates a struct with an inline array', function () {
let InlineArrayST s;
s.arr[5] = 10;
let ST s2;
assert (&s2 - (ST *)(&s) === 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;
assert (&s2 - (ST *)(&s) === 100 * 100);
});
});