Skip to content

Commit

Permalink
merge interpret3
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Feb 6, 2011
1 parent f77b501 commit 110a7e0
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -237,3 +237,105 @@ struct Matrix5248 {
};

static assert(Matrix5248().Compile());

// Interpreter code coverage tests
int cov1(int a)
{
a %= 15382;
a /= 5;
a = ~ a;
bool c = (a==0);
bool b = true && c;
assert(b==0);
b = false && c;
assert(b==0);
b = false || c;
assert(b==0);
a ^= 0x45349;
a = ~ a;
a &= 0xFF3F;
a >>>= 1;
a = a ^ 0x7393;
a = a >> 1;
a = a >>> 1;
a = a | 0x010101;
return a;
}
static assert(cov1(534564) == 71589);

int cov2()
{
int i = 0;
do{
goto DOLABEL;
DOLABEL:
if (i!=0) {
goto IFLABEL;
IFLABEL:
switch(i) {
case 3:
break;
case 6:
goto SWITCHLABEL;
SWITCHLABEL:
i = 27;
goto case 3;
}
return i;
}
i = 6;
} while(true);
return 88; // unreachable
}

static assert(cov2()==27);

template CovTuple(T...)
{
alias T CovTuple;
}

alias CovTuple!(int, long) TCov3;

int cov3(TCov3 t)
{
TCov3 s;
s = t;
assert(s[0] == 1);
assert(s[1] == 2);
return 7;
}

static assert(cov3(1, 2) == 7);

template compiles(int T)
{
bool compiles = true;
}

int badassert1(int z)
{
assert(z == 5, "xyz");
return 1;
}

size_t badslice1(int[] z)
{
return z[0..3].length;
}

size_t badslice2(int[] z)
{
return z[0..badassert1(1)].length;
}

size_t badslice3(int[] z)
{
return z[badassert1(1)..2].length;
}

static assert(!is(typeof(compiles!(badassert1(67)))));
static assert(is(typeof(compiles!(badassert1(5)))));
static assert(!is(typeof(compiles!(badslice1([1,2])))));
static assert(!is(typeof(compiles!(badslice2([1,2])))));
static assert(!is(typeof(compiles!(badslice3([1,2,3])))));

0 comments on commit 110a7e0

Please sign in to comment.