START_MARKER |
test_true([["$Id: testsuite.in,v 1.864 2009/02/12 21:06:27 srb Exp $"]]); |
|
// This triggered a bug only if run sufficiently early. |
test_compile_any([[#pike 7.2]]) |
test_compile_any([[#pike 7.4]]) |
test_compile_any([[#pike 7.0]]) |
test_compile_any([[#pike 0.6]]) |
|
cond([[all_constants()->_verify_internals]], |
[[ |
test_do(_verify_internals()) |
]]); |
test_eq(1e1,10.0); |
test_eq(1E1,10.0); |
test_eq(1e+1,10.0); |
test_eq(1.1e1,11.0); |
test_eq(1e-1,0.1); |
test_eq('\x20',32); |
test_eq("\x20","\040"); |
test_eq("\d32","\x20"); |
test_eq('Å',"Å"[0]); |
test_eq('\7777',"\7777"[0]); |
test_eq('\77777777',"\77777777"[0]); |
test_eq("\x10000","\x10000"); |
test_eq(0x80000000-0x80000000, 0); |
test_eq(0xf0000000-0xf0000000, 0); |
test_eq(0x80000001-0x80000000, 1); |
test_eq(0x80000000-0x80000001,-1); |
test_eq(-2147483648*-1, -2147483648/-1); |
cond([[ 0x8000000000000000 ]], |
[[ |
test_eq(0x8000000000000000-0x8000000000000000, 0); |
test_eq(0xf000000000000000-0xf000000000000000, 0); |
test_eq(0x8000000000000001-0x8000000000000000, 1); |
test_eq(0x8000000000000000-0x8000000000000001,-1); |
test_eq(-9223372036854775808*-1, -9223372036854775808/-1); |
]]) |
test_true([[1.0e-40]]); |
test_eq([[#"foo |
bar"]],[["foo\nbar"]]); |
test_eq([[#"foo\ |
bar"]],[["foobar"]]); |
test_true([[stringp(#string "Makefile")]]); |
test_any([[class Bar { array(int) foo = ({}); }; |
class Foo { inherit Bar; array(int) foo = ({1}); }; |
return sizeof(Foo()->foo);]],1); |
|
test_eq([["(" + 0x7fffffff + ")"]], "(2147483647)") |
test_eq([["(" + -0x80000000 + ")"]], "(-2147483648)") |
cond(0x8000000000000000, [[ |
test_eq([["(" + 0x7fffffffffffffff + ")"]], "(9223372036854775807)") |
test_eq([["(" + -0x8000000000000000 + ")"]], "(-9223372036854775808)") |
]]) |
test_eq([["(" + Int.NATIVE_MAX + ")"]], [[sprintf ("(%d)", Int.NATIVE_MAX)]]) |
test_eq([["(" + Int.NATIVE_MIN + ")"]], [[sprintf ("(%d)", Int.NATIVE_MIN)]]) |
|
# __func__ |
test_eq(__func__, "a") |
test_eq("b", __func__) |
|
test_eq(8, 0b1000); |
test_eq(-8, -0b1000); |
test_eq(16, 0b10000); |
test_eq(-16, -0b10000); |
|
test_true(1e-100000000000000000000000000000000000000000000000000000000000<=1e-10000) |
test_true(1e-10000<=1e-1000) |
test_true(1e-1000<=1e-100) |
test_true(1e-100<=1e-10) |
test_true(1e-10<=1e-1) |
test_true(1e-1<=1e1) |
test_true(1e1<=1e10) |
test_true(1e10<=1e100) |
test_true(1e100<=1e1000) |
test_true(1e1000<=1e10000) |
test_true(1e10000<=1e100000000000000000000000000000000000000000000000000000000000) |
|
test_compile_warning('\3434523423423523423423423423') |
test_compile_warning("\3434523423423523423423423423") |
test_compile_warning("\d109827346981234561823743412654") |
test_compile_warning("\x109a27bc69e256c83deaa34c26b4") |
test_compile_error('\u17fo') |
test_compile_warning("\u17fo") |
test_compile_error('\uu117f') |
test_eq("\uuuu17fo", "\\uuu17fo") |
test_eq('\u117f', 0x117f) |
test_eq("\u117foo", "\10577oo") |
test_eq("\u1117foo", "\10427foo") |
test_eq("\uuuu117foo", "\\uuu117foo") |
test_compile_error('\U117f') |
test_compile_warning("\U117f") |
test_compile_warning("\UdEaDbEaT") |
test_eq("\UUdEaDbEaT", "\\UdEaDbEaT") |
test_eq('\UDeaDBeEF', -559038737) |
test_eq("\UDeaDBeEFFF", "\33653337357FF") |
test_eq("\UUDeaDBeEFFF", "\\UDeaDBeEFFF") |
test_any([[ |
// Suppress warnings. |
class handler { |
void compile_warning (string file, int line, string err) {}; |
}; |
return compile_string("string s = \"\\3434523423423523423423423423\";", |
"-", handler())()->s; |
]], "\37777777777") |
test_any([[ |
// Suppress warnings. |
class handler { |
void compile_warning (string file, int line, string err) {}; |
}; |
return compile_string("int i = '\\3434523423423523423423423423';", |
"-", handler())()->i; |
]], -1) |
|
test_do([[ |
// bug 2677 |
int x; |
if (time()) |
x = 1; |
else |
foo: break foo; |
]]) |
|
test_any([[ |
// bug 2690 |
array(function) foo(void|int b) |
{ |
int add() { return b++; }; |
return ({ add, add }); |
}; |
array(function) bar = foo(); |
return equal(({`==(@bar),@bar()}), ({ 1, 0, 1 })); |
]], 1) |
|
test_any([[ |
int f (int i) {i = 0; return i;}; |
return f (1); |
]],0) |
|
test_any([[ |
// Test that F_TAIL_RECUR and RECUR work properly. |
class X |
{ |
int Ack(int M, int N) { |
if (M == 0) return( N + 1 ); |
if (N == 0) return( Ack(M - 1, 1) ); |
return( Ack(M - 1, Ack(M, (N - 1))) ); |
} |
}; |
|
return X()->Ack(3,5); |
]],253) |
|
test_any([[ |
// Test that F_COND_RECUR works properly. |
// This test forces F_COND_RECUR to fail. |
class X |
{ |
int Ack(int M, int N) { |
if (M == 0) return( N + 1 ); |
if (N == 0) return( Ack(M - 1, 1) ); |
return( Ack(M - 1, Ack(M, (N - 1))) ); |
} |
}; |
|
class Y { inherit X; |
int Ack(int M, int N) { return ::Ack(M, N); } |
}; |
|
return Y()->Ack(2,2); |
]],7) |
|
test_any([[ |
// Test that F_RECUR et al are not used for inlined functions |
// where the scope is in use. |
class X { |
inline function(int:int) foo(int x, int y) |
{ |
if (y) return foo(x+y, y-1); |
return lambda(int z) { return x+z; }; |
} |
}; |
return X()->foo(10, 3)(5); |
]], 21) |
|
test_any([[ |
// Test that loop optimizer isn't too aggressive. |
// Thanks to Alexander Demenshin <aldem-pike@aldem.net> |
int x,y,a; |
for(;x<10000;x++) { |
y += (x - a++); |
} |
return a; |
]], 10000) |
|
test_any([[ |
// Test that loop optimizer isn't too aggressive. |
// Thanks to Alexander Demenshin <aldem-pike@aldem.net> |
mapping m = ([]); |
for(;m->x<10000;m->x++) { |
m->y += (m->x - m->a++); |
} |
return m->a; |
]], 10000) |
|
test_any([[ |
// Test that loop optimizer isn't too aggressive. |
// Thanks to me. / Marcus |
for(int i=0; i<3.0; i++) |
if(i>4.0) |
return -1; |
return 0; |
]], 0) |
|
test_any([[ |
// Test that optimizer notes side effects in arguments to `!= |
// Thanks to Marcus Agehall |
int j = 20, i; |
string end = "17"; |
for( ; i < j ; i++) |
if(sscanf(end, "%d%s", j, end) != 2) |
cd("."); |
return i; |
]], 17) |
|
test_any([[ |
// Another over-optimization test. |
string x(string i) { return i; }; |
return x("")+1+1; |
]], "11") |
|
test_compile_any([[ |
mixed foo() |
{ |
Stdio.File bar(int x, int y) |
{ |
return 0; |
}; |
return bar; |
} |
]]) |
|
test_compile_any([[ |
string foo (string a, string b, string c, string d, string e, string f, string g) |
{ |
string out; |
if (a) |
out = "foo"; |
else |
out = "bar"; |
return out; |
} |
]]) |
|
dnl number of variables/scope, number of scopes, expect_compiler_error |
define(test_scopes,[[ |
test_any([[ |
write("Testing scoped variables $1:$2%s...\n", |
$3?" expecting a compilation error":""); |
string line = sprintf("#line %d %O\n", __LINE__, __FILE__); |
string s = "{\n" + |
(map(indices(allocate($1)), lambda(int no) { |
no++; |
return sprintf(" int var_%d;\n" |
" if (var_%d)\n" |
" error(\"Variable var_%d not \"\n" |
" \"initialized to zero: \"\n" |
" \"%%O\\n\",\n" |
" var_%d);\n" |
" var_%d = %d;\n", |
no, no, no, no, no, no); |
}) + |
map(indices(allocate($1)), lambda(int no) { |
no++; |
return sprintf(" if (var_%d != %d)\n" |
" error(\"Variable var_%d was \"\n" |
" \"clobbered with %%O.\\n\",\n" |
" var_%d);\n", |
no, no, no, no); |
})) * "" + |
"}\n"; |
program p; |
if ($3) master()->set_inhibit_compile_errors (1); |
mixed err = catch { |
p = compile_string("int a() {\n" + line + (s * $2) + |
" return 0;\n" |
"}\n"); |
}; |
if ($3) { |
master()->set_inhibit_compile_errors (0); |
if (err) return 0; |
error("Expected a compilation error for $1 variables in $2 scope%s.\n", |
($2>1)?"s":""); |
} |
if (err) throw(err); |
return p()->a(); |
]], 0) |
]]) |
|
test_scopes(255, 1, 0) |
test_scopes(256, 1, 1) |
test_scopes(16, 17, 0) |
test_scopes(17, 16, 0) |
|
test_any([[ |
// LysLysKOM 14180500 |
if (1) { |
string var = "Reinitialization error."; |
} |
sscanf("", "%d", int zero); |
return zero; |
]], 0); |
|
test_any([[ |
// LysLysKOM 14189033 |
int i; |
for (i = 0; i < 4; i++) { |
sscanf("", "%d", int test); |
if (test) return test; |
test = i+1; |
} |
return 0; |
]], 0) |
|
dnl FIXME: Add test that local and local:: in combination |
dnl with recursion works correctly. |
|
test_eval_error([[mixed x; return mkmapping(x,x)]]); |
|
test_eval_error([[class Foo { |
void bar() {} |
void foo() {destruct(this_object());bar();} |
}; |
Foo()->foo(); |
]]) |
|
test_do([[ |
void foo (int i) { |
multiset res = (<>); |
if (i) res = res; |
}; |
foo (1); |
]]) |
|
test_any([[ |
array tmp=({}); |
tmp=({([])})+tmp; |
tmp->foo=7; |
tmp=({([])})+tmp; |
return sizeof(tmp[0]); |
]], 0) |
|
test_any([[ |
// Bug 4537. |
void fiddle(array(int) a) |
{ |
a += ({ 2 }); |
}; |
|
array(int) a = ({ 1 }); |
fiddle(a); |
return sizeof(a); |
]], 1) |
|
dnl bug in for loop optimization in combination with += |
|
test_any([[ |
array v=({1,2,3}); |
for (int i=0; i<sizeof(v); i++) |
for (int j=0; j<i; j++) |
{ |
v+=({1+i}); |
if (i==17) { i=10000; break; } |
} |
return sizeof(v); // if buggy, will be 6 and not 140 |
]], 140); |
|
test_any([[ |
array v=({1,2,3}); |
for (int i=0; i<sizeof(v); i++) |
for (int j=0; j<i; j++) |
{ |
v=v+({1+i}); |
if (i==17) { i=10000; break; } |
} |
return sizeof(v); // not buggy, will be 140 |
]], 140); |
|
test_any([[int a=0xffffffff; return a+17]], 0x100000010); |
test_any([[int a=0xffffffff; return a-17]], 0xffffffee); |
test_any([[int a=0xffffffff; return a*17]], 0x10ffffffef); |
test_any([[int a=0xffffffff; return a^17]], 0xffffffee); |
test_any([[int a=0xffffffff; return a&17]], 17); |
test_any([[int a=0xffffffff; return a|17]], 0xffffffff); |
test_any([[int a=0xffffffff; return a<<17]], 0x1fffffffe0000); |
|
test_any([[ int a=0xffffffff; return a/17 ]], |
[[ (0xffffffff == -1)?-1:0x0f0f0f0f ]]); |
test_any([[ int a=0xffffffff; return a%17 ]], |
[[ (0xffffffff == -1)?16:0 ]]); |
test_any([[ int a=0xffffffff; return a>>17 ]], |
[[ (0xffffffff == -1)?-1:0x7fff ]]); |
|
test_any([[return sprintf("%O", typeof(aggregate("foo")));]], "array(string(0..255))"); |
test_any([[int a; return sprintf("%O", typeof(aggregate(a)));]], "array(int)"); |
test_any([[int|string a; |
string s = sprintf("%O", typeof(aggregate(a))); |
return (< "array(string) | array(int)", "array(string | int)", "array(int | string)" >)[s];]], 1); |
test_any([[return sprintf("%O", typeof(aggregate()));]], "array(zero)"); |
test_any([[int i; return (< "int", "int | zero", "zero | int" >) |
[sprintf("%O", typeof(max(i,0)))];]], 1) |
|
test_any([[array(string) a; return sprintf("%O", typeof(a[0])); ]], "string") |
|
test_any([[class foo { string a; }; |
object(foo) bar; |
return sprintf("%O", typeof(bar->a));]], "string"); |
|
test_any([[class foo { string a; }; |
array(object(foo)) bar; |
return sprintf("%O", typeof(bar[0]->a));]], "string"); |
|
test_any([[function(:string)|function(int:int) f; |
return sprintf("%O", typeof(f())); ]], |
"string") |
|
test_any([[function(:string)|function(int:int) f; |
return sprintf("%O", typeof(f(1))); ]], |
"int") |
|
test_any([[function(:string)|function(mixed, mixed...:int) f; |
return sprintf("%O", typeof(f())); ]], |
"string") |
|
test_any([[function(:string)|function(mixed, mixed ...:int) f; |
return sprintf("%O", typeof(f(1))); ]], |
"int") |
|
test_any([[mapping(object:string)|mapping(string:int) f; |
return sprintf("%O", typeof(f[class{}()])); ]], |
"string") |
|
test_any([[mapping(object:string)|mapping(string:int) f; |
return sprintf("%O", typeof(f[""])); ]], |
"int") |
|
test_any([[mapping(object:string)|mapping(string:int) f; |
return sort((sprintf("%O", typeof(f[0])) - " ")/"|")*"|"; ]], |
"int|string") |
|