pike.git
/
src
/
testsuite.in
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/testsuite.in:1:
-
test
_
true([["$Id: testsuite.in,v 1.365 2001/01/11 17:17:18 js Exp $"]]);
+
START
_
MARKER
-
+
// 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);
pike.git/src/testsuite.in:14:
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)]])
+
test_eq([[Int.NATIVE_MAX]], [[(int) (Int.NATIVE_MAX + "")]])
+
test_eq([[Int.NATIVE_MIN]], [[(int) (Int.NATIVE_MIN + "")]])
+
test_eq([[(string) Int.NATIVE_MAX]], [[Int.NATIVE_MAX + ""]])
+
test_eq([[(string) Int.NATIVE_MIN]], [[Int.NATIVE_MIN + ""]])
+
test_eq([[(string) Int.NATIVE_MAX]], [[sprintf ("%d", Int.NATIVE_MAX)]])
+
test_eq([[(string) 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_any([[
+
// Check that parent pointers aren't added unnecessarily [bug 2672].
+
class I {};
+
+
class X
+
{
+
// Neither the inherit nor the variable type should add
+
// a parent pointer requirement.
+
inherit I;
+
I i;
+
};
+
+
X x = ((program) X)(); // Error: Parent lost, cannot clone program.
+
return 0;
+
]], 0)
+
+
test_any([[
+
// Check that parent pointers aren't added unnecessarily [bug 2672].
+
class I {};
+
+
class X
+
{
+
// The cloning of I makes X need its parent usually,
+
// but note that since we're nested in a function
+
// scope by the testsuite, I will not be overloadable,
+
// and thus we won't need the parent.
+
inherit I;
+
I i = I();
+
};
+
+
X x = ((program) X)(); // Error: Parent lost, cannot clone program.
+
return 0;
+
]], 0)
+
+
test_eval_error([[
+
class Wrapper {
+
// Check that parent pointers aren't added unnecessarily [bug 2672].
+
class I {}
+
+
class X
+
{
+
// The cloning of I makes X need its parent.
+
inherit I;
+
I i = I();
+
}
+
};
+
+
object x = ((program) (Wrapper()->X))(); // Error: Parent lost, cannot clone program.
+
return 0;
+
]], 0)
+
+
test_any([[
+
// Check that parent pointers aren't added unnecessarily [LysLysKOM 18781511].
+
+
class Foo {
+
final constant const = 1;
+
class Bar
+
{
+
int func()
+
{
+
// parent-pointer not needed, since const is final.
+
return const;
+
};
+
}
+
};
+
+
return !Foo.Bar;
+
+
]], 0)
+
+
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([[
+
log_status("Testing scoped variables $1:$2%s...",
+
$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)
+
+
test_eval_error([[
+
// [Bug 5911]
+
class X {
+
string s;
+
};
+
X()->s = (mixed) X();
+
]])
+
+
test_any([[
+
// Bug 6062
+
class C { mapping options = ([ 1:1 ]); };
+
C c = C();
+
c->options[3] = 3;
+
c = C();
+
return sizeof(c->options) == 1;
+
]], 1)
+
+
test_any([[
+
// Bug 6063
+
class A { extern string s; string q() { return s; } };
+
class B { inherit A; string s = "s"; };
+
class C { inherit B; };
+
class D { inherit C; };
+
return ({ B(), C(), D() })->q() * "";
+
]], "sss")
+
+
test_any([[
+
// bug 6065
+
class A(string s) {};
+
class B(string s) { inherit A; };
+
return B("foo")->s;
+
]], "foo")
+
+
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)");
+
test_any([[return sprintf("%O", typeof(aggregate("foo")));]], "array(string
(102..111
)
)
");
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 | int)", "array(int | string)" >)[s];]], 1);
+
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");
pike.git/src/testsuite.in:128:
test_any([[class Foo { array(string) _values() {return ({""});} }; object(Foo) foo; return sprintf("%O", typeof(values(foo))); ]], "array(string)") test_any([[mapping(string:int) foo; array(string) bar; return sprintf("%O", typeof(rows(foo, bar))); ]], "array(int)")
+
test_any([[{
+
class Foo
+
{
+
mixed m;
+
};
+
class Bar
+
{
+
inherit Foo;
+
string m;
+
Foo b;
+
mixed f() {
+
return typeof(b->m);
+
}
+
};
+
Foo c;
+
Bar d;
+
return sprintf("%O$%O$%O$%O",
+
Bar()->f(), typeof(c->m), typeof(d->m), typeof(d->b->m));
+
}]], "mixed$mixed$string$mixed")
+
+
// las.c:find_return_type() checks.
+
test_eq([[
+
// Test case from Robert J. Budzynski <Robert.Budzynski@fuw.edu.pl>.
+
// When broken the return type will be mixed.
+
sprintf("%O", typeof(lambda(string s){
+
return Charset.decoder("utf-8")->feed(s)->drain();
+
}))
+
]], [[ "function(string : string)" ]])
+
+
// Test implicit lambda.
+
test_eq([[
+
`()(){ return 1; }
+
]], 1)
+
+
// Argument checking
+
+
// Test new_check_call.
test_any([[
-
+
constant foo = 5;
+
+
// Test that it survives a F_ARG_LIST with CAR == CDR.
+
return foo%foo;
+
]], 0)
+
+
// Test get_all_args.
+
test_eval_error([[
+
// A trick to get some svalues to freed refcounted stuff on the stack.
+
lambda (mixed a, mixed b, mixed c) {} (({time()}), ({time()}), ({time()}));
+
// set_weak_flag is chosen since it calls get_all_args with an
+
// argument spec that contains two arguments of different types.
+
([function] set_weak_flag)();
+
]])
+
test_eval_error([[
+
lambda (mixed a, mixed b, mixed c) {} (({time()}), ({time()}), ({time()}));
+
([function] set_weak_flag) (17);
+
]])
+
test_eval_error([[
+
lambda (mixed a, mixed b, mixed c) {} (({time()}), ({time()}), ({time()}));
+
([function] set_weak_flag) ("foo");
+
]])
+
test_eval_error([[
+
lambda (mixed a, mixed b, mixed c) {} (({time()}), ({time()}), ({time()}));
+
([function] set_weak_flag) (17, "foo");
+
]])
+
+
// Check that write() and error() with one argument are not
+
// incorrectly subjected to sprintf() argument
+
test_compile([[write("%\u2323");]])
+
test_compile([[error("%\u2323");]])
+
+
// type checks
+
+
define(test_type_error, [[
+
test_compile_error([[ $1 x; x=$3; ]])
+
test_compile_error_any([[ class ErrBa { $1 x() { return $3; } } ]])
+
test_compile_error_any([[ class ErrBa { $1 x() { $2 a=$3; return a; } } ]])
+
]])
+
+
test_type_error(int,float,17.23)
+
test_type_error(int,array,({1,2,3}))
+
test_type_error(int,mapping,([1:2,3:4]))
+
test_type_error(int,multiset,(<1,2,3>))
+
test_type_error(int,function,lambda() { return 17; })
+
test_type_error(int,program,object_program(this_object()))
+
test_type_error(int,object,this_object())
+
+
test_type_error(float,int,17)
+
test_type_error(float,array,({1,2,3}))
+
test_type_error(float,mapping,([1:2,3:4]))
+
test_type_error(float,multiset,(<1,2,3>))
+
test_type_error(float,function,lambda() { return 17; })
+
test_type_error(float,program,object_program(this_object()))
+
test_type_error(float,object,this_object())
+
+
test_type_error(array,int,17)
+
test_type_error(array,float,17.23)
+
test_type_error(array,mapping,([1:2,3:4]))
+
test_type_error(array,multiset,(<1,2,3>))
+
test_type_error(array,function,lambda() { return 17; })
+
test_type_error(array,program,object_program(this_object()))
+
test_type_error(array,object,this_object())
+
+
test_type_error(mapping,int,17)
+
test_type_error(mapping,float,17.23)
+
test_type_error(mapping,array,({1,2,3}))
+
test_type_error(mapping,multiset,(<1,2,3>))
+
test_type_error(mapping,function,lambda() { return 17; })
+
test_type_error(mapping,program,object_program(this_object()))
+
test_type_error(mapping,object,this_object())
+
+
test_type_error(multiset,int,17)
+
test_type_error(multiset,float,17.23)
+
test_type_error(multiset,array,({1,2,3}))
+
test_type_error(multiset,mapping,([1:2,3:4]))
+
test_type_error(multiset,function,lambda() { return 17; })
+
test_type_error(multiset,program,object_program(this_object()))
+
test_type_error(multiset,object,this_object())
+
+
test_type_error(function,int,17)
+
test_type_error(function,float,17.23)
+
test_type_error(function,array,({1,2,3}))
+
test_type_error(function,mapping,([1:2,3:4]))
+
test_type_error(function,multiset,(<1,2,3>))
+
+
test_type_error(program,int,17)
+
test_type_error(program,float,17.23)
+
test_type_error(program,array,({1,2,3}))
+
test_type_error(program,mapping,([1:2,3:4]))
+
test_type_error(program,multiset,(<1,2,3>))
+
+
test_type_error(object,int,17)
+
test_type_error(object,float,17.23)
+
test_type_error(object,array,({1,2,3}))
+
test_type_error(object,mapping,([1:2,3:4]))
+
test_type_error(object,multiset,(<1,2,3>))
+
+
test_any_equal([[
+
// This code caused a NULL dereference in Pike 7.8.306 and earlier.
+
indices foo;
+
return typeof(foo);
+
]], typeof(indices((mixed)0)))
+
+
// Check that complex function types survive soft casting to function.
+
ignore_warning("Soft cast of scope(0,function(*)) to function is a noop.", [[
+
test_eq(typeof([function]`+), typeof(`+))
+
]])
+
+
test_compile_error([[ static_assert(0, "Fail."); ]])
+
test_any([[ static_assert(1, "Ok."); ]], 0)
+
+
test_any([[
+
/* Detect bug in modify_shared_string().
+
*
+
* Note: For proper operation this test depends on HASH_PREFIX being
+
* <= 128, and the initial string in test having a single ref.
+
*/
+
string prefix = "A"*128;
+
string suffix = "B"*128;
+
+
string test = prefix + "C" + suffix;
+
string match = prefix + "D" + suffix;
+
+
if (test == match) return("Early match!");
+
+
test[128] = 'D';
+
+
if (test != match) return("Late mismatch!");
+
]], 0)
+
+
test_compile_error([[ string a="abcb"; a=a/"b"; ]])
+
test_compile_error([[ string a="abcb"; a/="b"; ]])
+
test_compile_error([[ string a="abcb"; string b="b"; a=a/b; ]])
+
test_compile_error([[ string a="abcb"; string b="b"; a/=b; ]])
+
test_compile_error([[ string a="x"; int b; b="x"*17; ]])
+
test_compile_error([[ string a="x"; array b; b="x"*17; ]])
+
test_compile_error([[ int b=17; string a; a=b*42; ]])
+
test_compile_error([[ int b=17; float c=42.0; b=b/c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b/=c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b=b*c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b*=c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b=b+c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b+=c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b=b-c; ]])
+
test_compile_error([[ int b=17; float c=42.0; b-=c; ]])
+
test_compile_error([[ float b=17.0; string a; a=b*42; ]])
+
test_compile_error([[ float b=17.0; string a; a=b*42.0; ]])
+
+
test_compile_error([[class F {inherit master()->dirnode;};]]);
+
+
test_any([[
+
class A {
+
constant i = -1;
+
string f() {
+
return ([1: "foo"])[i] || "bar"; // No warning here. C.f. lyslys 16630665.
+
}
+
};
+
class B {
+
inherit A;
+
constant i = 1;
+
};
+
return B()->f();
+
]], "foo")
+
+
ignore_warning("Wrong return type.", [[
+
ignore_warning("Expected: string.", [[
+
ignore_warning("Got : array(string).", [[
+
test_program_equal([[
+
#pike 7.6
+
string a()
+
{
+
string|array(string) res = ({"spud"});
+
return res + ({});
+
}
+
]], ({"spud"}))
+
]])]])]])
+
+
// Warnings
+
+
test_compile_warning([[ int *a ]])
+
test_compile_warning([[ int|float *a ]])
+
test_compile_warning([[ [mixed]1 ]])
+
test_compile_warning([[
+
class A { int a = 6; };
+
class B {
+
constant a = 5;
+
inherit A;
+
};
+
]])
+
+
//
+
+
test_any([[
class Foo { constant zero = 0; mapping(string:array(int)) m; string foo() { return sprintf("%O", typeof(m[""][zero])); } }; return Foo()->foo(); ]], "int") test_compile_any([[ class { ; }
pike.git/src/testsuite.in:150:
test_compile_any([[ class { ; ; } ]]) test_compile_any([[ class { ; constant c = 0; } ]]) test_compile_any([[
+
class { mixed a() { constant c = 17; return c; }
+
mixed b() { constant c = 17; return c; } }
+
]])
+
+
test_compile_any([[
constant FOO = 0; mapping(int:string) foo = ([FOO: "foo"]); ]]) test_compile_error([[ function(...:int) foo; ]]); test_compile_error([[ function(,...:int) foo; ]]); test_compile_error([[ function(string,...:int) foo; ]]);
-
+
test_compile_any([[
+
#pragma strict_types
+
void x (void|mapping(string:string) args)
+
{
+
if (args)
+
foreach (indices (args), string a)
+
werror ("%O\n", a);
+
}
+
]])
+
+
// For some reason, the test above doesn't generate the warning (about
+
// the type from indices (args)) if it comes after the one below.
+
// Also, if it is repeated it doesn't generate the warning the second
+
// time. Not very reassuring.. /mast
+
test_any([[return class Z { string bonk() { return "oiff"; } class A { string bonk_me() { return bonk(); } } class B { inherit A; } class C { string oiff() { return "bonk"; } class D { inherit B; } } }()->C()->D()->bonk_me()]],"oiff")
-
+
test_any_equal([[
+
// Test hiding of inherited symbols with protected.
+
class A {
+
local mixed a() {}
+
mixed b();
+
mixed c;
+
local mixed d;
+
extern mixed e;
+
local mixed f;
+
local mixed g() {}
+
mixed h();
+
this_program get_a() { return this_program::this; }
+
};
+
class B {
+
inherit A;
+
protected mixed a() {}
+
protected mixed b() {}
+
protected mixed c = a();
+
protected mixed d = b();
+
protected mixed e = a();
+
protected local mixed f = b();
+
protected mixed g();
+
protected mixed h();
+
this_program get_b() { return this_program::this; }
+
};
+
class C {
+
inherit B;
+
this_program get_c() { return this_program::this; }
+
};
+
class D {
+
inherit C;
+
this_program get_d() { return this_program::this; }
+
};
+
object(D) d = D();
+
return ({ "A", sort(indices(d->get_a())),
+
"B", sort(indices(d->get_b())),
+
"C", sort(indices(d->get_c())),
+
"D", sort(indices(d->get_d())) });
+
]], ({ "A", ({ "a", "b", "c", "d", "e", "f", "g", "get_a", "h" }),
+
"B", ({ "get_a", "get_b" }),
+
"C", ({ "get_a", "get_b", "get_c" }),
+
"D", ({ "get_a", "get_b", "get_c", "get_d" }) }))
+
+
test_any_equal([[
+
// Test hiding of inherited symbols with private.
+
class A {
+
local mixed a() {}
+
mixed b();
+
mixed c;
+
local mixed d;
+
extern mixed e;
+
local mixed f;
+
this_program get_a() { return this_program::this; }
+
};
+
class B {
+
inherit A;
+
private mixed a() {}
+
private mixed b() {}
+
private mixed c = a();
+
private mixed d = b();
+
private mixed e = a();
+
private local mixed f = b();
+
this_program get_b() { return this_program::this; }
+
};
+
class C {
+
inherit B;
+
this_program get_c() { return this_program::this; }
+
};
+
class D {
+
inherit C;
+
this_program get_d() { return this_program::this; }
+
};
+
object(D) d = D();
+
return ({ "A", sort(indices(d->get_a())),
+
"B", sort(indices(d->get_b())),
+
"C", sort(indices(d->get_c())),
+
"D", sort(indices(d->get_d())) });
+
]], ({ "A", ({ "a", "b", "c", "d", "e", "f", "get_a" }),
+
"B", ({ "get_a", "get_b" }),
+
"C", ({ "get_a", "get_b", "get_c" }),
+
"D", ({ "get_a", "get_b", "get_c", "get_d" }) }))
+
+
test_any([[
+
// Test that backtraces with prototypes are rendered correctly by
+
// describe_backtrace() et al. These backtraces have caused both
+
// "Bad offset" and "Identifier reference index out of range".
+
class A { void foo(); };
+
class B { int gazonk; inherit A; void bar() { foo(); } };
+
return sizeof(describe_backtrace(catch { B()->bar(); })) > 0;
+
]], 1)
+
+
test_any([[
+
// Test that backtraces with event handlers are rendered correctly.
+
// These backtraces have caused SEGV's due to function pointers
+
// out of bounds. cf [bug 6156].
+
return sizeof(describe_backtrace(catch {
+
Builtin.__Backtrace_Tester__();
+
})) > 0;
+
]], 1)
+
+
test_any([[
+
// Test that backtraces with event handlers are rendered correctly.
+
// These backtraces have caused SEGV's due to function pointers
+
// out of bounds. cf [bug 6156].
+
return catch { Builtin.__Backtrace_Tester__(); }[1][-1][2];
+
]], Builtin.__Backtrace_Tester__)
+
+
test_any([[
+
// Test multiple inherit of same symbol,
+
// where later symbol is protected.
+
class A { constant foo = 1; };
+
class B { constant foo = 2; };
+
class C { inherit A; protected inherit B; };
+
return C()->foo;
+
]], 1)
+
+
test_any([[
+
// Test multiple inherit of same symbol,
+
// where later symbol is protected.
+
class A { constant foo = 1; };
+
class B { protected constant foo = 2; };
+
class C { inherit A; inherit B; };
+
return C()->foo;
+
]], 1)
+
+
test_any_equal([[
+
// Test that extern works as intended.
+
class A { extern mixed foo; };
+
class B { inherit A; mixed foo; object get_a() { return A::this; } };
+
object(B) b = B();
+
b->foo = 17;
+
array res = ({ b->foo, b->get_a()->foo });
+
b->get_a()->foo = 10;
+
return res + ({ b->foo, b->get_a()->foo });
+
]], ({ 17, 17, 10, 10 }))
+
+
test_eval_error([[
+
// Test that extern works as intended.
+
class A { extern mixed foo; };
+
class B { inherit A; mixed bar; };
+
object(B) b = B();
+
b->bar = 17;
+
b->foo = 10;
+
return b->foo;
+
]])
+
test_compile_error([[ class A { constant q = "x"; } class B { inherit A; string z="z"; constant q="x"+z; } ]]) test_compile_any([[ class A { object x(int y) {
pike.git/src/testsuite.in:205:
} class B { void create(int y) { } } ]])
+
// Test that prototypes evaluate to zero.
+
test_any([[
+
class Foo {int foo();};
+
return Foo()->foo == 0;
+
]], 1)
+
test_any_equal([[
+
class Foo {int foo();};
+
return indices(Foo());
+
]], ({"foo"}))
+
test_any_equal([[
+
class Foo {int foo();};
+
return values(Foo());
+
]], ({0}))
+
test_any([[
+
class Foo
+
{
+
int foo();
+
int(0..1) f()
+
{
+
return foo == 0;
+
}
+
};
+
return Foo()->f();
+
]], 1)
+
test_any([[
+
class Foo
+
{
+
int foo();
+
int(0..1) f()
+
{
+
return functionp(foo);
+
}
+
};
+
class Bar
+
{
+
inherit Foo;
+
int foo() {}
+
};
+
return Bar()->f();
+
]], 1)
+
test_do([[ class Foo { inherit Stdio.File; void create() { } }; class Bar {
pike.git/src/testsuite.in:239:
void create() { Gazonk(Stdio.stdin); } }; Bar(); ]])
+
test_any([[
+
object f = class {
+
array recursive(mixed func, array data, mixed ... args)
+
{
+
array ret=({});
+
+
foreach(data, mixed foo)
+
{
+
if(arrayp(foo))
+
{
+
ret+=({ recursive(func, foo, @args) });
+
}else{
+
ret+=({ foo });
+
}
+
}
+
+
return func(ret, @args);
+
};
+
}();
+
+
mixed x = ({ "A", ({}) });
+
x = f->recursive(replace, x, "B", ({}));
+
+
for(int i = 0; i < sizeof(x); i++) {
+
if (!stringp(x[i]) && !arrayp(x[i])) return 0;
+
}
+
return 1;
+
]], 1);
+
+
test_compile_error( [[
+
// This triggs a compiler bug on old Pike 7.3.
+
non_existant(17) {
+
return 0;
+
}
+
]])
+
+
test_compile_error( [[
+
// This triggs a segfault on Pike 7.4.
+
void f()
+
{
+
constant days =
+
([ "1" : "Sunday"
+
"2" : "Monday" ]);
+
}
+
]])
+
+
test_compile_error( [[
+
// This triggs a compiler bug on old Pike 7.5.
+
return lambda(object (([mixed]a)->syntax_error) { return 0; }(0);
+
]])
+
+
test_compile_error( [[
+
// [bug 4362] This triggs a segfault on some versions of Pike 7.7.
+
mixed x = all_constants()[undefined_identifier];
+
]])
+
+
test_compile_any([[
+
#pike 7.4
+
#pragma strict_types
+
string x (string s) {return s;}
+
void y (void|string s) {x (s);}
+
]])
+
+
test_compile_warning([[
+
#pragma strict_types
+
// NB: This case used to leak the type function(:string).
+
string x (string s) {return s;};
+
void y (string|int s) {x (s);};
+
]])
+
+
test_compile_any([[
+
#pragma strict_types
+
array(string) x = ({"A", "B"});
+
mixed a() {return map (x, lower_case);}
+
]])
+
+
test_compile_any([[
+
class X {
+
X bar();
+
}
+
class Y {
+
constant X = global::X;
+
X foo();
+
}
+
]])
+
+
cond( [[ master()->resolv("Pike")->Security ]],[[
+
test_any( [[
+
// bug [2830] ------------------------------------------------------------
+
// http://community/crunch/show_bug.cgi?id=2830
+
class User{};
+
+
object luser = User();
+
+
object luser_creds = Pike.Security.Creds(luser, 0, 0);
+
return !catch {
+
return !!Pike.Security.call_with_creds(luser_creds, Stdio.File,
+
"/dev/null");
+
};
+
+
return 0;
+
]], 0 )
+
]])
+
+
test_any( [[
+
// bug [1996] ------------------------------------------------------------
+
// http://community/crunch/show_bug.cgi?id=1996
+
class Implementation
+
{
+
int foo() { return 1; }
+
};
+
class Prototype
+
{
+
int foo();
+
int bar() { return foo(); }
+
};
+
class Test
+
{
+
inherit Implementation;
+
inherit Prototype;
+
int test() { return bar(); }
+
};
+
return Test()->test();
+
]], 1 );
+
+
test_any( [[
+
// bug [721] -------------------------------------------------------------
+
// http://community/crunch/show_bug.cgi?id=721
+
int res=0;
+
catch
+
{
+
add_constant("test_a",compile_string("int foo();","test_a"));
+
add_constant("test_b",compile_string("int foo();","test_b"));
+
add_constant("test_c",compile_string(
+
"inherit test_a;\n"
+
"inherit test_b;\n"
+
"final int foo() { return 1; }\n","test_c"));
+
res=compile_string("inherit test_c;\n","test_d")()->foo();
+
};
+
return res;
+
]],1);
+
test_do(add_constant("test_a"))
+
test_do(add_constant("test_b"))
+
test_do(add_constant("test_c"))
+
+
test_any( [[
+
// bug [1858] ------------------------------------------------------------
+
// http://community/crunch/show_bug.cgi?id=1858
+
string s=#"
+
constant foo=({this_object()});
+
int|string test()
+
{
+
if (!foo[0]) return sprintf(\"foo is %O\\n\",foo)-\"\\n\";
+
if (foo[0]==this_object()) return 1;
+
return sprintf(\"foo is %O\\n\",foo)-\"\\n\";
+
}
+
";
+
class handler { void compile_error(string file, int line, string err) { }};
+
catch {
+
program p=compile_string(s,"test",handler());
+
return p()->test();
+
};
+
return 1; // compile error is ok
+
]],1);
+
+
// -----------------------------------------------------------------------
+
+
+
+
// This test checks for excessive recursion in
+
// destruct_objects_to_destruct, and also that it keeps the destruct
+
// order sane.
+
test_do([[
+
class Top
+
{
+
int count = 0;
+
+
class Foo
+
{
+
int c;
+
object foo;
+
protected void create(object o)
+
{
+
foo = o;
+
c = count++;
+
}
+
+
void destroy()
+
{
+
count--;
+
if (count != c)
+
error ("Destruct out of sequence, "
+
"%d destructed when %d should be.\n", c, count);
+
object x = foo && Foo(0);
+
x = 0;
+
// Cause call to destruct_objects_to_destruct.
+
for (int j = 0; j < 10; j++) write ("");
+
}
+
}
+
+
mixed eat_stack(int|void probe)
+
{
+
// Avoid eating as much C-stack by releasing the
+
// catch at every level.
+
if (probe) return 1;
+
if (catch(eat_stack(1))) return 1;
+
mixed err = 1;
+
if ((err = eat_stack()) != 10)
+
return intp(err) && err > 0 ? err + 1 : err;
+
if (err = catch {
+
+
Foo foo;
+
for(int i=0; i < 10000; i++)
+
foo = Foo(foo);
+
foo = 0;
+
// Cause call to destruct_objects_to_destruct.
+
for (int j = 0; j < 10; j++) write ("");
+
+
}) return err;
+
}
+
+
protected void create()
+
{
+
if (mixed err = eat_stack()) {
+
catch (err[1] = err[1][sizeof (err[1]) - 50..]);
+
throw (err);
+
}
+
}
+
};
+
+
Top();
+
]]);
+
+
// Testing stack popping wrt the various function call opcodes
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
object key = monitor::lock();
+
return f (1); // F_CALL_LFUN_AND_RETURN
+
};
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
mixed g = f;
+
int a()
+
{
+
object key = monitor::lock();
+
return g (1); // F_CALL_FUNCTION_AND_RETURN
+
}
+
]]);
+
test_program([[
+
Thread.Mutex monitor = Thread.Mutex();
+
int f (int x)
+
{
+
if(monitor->trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
add_constant ("f", f);
+
add_constant ("monitor", monitor);
+
return compile_string(#"
+
int g()
+
{
+
object key = monitor->lock();
+
return f (1); // F_APPLY_AND_RETURN
+
}")()->g();
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int dummy;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
object key = monitor::lock();
+
int res = this->f (1); // F_CALL_OTHER (no `->)
+
dummy = random (res);
+
return res;
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
mixed `-> (string what) {return this[what];}
+
int dummy;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
object key = monitor::lock();
+
int res = this->f (1); // F_CALL_OTHER (with `->)
+
dummy = random (res);
+
return res;
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int res = 0;
+
void f (int x)
+
{
+
if(monitor::trylock(1))
+
res = 0;
+
else
+
res = x;
+
};
+
int a()
+
{
+
object key = monitor::lock();
+
this->f (1); // F_CALL_OTHER_AND_POP (no `->)
+
return res;
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
mixed `-> (string what) {return this[what];}
+
int res = 0;
+
void f (int x)
+
{
+
if(monitor::trylock(1))
+
res = 0;
+
else
+
res = x;
+
};
+
int a()
+
{
+
object key = monitor::lock();
+
this->f (1); // F_CALL_OTHER_AND_POP (with `->)
+
return res;
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
object key = monitor::lock();
+
return this->f (1); // F_CALL_OTHER_AND_RETURN (no `->)
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
mixed `-> (string what) {return this[what];}
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
object key = monitor::lock();
+
return this->f (1); // F_CALL_OTHER_AND_RETURN (with `->)
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (iter == 1) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 1;
+
return a (1); // F_COND_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 2;
+
return a (1); // F_TAIL_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 2;
+
int res = a (1); // F_RECUR
+
iter = -1;
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
iter = 0;
+
iter = x;
+
}
+
else {
+
object key = monitor::lock();
+
iter = 2;
+
a (1); // F_RECUR_AND_POP
+
return iter;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
foreach (({1, monitor::lock()}), mixed m)
+
return f (m); // F_CALL_LFUN_AND_RETURN
+
};
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
mixed g = f;
+
int a()
+
{
+
foreach (({1, monitor::lock()}), mixed m)
+
return g (m); // F_CALL_FUNCTION_AND_RETURN
+
}
+
]]);
+
test_program([[
+
Thread.Mutex monitor = Thread.Mutex();
+
int f (int x)
+
{
+
if(monitor->trylock(1))
+
return 0;
+
return x;
+
}
+
int a()
+
{
+
add_constant ("f", f);
+
add_constant ("monitor", monitor);
+
return compile_string(#"
+
int g()
+
{
+
foreach (({1, monitor->lock()}), mixed m)
+
return f (m); // F_APPLY_AND_RETURN
+
}")()->g();
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int dummy;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
int res;
+
foreach (({1, monitor::lock()}), mixed m) {
+
res = this->f (m); // F_CALL_OTHER (no `->)
+
dummy = random (res);
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
mixed `-> (string what) {return this[what];}
+
int dummy;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
int res;
+
foreach (({1, monitor::lock()}), mixed m) {
+
res = this->f (m); // F_CALL_OTHER (with `->)
+
dummy = random (res);
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int res = 0;
+
void f (int x)
+
{
+
if(monitor::trylock(1))
+
res = 0;
+
else
+
res = x;
+
};
+
int a()
+
{
+
foreach (({1, monitor::lock()}), mixed m) {
+
this->f (m); // F_CALL_OTHER_AND_POP (no `->)
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
mixed `-> (string what) {return this[what];}
+
int res = 0;
+
void f (int x)
+
{
+
if(monitor::trylock(1))
+
res = 0;
+
else
+
res = x;
+
};
+
int a()
+
{
+
foreach (({1, monitor::lock()}), mixed m) {
+
this->f (m); // F_CALL_OTHER_AND_POP (with `->)
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
foreach (({1, monitor::lock()}), mixed m)
+
return this->f (m); // F_CALL_OTHER_AND_RETURN (no `->)
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
mixed `-> (string what) {return this[what];}
+
int f (int x)
+
{
+
if(monitor::trylock(1))
+
return 0;
+
return x;
+
};
+
int a()
+
{
+
foreach (({1, monitor::lock()}), mixed m)
+
return this->f (m); // F_CALL_OTHER_AND_RETURN (with `->)
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (iter == 1) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
iter = 1;
+
foreach (({1, monitor::lock()}), mixed m)
+
return a (m); // F_COND_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
iter = 2;
+
foreach (({1, monitor::lock()}), mixed m)
+
return a (m); // F_TAIL_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
return 0;
+
return x;
+
}
+
else {
+
iter = 2;
+
int res;
+
foreach (({1, monitor::lock()}), mixed m) {
+
res = a (m); // F_RECUR
+
iter = random (res);
+
return res;
+
}
+
}
+
}
+
]]);
+
test_program([[
+
inherit Thread.Mutex : monitor;
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
if (monitor::trylock(1))
+
iter = 0;
+
iter = x;
+
}
+
else {
+
iter = 2;
+
foreach (({1, monitor::lock()}), mixed m) {
+
a (m); // F_RECUR_AND_POP
+
return iter;
+
}
+
}
+
}
+
]]);
+
test_do(add_constant("f"))
+
test_do(add_constant("monitor"))
+
+
// Testing scoped frames wrt the various function call opcodes
+
test_program([[
+
int f (int x)
+
{
+
return x;
+
}
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
return f (1); // F_CALL_LFUN_AND_RETURN
+
};
+
]]);
+
test_program([[
+
int f (int x)
+
{
+
return x;
+
};
+
mixed g = f;
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
return g (1); // F_CALL_FUNCTION_AND_RETURN
+
}
+
]]);
+
test_program([[
+
int f (int x)
+
{
+
return x;
+
}
+
int a()
+
{
+
add_constant ("f", f);
+
return compile_string(#"
+
int g (void|int x)
+
{
+
function s = lambda () {return x;};
+
return f (1); // F_APPLY_AND_RETURN
+
}")()->g();
+
}
+
]]);
+
test_program([[
+
int dummy;
+
int f (int x)
+
{
+
return x;
+
};
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
int res = this->f (1); // F_CALL_OTHER (no `->)
+
dummy = random (res);
+
return res;
+
}
+
]]);
+
test_program([[
+
mixed `-> (string what) {return this[what];}
+
int dummy;
+
int f (int x)
+
{
+
return x;
+
};
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
int res = this->f (1); // F_CALL_OTHER (with `->)
+
dummy = random (res);
+
return res;
+
}
+
]]);
+
test_program([[
+
int res = 0;
+
void f (int x)
+
{
+
res = x;
+
};
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
this->f (1); // F_CALL_OTHER_AND_POP (no `->)
+
return res;
+
}
+
]]);
+
test_program([[
+
mixed `-> (string what) {return this[what];}
+
int res = 0;
+
void f (int x)
+
{
+
res = x;
+
};
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
this->f (1); // F_CALL_OTHER_AND_POP (with `->)
+
return res;
+
}
+
]]);
+
test_program([[
+
int f (int x)
+
{
+
return x;
+
};
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
return this->f (1); // F_CALL_OTHER_AND_RETURN (no `->)
+
}
+
]]);
+
test_program([[
+
mixed `-> (string what) {return this[what];}
+
int f (int x)
+
{
+
return x;
+
};
+
int a (void|int x)
+
{
+
function s = lambda () {return x;};
+
return this->f (1); // F_CALL_OTHER_AND_RETURN (with `->)
+
}
+
]]);
+
test_program([[
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (iter == 1) {
+
return x;
+
}
+
else {
+
function s = lambda () {return x;};
+
iter = 1;
+
return a (1); // F_COND_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
return x;
+
}
+
else {
+
function s = lambda () {return x;};
+
iter = 2;
+
return a (1); // F_TAIL_RECUR
+
}
+
}
+
]]);
+
test_program([[
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
return x;
+
}
+
else {
+
function s = lambda () {return x;};
+
iter = 2;
+
int res = a (1); // F_RECUR
+
iter = -1;
+
return res;
+
}
+
}
+
]]);
+
test_program([[
+
int iter = 0;
+
int a (void|int x)
+
{
+
if (!iter) {
+
iter = 1;
+
return a (x);
+
}
+
else if (iter == 2) {
+
iter = x;
+
}
+
else {
+
function s = lambda () {return x;};
+
iter = 2;
+
a (1); // F_RECUR_AND_POP
+
return iter;
+
}
+
}
+
]]);
+
test_do(add_constant("f"))
+
test_false([[object_variablep(class X { int y; int z() { return 1; }}(),"foo")]]) test_false([[object_variablep(class X { int y; int z() { return 1; }}(),"z")]]) test_true([[object_variablep(class X { int y; int z() { return 1; }}(),"y")]]) test_any([[ int a,b; [a,b]=({1,2}); return a]],1) test_any([[ int a,b; [a,b]=({1,2}); return b]],2) test_any([[ int a,b; [ [a],b]=({ ({ 1 }) ,2}); return a]],1) test_any([[ int a,b; [ [a],b]=({ ({ 1 }) ,2}); return b]],2)
-
test_any([[ int a; catch { [a]=({1,2}); }; return 1]],1)
-
test_any([[ int a,b; catch { [a,b]=({1}); }; return 1]],1)
+
test_any([[ int a; catch { [a]=({1,2});
return 0;
}; return 1]],1)
+
test_
compile_error([[ int a,b; catch { [a,b]=({1}); return 0; }; return 1]],1)
+
test_
any([[ int a,b; catch { [a,b]=
lambda
(
){ return (
{1}); }
()
; return
0; }; return
1]],1)
test_any([[ mapping m=([]); m[m]=m; return stringp(sprintf("%O",m)); ]],1)
-
+
dnl test_any([[
+
dnl // don't know if this /should/ be valid /Mirar
+
dnl // remove if it shouldn't
+
dnl
+
dnl // I see no reason this should be allowed - Hubbe
+
dnl
+
dnl array a=({});
+
dnl []=a; return 1; ]],1)
-
+
test_any([[
+
int q() { throw(1); };
+
catch {
+
return q();
+
};
+
return 17;
+
]],17)
+
+
test_any([[
+
return class
+
{
+
int q() { throw(1); };
+
int p() {
+
catch {
+
return q();
+
};
+
return 17;
+
}
+
}()->p();
+
]],17)
+
test_compile_error([[
-
static
function foo(string ...:object);
+
protected
function foo(string ...:object);
int bar() { return 17; } ]]) test_compile_error([[ array a; a = path_info[..(sizeof(path_info)-2]*"/"; ]]) test_compile_error([[ default ; ]])
pike.git/src/testsuite.in:282:
int main() { return 0; } ]]) dnl dnl this_program dnl
+
test_true(this_program) test_any([[int this_program; return this_program;]], 0) test_any([[class A { int a() { return this_program == A; }}; return A()->a();]], 1)
-
+
test_program([[
+
class A (int v)
+
{
+
this_program clone() {return this_program (v);}
+
}
+
int a() {return A (4)->clone()->v == 4;}
+
]])
+
test_program([[
+
int i = 17, j = 18;
+
class A (int v)
+
{
+
this_program clone() {return this_program (i);}
+
}
+
int a() {return A (4)->clone()->v == 17;}
+
]])
+
test_program([[
+
class A (int v)
+
{
+
this_program clone() {return this_program (j);}
+
}
+
int i = 17, j = 18;
+
int a() {return A (4)->clone()->v == 18;}
+
]])
+
test_program([[
+
int i = 17, v;
+
this_program clone() {return this_program (i);}
+
void create (int v_) {v = v_;}
+
int a() {return clone()->v == 17;}
+
]])
+
test_program([[
+
this_program clone() {return this_program (i);}
+
int i = 17, v;
+
void create (int v_) {v = v_;}
+
int a() {return clone()->v == 17;}
+
]])
+
test_program([[
+
class A {this_program clone() {return this_program();}}
+
class B {inherit A;}
+
int a() {return object_program (B()->clone()) == B;}
+
]])
+
test_program([[
+
class A {this_program clone() {return this_program();}}
+
class B {inherit A;}
+
int a() {return typeof(B()->clone()) <= B;}
+
]])
-
+
test_program([[
+
class A {
+
class B {
+
mixed f() {
+
return ({global::this_program,
+
A::this_program, // Works, but not really useful.
+
B::this_program, // Ditto.
+
this_program});
+
}
+
}
+
}
+
int a() {
+
return equal (A()->B()->f(), ({object_program (this_object()), A, A.B, A.B}));
+
}
+
]])
+
+
test_compile_error([[
+
mixed x() {
+
return ::x;
+
}
+
]])
+
+
test_program([[
+
class A {
+
class B {
+
constant this_program = "foo";
+
mixed f (int this_program) {
+
return ({A::this_program, B::this_program, this_program});
+
}
+
}
+
}
+
int a() {
+
return equal (A()->B()->f (1), ({A, "foo", 1}));
+
}
+
]])
+
+
test_program([[
+
class I {
+
string this_program = "foo";
+
}
+
class A {
+
class B {
+
inherit I;
+
mixed f (int this_program) {
+
return ({A::this_program, B::this_program, this_program});
+
}
+
}
+
}
+
int a() {
+
return equal (A()->B()->f (1), ({A, "foo", 1}));
+
}
+
]])
+
+
test_program([[
+
string this_program = "foo";
+
class A {
+
class B {
+
mixed f() {
+
return ({A::this_program, B::this_program, this_program});
+
}
+
}
+
}
+
int a() {
+
return equal (A()->B()->f(), ({A, A.B, "foo"}));
+
}
+
]])
+
+
test_compile_error_any([[
+
class A {}
+
class B {
+
inherit A:C;
+
mixed f() {return A::this_program;}
+
}
+
]])
+
+
test_compile_error_any([[
+
#pike 7.6
+
class A {}
+
class B {
+
inherit A:C;
+
mixed f() {return C::this_program;}
+
}
+
]])
+
+
test_any([[
+
class A {};
+
class B {
+
inherit A:C;
+
mixed f() {return C::this_program;}
+
};
+
return B()->f() == A;
+
]], 1)
+
+
test_any([[
+
class A {
+
class Nested {
+
constant nested = 1;
+
}
+
};
+
class B {
+
inherit A;
+
class Nested {
+
inherit ::this_program;
+
constant other = 2;
+
}
+
};
+
object n = B()->Nested();
+
return n->nested + n->other;
+
]], 3)
+
dnl test_compile_error(0()) test_compile_error(1()) test_compile_error(""()) test_compile_error(([])()) test_compile_error(([])()) test_any([[ class X { int y; class Z { void destroy() { y++; } } }; X x=X(); destruct(x->Z()); return x->y;]],1) test_eval_error([[ class Z { int destroy() { return 1/y; } }(); ]])
-
test_any([[ class X { int y; class Z {
static
void destroy() { y++; } } }; X x=X(); destruct(x->Z()); return x->y;]],1)
-
test_any([[ class X { int y; class Z {
static
void create() { y++; } } }; X x=X(); destruct(x->Z()); return x->y;]],1)
+
test_any([[ class X { int y; class Z {
protected
void destroy() { y++; } } }; X x=X(); destruct(x->Z()); return x->y;]],1)
+
test_any([[ class X { int y; class Z {
protected
void create() { y++; } } }; X x=X(); destruct(x->Z()); return x->y;]],1)
cond([[all_constants()->_debug]], [[ test_do(_debug(_debug(0))) ]])
-
test_do(_static_modules
(
))
+
test_do(
indices(
_static_modules))
test_compile_any([[import Stdio; class x { string y() { read_file("foo"); } }]])
-
+
dnl ----------------------------------------------------------------
+
dnl backtrace/linenumber tests
+
dnl ----------------------------------------------------------------
+
+
test_any([[
+
program p=compile_string(
+
"int foo()\n"
+
"{\n"
+
" error(\"test error\\n\"); // line 3\n"
+
" return 17;\n"
+
"}","test");
+
mixed err=catch { p()->foo(); };
+
if (err[1][-1][1]!=3)
+
{
+
werror("backtrace is:\n"+master()->describe_backtrace(err));
+
}
+
return err[1][-1][1];
+
]],3);
+
+
// Bug 2660
+
test_any([[
+
int foo(mixed a, mixed ... b) {
+
return sizeof(backtrace()[-1]) - (3 + 1 + sizeof(b));
+
};
+
return foo(1,2,3,4)|foo(1);
+
]], 0)
+
+
define(test_backtrace_line_charset, [[
+
test_any([[
+
program p=compile_string(
+
Charset.encoder("]]$1[[")->feed(
+
"#charset ]]$1[[\n"
+
"int foo()\n"
+
"{\n"
+
" error(\"test error\\n\"); // line 3\n"
+
" return 17;\n"
+
"}")->drain(),"test");
+
mixed err=catch { p()->foo(); };
+
if (err[1][0][1]!=3)
+
{
+
werror("backtrace is:\n"+master()->describe_backtrace(err));
+
}
+
return err[1][0][1];
+
]],3);
+
]])
+
dnl test_backtrace_line_charset(utf-7)
+
+
test_program([[
+
class X
+
{
+
protected void create (int i)
+
{
+
if (i)
+
error ("foo\n"); // Line 7
+
}
+
}
+
+
int f()
+
{
+
X (0);
+
X (1); // Line 14
+
}
+
+
int a()
+
{
+
array bt = catch (f())[1];
+
int ok = 0;
+
foreach (reverse (bt), object ent)
+
switch (functionp (ent[2]) && function_name (ent[2])) {
+
case "create": if (ent[1] == 7) ok++; break;
+
case "f": if (ent[1] == 14) ok++; break;
+
}
+
return ok == 2;
+
}
+
]])
+
+
test_program([[// [bug 3060]
+
void x (mixed val)
+
{
+
}
+
+
class X
+
{
+
void create() {error ("foo\n");} // Line 8
+
}
+
+
object rx = class {}();
+
+
int y()
+
{
+
x (rx->x);
+
rx = X(); // Line 16
+
}
+
+
int a()
+
{
+
mixed bt = catch (y())[1];
+
int ok = 0;
+
foreach (reverse (bt), object ent)
+
switch (functionp (ent[2]) && function_name (ent[2])) {
+
case "create": if (ent[1] == 8) ok++; break;
+
case "y": if (ent[1] == 16) ok++; break;
+
}
+
return ok == 2;
+
}
+
]])
+
+
test_any([[
+
// Test a lot of code without a relative pc update in it. There must
+
// not be any labels in it since the pc counting is reset then.
+
int a = 1, b = 1, c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c; c=a+b,a=b,b=c;
+
return __LINE__ == backtrace()[-1][1];
+
]], 1)
+
+
dnl Note: This line number error tend to go away with more debug.
+
test_program([[
+
int x = 0;
+
int y = [int] backtrace()[-1][1];
+
int a() {return y == 3;}
+
]])
+
+
dnl This test used to get the last line of the else block
+
test_any([[
+
int expected_line;
+
void foo(object o)
+
{
+
expected_line = __LINE__ + 1;
+
if (o->a && b) {
+
o->a = o->b;
+
} else if (o->b) {
+
o->b = o->a;
+
}
+
};
+
mixed err = catch { foo(UNDEFINED); };
+
return err[1][-1][1] - expected_line;
+
]], 0)
+
+
dnl ----------------------------------------------------------------
+
dnl scopes and stuff
+
dnl ----------------------------------------------------------------
+
dnl dnl Undocumented but important behaviour... dnl test_eq([[Stdio._stdin]],[[Stdio.stdin->_fd]])
-
+
test_program([[
+
class A {
+
string f() {return "A";}
+
}
+
class B {
+
string f() {return "B";}
+
}
+
class C {
+
inherit B;
+
}
+
class D {
+
inherit A;
+
inherit C;
+
string g() {return f();}
+
}
+
int a() {
+
return D()->g() == "B";
+
}
+
]])
+
test_program([[
+
class A {
+
string f() {return "A";}
+
}
+
class B {
+
string f() {return "B";}
+
}
+
class C {
+
inherit B;
+
}
+
class D {
+
inherit C;
+
inherit A;
+
string g() {return f();}
+
}
+
int a() {
+
return D()->g() == "A";
+
}
+
]])
+
test_program([[
+
class A {
+
string f() {return "A";}
+
}
+
class B {
+
string f() {return "B";}
+
}
+
class C {
+
inherit B;
+
}
+
class D {
+
string f() {return "D";}
+
inherit A;
+
inherit C;
+
string g() {return f();}
+
}
+
int a() {
+
return D()->g() == "D";
+
}
+
]])
+
test_compile_any([[ class Bar { int f() {return 17;} class Foo { int g() {return f();} } inherit Foo;
pike.git/src/testsuite.in:340:
} class Gnu { inherit Bar; inherit Foo; } ]])
+
dnl Bug 2571
+
test_any([[
+
int var;
+
void x() {var++;};
+
lambda () {x();}();
+
return var;
+
]], 1);
+
+
test_do([[
+
// Save our constants for future use...
+
add_constant("__saved_constants__", ([]) + all_constants());
+
]])
+
+
test_any([[
+
Stdio.write_file("testsuite_test.pmod",
+
#"
+
// this crashes Pike /Mirar 2001-05-19
+
// I haven't been able to minimize it futher,
+
// and it needs to be in a separate module.
+
+
mapping es=0;
+
+
string efoo(string e)
+
{
+
if (!es)
+
{
+
mapping res=([]);
+
+
string l;
+
+
if (sscanf(l,\"%s%s\",string ext,string type)==4 &&
+
ext!=\"\" && ext[0]!=\"#\") // note the type error
+
res[ext]=type;
+
+
es=res;
+
}
+
}
+
");
+
+
// Compilation handler that hides compilation errors.
+
class handler
+
{
+
void compile_error(string file, int line, string err)
+
{
+
// log_msg("file: %O, line: %O, err: %O\n", file, line, err);
+
}
+
};
+
+
// turn this on when the bug is found
+
// master()->set_inhibit_compile_errors(lambda(){});
+
+
//_optimizer_debug(2);
+
//_assembler_debug(20);
+
+
object orig_master = master();
+
replace_master(object_program(orig_master)());
+
catch {
+
compile_string("import \".\";\n"
+
"int foo() { testsuite_test.efoo; }\n",
+
"testsuite_test", handler());
+
};
+
replace_master(orig_master);
+
return 0;
+
]],0);
+
+
test_any([[
+
// infokom:350113
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
mkdir("testsuite_test_dir.pmod");
+
Stdio.write_file("testsuite_test_dir.pmod/module.pmod",
+
#"
+
.A a() {return 0;}
+
");
+
Stdio.write_file("testsuite_test_dir.pmod/A.pike",
+
#"
+
void create (.X x) {.y();}
+
");
+
+
// Compilation handler that hides compilation errors.
+
class handler
+
{
+
void handle_error(array(mixed)|object trace) { }
+
void compile_error(string file, int line, string err) { }
+
void compile_warning(string file, int line, string err) { }
+
};
+
+
object orig_master = master();
+
replace_master(object_program(orig_master)());
+
master()->set_inhibit_compile_errors(handler());
+
mixed err = catch {
+
compile_string("import \".\"; "
+
"int foo() { testsuite_test_dir.a(); }",
+
"test",handler());
+
};
+
master()->set_inhibit_compile_errors(0);
+
replace_master(orig_master);
+
if(err)
+
{
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
return 0;
+
}
+
+
return 1;
+
]],0);
+
+
test_do([[
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
mkdir("testsuite_test_dir.pmod");
+
+
Stdio.write_file("testsuite_test_dir.pmod/module.pmod",
+
#"
+
.A a();
+
class X {}
+
");
+
Stdio.write_file("testsuite_test_dir.pmod/A.pike",
+
#"
+
.X f() {return 0;}
+
");
+
+
object orig_master = master();
+
replace_master(object_program(orig_master)());
+
mixed err = catch {
+
compile_string("import \".\"; "
+
"int foo() { testsuite_test_dir.A(); }",
+
"test");
+
};
+
replace_master(orig_master);
+
if (err) throw (err);
+
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
]]);
+
+
test_do([[
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/module.pmod", #"\
+
.B b();
+
class X {}");
+
Stdio.write_file ("testsuite_test_dir.pmod/A.pike", #"\
+
int f() {return 0;}");
+
Stdio.write_file ("testsuite_test_dir.pmod/B.pike", #"\
+
inherit .A;
+
.X g() {return f() && .X();}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
mixed err = catch {
+
compile_string ("import \".\";\n"
+
"int foo() { testsuite_test_dir.B(); }",
+
"test");
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
]]);
+
+
test_do([[
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/module.pmod", #"\
+
.B.B b();
+
class X {}");
+
Stdio.write_file ("testsuite_test_dir.pmod/A.pike", #"\
+
int f() {return 0;}");
+
Stdio.write_file ("testsuite_test_dir.pmod/B.pmod", #"\
+
class B {
+
inherit .A;
+
.X g() {return f() && .X();}
+
}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
mixed err = catch {
+
compile_string ("import \".\";\n"
+
"int foo() { testsuite_test_dir.B.B(); }",
+
"test");
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
]]);
+
+
test_do([[
+
// Problem: The expression .B.c in module.pmod is resolved during
+
// compilation pass 1 of B.pike, but it's only declared then and
+
// doesn't yet have any value.
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/module.pmod", #"\
+
mixed x = .B.c;
+
class A {}");
+
Stdio.write_file ("testsuite_test_dir.pmod/B.pike", #"\
+
constant c = .A();"); // Should give a "not constant" compile error.
+
+
// Compilation handler that hides compilation errors.
+
class handler
+
{
+
void handle_error(array(mixed)|object trace) { }
+
void compile_error(string file, int line, string err) { }
+
void compile_warning(string file, int line, string err) { }
+
};
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
mixed err = catch {
+
compile_string (#"\
+
mixed foo() {return .testsuite_test_dir.A;}",
+
"test", handler());
+
};
+
replace_master (orig_master);
+
if (!err) error ("Expected compile error.\n");
+
if (!objectp (err) || !err->is_compilation_error) throw (err);
+
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
]]);
+
+
test_any_equal([[
+
// Problem: module.pmod is in pass 1 when it tries to resolve the
+
// .B.c constant and is therefore temporarily interned as a
+
// placeholder object. The (<>) in B.pike is equivalent to
+
// aggregate_multiset, which due to the import is looked up in the
+
// placeholder object and therefore resolved as a nonconstant
+
// placeholder object.
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/module.pmod", #"\
+
mixed x = .B.C;
+
mixed foo() {return x->c;}");
+
Stdio.write_file ("testsuite_test_dir.pmod/B.pike", #"\
+
import \".\";
+
class C {
+
constant c = (<>);
+
}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
mixed res;
+
mixed err = catch {
+
res = compile_string (#"\
+
mixed foo() {return .testsuite_test_dir.foo();}",
+
"test")()->foo();
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
return res;
+
]], (<>));
+
+
test_do([[
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/A.pmod", #"\
+
string pof() {return testsuite_test_dir.A.bingo();}
+
string bingo () {return \"17\";}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
master()->add_module_path (getcwd());
+
mixed err = catch {
+
compile_string (#"\
+
string foo() {
+
return testsuite_test_dir.A.pof();
+
}", "test");
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
]])
+
+
test_do([[
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/module.pmod", #"\
+
.Foo.C x;");
+
Stdio.write_file ("testsuite_test_dir.pmod/Foo.pmod", #"\
+
import \".\";
+
class C
+
{
+
int f (array x)
+
{
+
return lambda() {
+
// 'sizeof' below will be a placeholder object in
+
// pass 1. That shouldn't cause a type error.
+
int i = sizeof (x);
+
return i;
+
}();
+
}
+
}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
mixed err = catch {
+
compile_string (#"\
+
mixed foo() {return .testsuite_test_dir.x;}",
+
"test");
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
Stdio.recursive_rm("testsuite_test_dir.pmod");
+
]]);
+
+
test_do([[
+
Stdio.write_file ("testsuite_test_a.pmod", #"
+
class a {}
+
testsuite_test_b.b2 foo() {return testsuite_test_b.b2 (17);}");
+
+
Stdio.recursive_rm ("testsuite_test_b.pmod");
+
mkdir ("testsuite_test_b.pmod");
+
Stdio.write_file ("testsuite_test_b.pmod/b1.pike", #"
+
protected void create() {}");
+
Stdio.write_file ("testsuite_test_b.pmod/b2.pike", #"
+
inherit testsuite_test_b.b1;
+
constant a = testsuite_test_a.a;
+
protected void create (int i) {}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
master()->add_module_path (getcwd());
+
mixed err = catch {
+
compile_string ("inherit testsuite_test_b.b2;");
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
+
Stdio.recursive_rm ("testsuite_test_a.pmod");
+
Stdio.recursive_rm ("testsuite_test_b.pmod");
+
]])
+
+
cond(0,[[
+
test_do([[
+
// This is a case of cyclic references I think should work, but
+
// afaict it's not possible without changing the resolve methods
+
// thoroughly. /mast
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
mkdir ("testsuite_test_dir.pmod");
+
+
Stdio.write_file ("testsuite_test_dir.pmod/A.pmod", #"\
+
.B.B b() {}
+
class A {}
+
class Ab {int ai() {return 4711;}}
+
class Ad {inherit .B.Bb; int ai() {return bi() + 1;}}");
+
Stdio.write_file ("testsuite_test_dir.pmod/B.pmod", #"\
+
.A.A a() {}
+
class B {}
+
class Bb {int bi() {return 17;}}
+
class Bd {inherit .A.Ab; int bi() {return ai() - 1;}}");
+
+
object orig_master = master();
+
replace_master (object_program (orig_master)());
+
mixed err = catch {
+
compile_string (#"\
+
import \".\";
+
int foo() {
+
testsuite_test_dir.A.Ad();
+
testsuite_test_dir.B.Bd();
+
}", "test");
+
};
+
replace_master (orig_master);
+
if (err) throw (err);
+
+
Stdio.recursive_rm ("testsuite_test_dir.pmod");
+
]]);
+
]]);
+
+
test_do([[
+
// Restore constants that were zapped by the various masters used above.
+
foreach(__saved_constants__; string const; mixed val) {
+
add_constant(const, val);
+
}
+
add_constant("__saved_constants__");
+
]])
+
test_compile_any([[int log() { return 17; } class Greta { int hanna() { return log(); } }]]) test_compile_any([[int kajsa(int a,int b) { return 17; } class Jenny { int kajsa() { return 17; } class Greta { int hanna() { return kajsa(); } } }]]) test_any([[add_constant("kajsa",lambda(int a,int b) { return 17; }); return compile_string("int kajsa() { return 17; } class Greta { int hanna() { return kajsa(); } }")()->kajsa()]],17)
-
+
test_do(add_constant("kajsa"))
test_compile([[Stdio.File foo=Stdio.File();]]) test_compile([[ string|multiset(string) foo; array(string) gazonk; array(string) bar = indices(foo)-gazonk; ]]) test_compile([[class { Stdio.File foo=Stdio.File(); }]]) test_compile_any([[void foo(Stdio.FILE f) {}]]) test_compile_any([[void foo(array(Stdio.FILE) f) {}]]) test_compile_any([[void foo(array(Stdio.FILE) f) {}]])
pike.git/src/testsuite.in:372:
inherit a; class c { int d (string x, string y) { return x==y; } } } ]]) test_compile([[Stdio.File foo=Stdio.FILE();]])
+
dnl variant
+
test_any([[
+
class A {
+
variant string a() { return "A:a()"; }
+
variant string a(string s) { return sprintf("A:a(%q)", s); }
+
};
+
class B {
+
inherit A;
+
variant string a(int i) { return local::a() + ":" + local::a((string)i) + ":" + ::a((string)i); }
+
variant string a(string s) { return sprintf("B:a(%q)", s); }
+
};
+
class C {
+
inherit B;
+
string a() { return "C:a()"; }
+
variant string a(string s) { return ::a(sizeof(s)) + "|" + ::a(s) + "|" + a(); }
+
};
+
return C()->a("foo");
+
]], "A:a():B:a(\"3\"):A:a(\"3\")|B:a(\"foo\")|C:a()")
+
+
test_any([[
+
// Test symbol lookup for inherit in multi-pass.
+
// LysLysKOM 16472935
+
// An old pike will attempt to lookup X in the innermost X
+
// during the second pass and thus fail with a compilation error.
+
class X {
+
constant foo = "outer";
+
class X {
+
constant foo = "middle";
+
class X {
+
constant foo = "inner";
+
}
+
}
+
};
+
class Y {
+
inherit X.X;
+
};
+
return Y()->foo;
+
]], "middle")
+
+
test_any([[
+
// Test external symbol lookup in las.c:eval_low_safe_and_stupid().
+
// LysLysKOM 18285732
+
// An old pike will fail with the fatal
+
// "Identifier out of range, loc->parent_identifer=-1!"
+
// during __INIT().
+
+
class A
+
{
+
static string foo = "bar";
+
};
+
+
string to_compile=#"
+
constant fum = \"gazonk\";
+
+
class B()
+
{
+
inherit A;
+
int fi()
+
{
+
return fum?1:0;
+
}
+
}
+
";
+
+
add_constant("A",A);
+
compile_string(to_compile);
+
add_constant("A");
+
return 0;
+
]], 0)
+
+
test_any([[
+
// Test eval_low() on seemingly constant expressions, that
+
// attempt to access variables in the fake object. [Bug 5273]
+
// An old pike (with RTL debug) will fail with the fatal
+
// "Invalid type 33896 in svalue at 891e510."
+
// during compilation.
+
+
class Test
+
{
+
protected object foo;
+
+
mixed `-> (mixed what)
+
{
+
return foo;
+
}
+
+
int bar ()
+
{
+
return (this_object()->gazonk == "foo") ? 1 : 0;
+
}
+
};
+
+
return Test()->bar;
+
]], 0)
+
test_any([[string gurk="bozo"; string b(int x) { return (x?b(x-1)+gurk:""); }; return b(5)]],[["bozo"*5]]) dnl this should really work... dnl test_compile_any([[void foo(int,string,...);]])
-
test_eval_error([[class X { int create() { create(); } }();]])
+
dnl This
test
doesn't run out of stack anymore, freaky
+
dnl test
_eval_error([[class X { int create() { create(); } }();]])
test_compile_error([[ int float; ]]) test_compile_error([[ int array; ]]) test_compile_error([[ int function; ]]) test_compile_error([[ int int; ]]) test_compile_error([[ int mapping; ]]) test_compile_error([[ int multiset; ]]) test_compile_error([[ int object; ]]) test_compile_error([[ int string; ]]) test_compile_error([[ int void; ]]) test_compile_error([[ int inline; ]])
pike.git/src/testsuite.in:420:
test_compile_error([[ int continue; ]]) test_compile_error([[ int default; ]]) test_compile_error([[ int for; ]]) test_compile_error([[ int foreach; ]]) test_compile_error([[ int if; ]]) test_compile_error([[ int float = 0; ]]) test_eval_error([[ return 0.0[0]; ]]) test_eval_error([[ return 0[0]; ]]) test_compile_error([[constant x=class {}(); ]])
-
test_compile_error_
low
([[
+
test_compile_error_
any
([[
mixed foo; mapping query_variables() { return ([]); }; mixed foo(mixed bar) { return 1/foo; } ]])
-
test_compile_error_
low
([[
+
test_compile_error_
any
([[
class A {int wrong = "bogus"; void create() {}} class B {inherit A;} ]])
-
+
test_any([[
+
// Test dynamic module indexing.
+
object protocols = Protocols;
+
return protocols.HTTP.get_url_data;
+
]], [[ Protocols.HTTP.get_url_data ]])
test_compile([[float x=(gauge { return; },1.0);]]) cond( [[ master()->resolv("Gmp")->mpz ]], [[ test_compile_error([[object x = Gmp.mpz(17); constant y = x;]]) ]]) test_any([[object(Stdio.File) f; f=Stdio.File(); return 1]],1)
-
test_compile([[float t=gauge { string foo; };]])
+
test_compile([[float t=gauge { string foo;
foo;
};]])
test_compile_any([[class { object(Stdio.FILE) f; void create() { f=Stdio.FILE(); }}]]) test_eq([[compile_string("#define A(X) (X)\nint x() { return A \n\t(1); }")()->x()]],1) test_any([[class G { mapping t=([]); class tO { void init(string name) { t[name]=this_object(); }} class W { inherit tO; void create() { init("foo"); }} }; object x=G(); x->W(); return objectp(x->t->foo)]],1) test_program([[class foo { program x() { return class {}; }}; class bar { inherit foo; program x() { return class {}; }} int a() { return foo()->x != bar()->x(); }]]) test_any([[ class A { constant gurka = 2; int foo = gurka; }; class B {
-
static
inherit A;
+
protected
inherit A;
constant gurka = 1; int bar; void create() { bar = foo; } }; return B()->bar; ]], 1) test_any([[ class A { constant gurka = 2; int foo = gurka; }; class B {
-
static
inherit A;
+
protected
inherit A;
constant gurka = 1; int bar; int baz = 3; void create() { bar = baz + foo; } }; return B()->bar; ]], 4) test_any([[ class A { constant gurka = 1; int foo = gurka; }; class B { constant banan = 2; int foo = banan; }; class C {
-
static
inherit A;
-
static
inherit B;
+
protected
inherit A;
+
protected
inherit B;
constant gurka = 3; constant banan = 4; int bar; int baz = 5; void create() { bar = baz + A::foo + B::foo; } }; return C()->bar; ]], 12)
pike.git/src/testsuite.in:517:
inherit B; int c = 4; }; class D { inherit C; }; object d = D(); return d->a + d->b + d->c; ]], 7)
-
test_compile_error_
low
([[
+
test_compile_error_
any
([[
class AScope { int gurka; class A { int func() { return gurka; } } } class CScope { string hohum; class C { inherit AScope.A; } } ]])
-
+
test_program([[
+
class A
+
{
+
constant x = 1.0;
+
}
+
+
class B
+
{
+
inherit A;
+
class C
+
{
+
constant y = x+2.0;
+
}
+
}
+
+
mixed a()
+
{
+
return 3.0 == B()->C()->y;
+
}
+
]])
+
+
test_program_eq([[
+
constant x = X;
+
class X {constant c = "right";}
+
+
constant y = Y;
+
class Y {constant c = "wrong";}
+
+
string a()
+
{
+
return ::`[]("x")->c;
+
}
+
]], "right")
+
+
test_program_eq([[
+
class A {
+
string x = "x";
+
class B {
+
string f() {return x;}
+
}
+
}
+
class C {
+
inherit A;
+
constant D = A::B;
+
}
+
string a() {
+
return C()->D()->f();
+
}
+
]], "x")
+
+
test_program_eq([[
+
class A {
+
string x = "x";
+
class B {
+
string f() {return x;}
+
}
+
}
+
class C {
+
inherit A;
+
string x = "y";
+
constant D = A::B;
+
}
+
string a() {
+
return C()->D()->f();
+
}
+
]], "y")
+
+
test_program_eq([[
+
class A {
+
local string x = "x";
+
class B {
+
string f() {return x;}
+
}
+
}
+
class C {
+
inherit A;
+
string x = "y";
+
constant D = A::B;
+
}
+
string a() {
+
return C()->D()->f();
+
}
+
]], "x")
+
+
test_program_eq([[
+
class A {
+
local string x = "x";
+
class B {
+
void set (string new) {x = new;}
+
string f() {return x;}
+
}
+
}
+
class C {
+
inherit A;
+
string x = "y";
+
constant D = A::B;
+
}
+
string a() {
+
C c = C();
+
C.D d = c->D();
+
d->set ("bar");
+
c->x = "foo";
+
return d->f();
+
}
+
]], "bar")
+
+
dnl Come back when we decide that this should be possible dnl test_do([[ dnl class A { dnl constant i = 5; dnl }; dnl class B { dnl inherit A; dnl int i = 17; dnl }; dnl B();
pike.git/src/testsuite.in:615:
]],[[ ({D, ({C, ({B, ({A})})})}) ]]) test_any([[ class A {}; class B { inherit A; }; class C { inherit B; }; class D { inherit C; }; return sizeof( Program.all_inherits(D) - ({A,B,C}) ); ]],0)
+
test_any_equal([[
+
class A {
+
class C {}
+
};
+
class B {
+
class C {}
+
};
+
return ({A <= B, A >= B});
+
]], ({1, 1}))
-
test_
program
([[
+
test_
tests
([[
int errors; int tests;
-
#define indent(X) (X)
-
+
int maxdepth;
-
int quiet;
+
-
+
class Codec {
+
string nameof(mixed x)
+
{
+
return ([ trace:"efun:trace", write:"efun:write", `+:"efun:`+" ])[x];
+
}
+
+
function functionof(string x)
+
{
+
return ([ "efun:trace":trace, "efun:write":write, "efun:`+":`+ ])[x] ||
+
0;
+
}
+
+
mixed encode_object (object o) {}
+
void decode_object (object o, mixed d) {}
+
}
+
void low_generate(int depth, array(string) code, string acc, string ans, int cnt) { mixed tmp; if(--depth<0) { string res="None"; tests++; if(!(tests & 63)) { __signal_watchdog();
-
if
(
!quiet)
-
werror("\r
%d:
%d
",maxdepth,tests);
+
log_status
(
"Testing
vtables
and
scope
access:
%d:%d",maxdepth,tests);
} string test=code*"\n"+"\n" "mixed Q() { return "+acc+"();}\n"
-
"int main() { trace(9);
werror
(\"%O\\n\","+acc+"()); }\n"
+
"int main() { trace(9);
write
(\"%O\\n\","+acc+"()); }\n"
;
-
mixed tmp;
+
mixed tmp
, x
;
mixed err=catch { tmp=compile_string(test)(); res=tmp->Q(); if(res != ans) throw("Test failed");
-
+
res = "None";
+
tmp = decode_value(encode_value(tmp, Codec()), Codec());
+
res=tmp->Q();
+
if(res != ans)
+
throw("Test failed for encode/decode.");
+
x=Program.inherit_list(object_program(tmp));
};
-
mixed x=Program.inherit_list(object_program(tmp));
+
if(err) { errors++;
-
werror
("
\nTest
failed:\n----------------------------------\n%s\n---------------------------------
\nexpected
answer: %
O\nAnswer
received: %O\n",test,ans,res);
-
if(err!
=
"Test failed")
+
log_msg
("
Test
failed:\n
"
+
"
----------------------------------\n
"
+
"
%s\n
"
+
"
---------------------------------
\n"
+
"expected
answer: %
O\n"
+
"Answer
received: %O\n",test,ans,res);
+
if(
!stringp(
err
) ||
!
has_prefix(err,
"Test failed")
)
{ string tmp=master()->describe_backtrace(err); array s=tmp/"\n"; s=s[..20];
-
werror
("%s\n",s*"\n");
+
log_msg
("%s\n",s*"\n");
}
-
+
if (res == "None") {
+
// Probable decode error; try to get some debug.
+
catch {
+
log_msg("Encoding...\n");
+
string encoded = ((function)encode_value)(tmp, Codec(), 6);
+
log_msg("Decoding...\n");
+
tmp = ((function)decode_value)(encoded, Codec(), 6);
+
log_msg("Strange... No error thrown...\n");
+
};
+
}
return; } }else{ low_generate(depth, code+ ({sprintf("string F%d(){ return %s()+\"F%d\"; }",cnt,acc,cnt)}), sprintf("F%d",cnt), sprintf("%sF%d",ans,cnt), cnt+1); for(int e=0;e<sizeof(code);e++) { low_generate(depth, code[..e-1]+({
-
sprintf("class C%d {\n%s\n};",cnt,
indent(
code[e..]*"\n")
)
+
sprintf("class C%d {\n%s\n};",cnt,code[e..]*"\n")
}), sprintf("C%d()->%s",cnt,acc), ans,cnt+1); } if(sscanf(acc,"%s()->%s",string classname,string rest)) { low_generate(depth, code+({sprintf("inherit %s;",classname) }), rest, ans, cnt); } } }
-
int a()
+
array(
int
)
a()
{
-
werror("Testing vtables and scope access.\n");
-
-
string testargs=getenv()->TESTARGS;
-
if(testargs &&
-
(has_value(testargs/" ", "-q") ||
-
has_value(testargs/" ", "-quiet") ) )
-
quiet=1;
-
return 1;
-
+
int total_tests; for(maxdepth=1;maxdepth<9 && !errors;maxdepth++) { low_generate(maxdepth, ({ "string X(){return \"X\";}" }), "X", "X",0);
-
if(quiet)
-
werror("Maxdepth %d\n",maxdepth);
-
else
-
werror("\r%d: %d\n",maxdepth,tests);
+
total_tests+=tests; tests=0; }
-
if(errors)
werror
(
"%d/%d
tests failed.\n",errors,
total_tests
);
-
return !
errors;
+
return
(
{
total_
tests
-
errors,
errors
})
;
} ]])
-
+
+
test_true([[Program.implements( class { int x; string y; void foo(int x) {} }, class { void foo(mixed z) {} int x; })]]) test_false([[Program.implements( class { int x; string y; void foo(int x) {} }, class { void foo(mixed z) {} string x; })]]) test_eq([[object_program(master())]],[[(program)"/master"]]) test_compile([[object("master") m = master();]]) test_any([[if(int x=1,y=2) return x;]],1) test_any([[int x; x++; if(x) return x; return -1;]],1) test_any([[int x; if(x) return x; return -1;]],-1) test_any([[int x,y; if(x==y || x==1) return 2; return 0;]],2); test_any([[int x,y; if(x==y && x==0) return 2; return 0;]],2); test_any([[int x,y=1; if(x==y || x==1) return 2; return 0;]],0); test_any([[int x,y=1; if(x==y && x==0) return 2; return 0;]],0);
-
+
test_any([[int x = 1; x = x + (x = 0, 1); return x;]], 2);
-
test_eq([[ "\007" & "\023"]],"\003")
-
test_eq([[ "\007" | "\023"]],"\027")
-
test_eq([[ "\007" ^ "\023"]],"\024")
+
-
+
test_any([[ return class { int i=17; }()["i"] ]],17) test_any([[ return class { int i=17; mixed `[](string foo) { return i; }}()[""] ]],17) test_any([[ return class { int i=17; mixed `[](string foo) { return ::`[]("i"); }}()[""]
pike.git/src/testsuite.in:851:
return C()->foo(); ]], 1) test_compile_any([[ class X { void hej() {} } class Y { inherit X:banan; void hopp() { banan::hej(); } } ]]) test_compile_any([[
-
class X {
static
void hej() {} }
+
class X {
protected
void hej() {} }
class Y { inherit X:banan; void hopp() { ::hej(); } } ]]) test_compile_any([[
-
class X {
static
void hej() {} }
+
class X {
protected
void hej() {} }
class Y { inherit X; void hopp() { X::hej(); } } ]]) test_compile_any([[
-
class X {
static
void hej() {} }
+
class X {
protected
void hej() {} }
class Y { public inherit X:banan; void hopp() { banan::hej(); } } ]]) test_compile_any([[
-
class X {
static
void hej() {} }
+
class X {
protected
void hej() {} }
class Y { inherit X:banan; void hopp() { banan::hej(); } } ]])
-
+
// Testing hidden identifier lookup with ::
+
+
test_program([[
+
class X {
+
int i = 17;
+
class Y {
+
constant i = 18;
+
mixed f (int i) {return ({i, Y::i, X::i});}
+
}
+
}
+
int a() {return equal (X()->Y()->f (19), ({19, 18, 17}));}
+
]])
+
+
test_compile_error_any([[
+
#pike 7.2
+
class X {
+
int i = 17;
+
class Y {
+
constant i = 18;
+
mixed f (int i) {return ({i, Y::i, X::i});}
+
}
+
}
+
]])
+
+
test_compile_error_any([[
+
class X {
+
constant i = 18;
+
mixed f() {return Y::i;}
+
}
+
]])
+
+
test_program([[
+
class A {
+
int i = 17;
+
}
+
class X {
+
inherit A: Y;
+
class Y {
+
constant i = 18;
+
mixed f() {return Y::i;}
+
}
+
}
+
int a() {return X()->Y()->f() == 18;}
+
]])
+
+
test_program([[
+
#pike 7.2
+
class A {
+
int i = 17;
+
}
+
class X {
+
inherit A: Y;
+
class Y {
+
constant i = 18;
+
mixed f() {return Y::i;}
+
}
+
}
+
int a() {return X()->Y()->f() == 17;}
+
]])
+
+
test_program([[
+
class A {
+
string s = "A";
+
}
+
class B {
+
constant s = "B";
+
}
+
class X {
+
constant s = "X";
+
inherit A;
+
class Y {
+
inherit B: A;
+
constant s = "Y";
+
mixed f() {return X::s + X::A::s + Y::s + Y::A::s + A::s;}
+
}
+
}
+
+
int a() {
+
// Ignore the warning we get from overloading a constant with a string.
+
master()->get_inhibit_compile_errors()->warning=0;
+
return X()->Y()->f() == "XAYBB";
+
}
+
]])
+
+
test_program([[
+
class A {
+
string s = "A";
+
}
+
inherit A;
+
class X {
+
constant s = "X";
+
mixed f (string s) {return s + X::s + A::s;}
+
}
+
int a() {return X()->f("L") == "LXA";}
+
]])
+
+
test_program([[
+
class A {
+
string f() {return "A";}
+
string g() {return A::f();}
+
}
+
class B {
+
inherit A;
+
string f() {return "B";}
+
}
+
int a() {return B()->g() == "B";}
+
]])
+
+
test_program([[
+
class A {
+
string g() {return A::f();}
+
string f() {return "A";}
+
}
+
class B {
+
inherit A;
+
string f() {return "B";}
+
}
+
int a() {return B()->g() == "B";}
+
]])
+
+
test_program([[
+
class A {
+
string f() {return "A";}
+
string g() {return A::f();}
+
}
+
class B {
+
string f() {return "B";}
+
inherit A;
+
}
+
int a() {return B()->g() == "B";}
+
]])
+
+
test_program([[
+
class A {
+
string f() {return "A";}
+
class I {
+
string g() {return A::f();}
+
}
+
}
+
class B {
+
inherit A;
+
string f() {return "B";}
+
}
+
int a() {return B()->I()->g() == "B";}
+
]])
+
+
// Testing 'global::'
+
+
test_equal([[
+
compile_string (#"
+
string p = \"g\";
+
mixed f (string p) {return ({global::p, p});}")()->f ("l");
+
]], ({"g", "l"}))
+
+
test_eval_error([[
+
compile_string (#"
+
string pp = \"g\";
+
mixed f (string p) {return global::p;}");
+
]])
+
+
test_eval_error([[
+
compile_string (#"
+
#pike 7.2
+
string p = \"g\";
+
mixed f (string p) {return global::p;}");
+
]])
+
+
test_equal([[
+
compile_string (#"
+
int x = 23;
+
class A {
+
constant x = 24;
+
}
+
inherit A;
+
class X {
+
int x = 32;
+
mixed f (int x) {return ({global::x, global::A::x, X::x, x});}
+
}")()->X()->f (33);
+
]], ({23, 24, 32, 33}))
+
+
// Testing 'global.'
+
+
test_compile([[
+
mixed a() {return global.Parser.HTML;}; a;
+
]], 0);
+
+
test_compile_error([[
+
#pike 7.2
+
mixed a() {return global.Parser.HTML;}
+
]], 0);
+
+
test_any([[
+
if (!programp (Parser.HTML)) error ("This test uses the existence of Parser.HTML.\n");
+
return compile_string (#"
+
class Parser {constant HTML = 1;}
+
mixed foo() {return programp (Parser.HTML);}")()->foo();
+
]], 0);
+
+
test_any([[
+
if (!programp (Parser.HTML)) error ("This test uses the existence of Parser.HTML.\n");
+
return compile_string (#"
+
mixed foo() {return programp (Parser.HTML);}
+
class Parser {constant HTML = 1;}")()->foo();
+
]], 0);
+
+
test_any([[
+
if (!programp (Parser.HTML)) error ("This test uses the existence of Parser.HTML.\n");
+
return compile_string (#"
+
class Parser {constant HTML = 1;}
+
mixed foo() {return programp (global.Parser.HTML);}")()->foo();
+
]], 1);
+
+
test_any([[
+
if (!programp (Parser.HTML)) error ("This test uses the existence of Parser.HTML.\n");
+
return compile_string (#"
+
mixed foo() {return programp (global.Parser.HTML);}
+
class Parser {constant HTML = 1;}")()->foo();
+
]], 1);
+
// testing virtual overloading test_any([[ class fnord { int ber() { return 1; } int goo() { return ber(); } }; class blorg {
pike.git/src/testsuite.in:946:
}; class blorg { inherit fnord; int ber() { return 2; } }; return blorg()->goo(); ]],3)
+
test_compile_error_any([[class X {int x; int f() {return local::x;}}]])
+
test_compile_any([[
+
#pike 7.2
+
class X {int x; int f() {return local::x;}}
+
]])
+
// Testing the 'inline' keyword test_program([[class foo { inline int c() { return time(); } int d() { return c(); } }; class bar { inherit foo; int c() { return 0; } } int a() { return bar()->d(); }]],0) test_compile_any([[ class top { class the_class { } }
pike.git/src/testsuite.in:970:
constant top_the_class=top::the_class; class the_other_class { inherit top_the_class; } } ]])
+
// Identity of nested programs.
+
test_program([[
+
class A {int i; class X {int j;};}
+
class B {inherit A;}
+
int a() {return A()->X == B()->X;}
+
]])
+
test_program([[
+
class A {int i; class X {int j;};}
+
class B {inherit A;}
+
int a() {return A.X == B.X;}
+
]])
+
test_program([[
+
class A {int i; class X {int j = i;};}
+
class B {inherit A;}
+
int a() {return A()->X != B()->X;}
+
]])
+
test_program([[
+
class A {int i; class X {int j = i;};}
+
class B {inherit A;}
+
int a() {return A.X == B.X;}
+
]])
+
// Testing __INIT test_any([[
-
class X { int x = 1; };
-
class Y { int y = 2; };
-
class Z { inherit X; inherit Y; int z = 4; };
+
class X { int x = 1;
int zz = 1; int zzz=8; int xx=16;
};
+
class Y { int y = 2;
int xx;
};
+
class Z { inherit X; inherit Y; int z = 4;
int zz = 0; int zzz;
};
object zz = Z();
-
return zz->x + zz->y + zz->z;
+
return zz->x + zz->y + zz->z
+ zz->zz + zz->zzz + zz->xx
;
+
]], 15)
+
+
test_any([[
+
// Test __INIT with forward references to programs needing their parents.
+
class X {
+
program y = Y;
+
local class Y {
+
program z = y;
+
};
+
};
+
object x = X();
+
return x->y == x->Y;
+
]], 1)
+
+
// Testing getter/setters
+
test_any([[
+
// Trivial case.
+
class X {
+
int `->x() { return 5; }
+
};
+
return X()->x;
+
]], 5)
+
+
test_any([[
+
// Strange behaviour getter & setter.
+
class X {
+
int y = 2;
+
int `->x() { return y*3; }
+
void `->x=(int z) { y += z*5; }
+
};
+
X x = X();
+
x->x = 2;
+
return x->x;
+
]], 36)
+
+
test_any([[
+
// Multiple inheritance.
+
class X {
+
int y = 0;
+
int `->x() { return y; }
+
void `->x=(int z) { y = z; }
+
};
+
class Y {
+
inherit X:x1;
+
inherit X:x2;
+
int `->x1() { return x1::x; }
+
void `->x1=(int z) { x1::x = z; }
+
int `->x2() { return x2::x; }
+
void `->x2=(int z) { x2::x = z; }
+
};
+
Y y = Y();
+
y->x1 = 1;
+
y->x2 = 2;
+
return (y->x1 + y->x2) * y->x;
+
]], 6)
+
+
test_any([[
+
// Triggered fatal error "Getter/setter variable outside program!".
+
class X {
+
protected int xx;
+
int `->x() { return xx; }
+
void `->x=(int xxx) { xx = xxx; }
+
protected void create(int xxx) {
+
x = xxx;
+
}
+
};
+
class Y {
+
inherit X;
+
protected void create(int yyy) {
+
X:x = yyy + 2;
+
}
+
};
+
return Y(5)->x;
]], 7)
-
+
test_eval_error([[
+
// Triggered infinite recursion and core dump.
+
// cf LysLysKOM 18719518/Pike mailinglist 12047.
+
object o = class{}();
+
o->foo += "";
+
]])
+
+
test_compile_error([[
+
class X {
+
int x;
+
int `->x() { return 0; }
+
};
+
]])
+
+
test_compile_error([[
+
class X {
+
int `->x() { return 0; }
+
int x;
+
};
+
]])
+
+
test_compile_error([[
+
class X {
+
int x;
+
void `->x=(int z) { }
+
};
+
]])
+
+
test_compile_error([[
+
class X {
+
void `->x=(int z) { }
+
int x;
+
};
+
]])
+
+
test_compile_error([[
+
class X {
+
void `->x(int z) { }
+
};
+
]])
+
+
// Disabled for now.
+
cond([[ 0 ]], [[
+
test_compile_error([[
+
class X {
+
int `->x=() { }
+
};
+
]])
+
]])
+
+
test_compile_warning([[
+
class X {
+
protected int `->x() { return 0; }
+
private void `->x=(int x) { }
+
};
+
]])
+
+
test_compile_warning([[
+
class X {
+
protected int `->x() { return 0; }
+
void `->x=(int x) { }
+
};
+
]])
+
test_do([[
-
+
// bug 3006
class X { constant foo = Foo; class Foo {} void bar() { foo f = Foo(); } }; ]])
-
+
test_program([[
+
// Another variant of [bug 3006].
+
class X {
+
constant foo = Foo;
+
class Foo {}
+
}
+
int a() {return programp (X.foo);}
+
]])
+
+
cond(0,[[
+
test_program([[
+
// This shows a case when on-demand resolving is required.
+
class X {
+
constant foo = a + 1;
+
constant a = b + 1;
+
constant b = c + 1;
+
constant c = d + 1;
+
constant d = 1;
+
};
+
int a() {return X.foo == 5;}
+
]])
+
test_program([[
+
// Reference case for the test above.
+
class X {
+
constant d = 1;
+
constant c = d + 1;
+
constant b = c + 1;
+
constant a = b + 1;
+
constant foo = a + 1;
+
};
+
int a() {return X.foo == 5;}
+
]])
+
]])
+
test_any([[ class X {
-
static
string f() { return "p"; }
-
static
class gazonk { void create() { f(); }};
-
static
class g { object e() { return gazonk(); }};
+
protected
string f() { return "p"; }
+
protected
class gazonk { void create() { f(); }};
+
protected
class g { object e() { return gazonk(); }};
void create() { g()->e(); }}; return objectp(X()); ]],1)
-
test_any([[class A {
protected
int x=1; }; class B { inherit A; int foo() { return A::x; }}; return A()->x
==
B()->x && B()->foo()==A()->x;]],1)
+
test_any([[class A { int x=1; }; class B {
protected
inherit A; int foo() { return A::x; }}; return A()->x
&& !
B()->x && B()->foo()==A()->x;]],1)
test_any([[class C { int q() { return p(); } int p() { return 17; }}; return C()->q();]],17) test_any([[class C1 { class D { string id() { return "foo"; } }; class Y { program YinD() { return D; }} }; class C2 { inherit C1; class D { string id() { return "bar"; } } }; return C2()->Y()->YinD()()->id()]],"bar") test_any([[object o=class foo{int c;class bar{void create(){c++;};}}(); o->bar(); return o->c;]],1) test_do([[add_constant("GURKA2",class foo { int c; class bar{void create() {c+=17;}}}()); ]]) test_any([[class x { inherit GURKA2.bar; }(); return GURKA2->c;]],17) test_any([[class x { inherit GURKA2.bar; }(); return GURKA2->c;]],34) test_do([[add_constant("GURKA2",class foo { int c; class bar{void create() { class sune { void create() {c+=17;}}(); }}}()); ]]) test_any([[class x { inherit GURKA2.bar; }(); return GURKA2->c;]],17) test_any([[class x { inherit GURKA2.bar; }(); return GURKA2->c;]],34) test_do([[add_constant("GURKA2");]]);
-
test_eq(class {
static
int foo=17; }()->foo,0)
-
test_eval_error(class c {
static
int foo=17; }()->foo=18;)
+
test_eq(class {
protected
int foo=17; }()->foo,0)
+
test_eval_error(class c {
protected
int foo=17; }()->foo=18;)
test_equal( [[ ({ (["foo":"bar"]), (<"foo">), ([]) })->foo ]], [[ ({"bar",1,0}) ]]) test_any([[mixed a=({([]),0}); a[1]=a; return a->foo[0];]],0) test_eval_error([[return column(({0}),"foo");]]) test_any([[ class A { constant a=0; int foo() { return a; } }; class B { inherit A; constant a=1; }; return B()->foo(); ]], 1) test_any([[
pike.git/src/testsuite.in:1036:
class p2 { int foo() { return 3; }}; class c1 { inherit p1; inherit p2; int foo() { return p1::foo()+p2::foo(); }}; class c2 { inherit c1; }; return c2()->foo();]],4) test_any([[ class p1 { int foo() { return 1; } }; class p2 { int foo() { return 2; } }; class c1 { inherit p1; inherit p2; }; return c1()->foo();]],2)
-
test_any([[class foo { int x=random(100); int `<(object o) { return x < o->x; } }; object *o=allocate(100,foo)(); sort(o); for(int e=1;e<100;e++) if(o[e-1]->x > o[e]->x) return e; return -1;]],-1)
-
+
test_any([[ mixed ret=({}); int a, b = 3; for (a = 0; a < b; a++) { ret+=({a,b}); if (a % 2) b += 1; } return equal(ret,({0,3,1,3,2,4,3,4,4,5})); ]],1)
pike.git/src/testsuite.in:1084:
} return equal(ret,({0,3,1,3,2,4,3,4,4,5})); ]],1) test_compile_error([[void foo() { 1++; }]]) dnl test_compile_error([[void foo() { return destruct(this_object()); }]]) test_any([[class foo { constant x=17; }; class bar { inherit foo; constant x=18; }; return bar()->x;]],18) test_program([[inline string foo(string s){ while(s[0] == ' ' || s[0] == '\t') s = s[1..]; return(s); } string a() { return foo(" bar"); }]])
+
+
// lambda function tests
+
test_true([[lambda(int x) { return lambda() { return x; };}]]) test_eq([[lambda(int x) { return lambda() { return x; };}(4)()]],4) test_eq([[lambda(int x) { return lambda() { return x; };}(17)()]],17) test_eq([[lambda(int x) { return lambda() { return lambda() { return x; };};}(17)()()]],17)
-
+
// trampoline tests
+
test_do([[{
+
function trampoline =
+
lambda() {
+
int i = 17;
+
return lambda () {
+
error ("Trampoline called.\n");
+
return i;
+
};
+
}();
+
+
// Now find the trampoline object. Pike tries very hard to hide
+
// it, so we have to do it the hard way..
+
object obj;
+
find_trampoline_object: {
+
for (obj = next_object();
+
objectp (obj) || // It's a normal object.
+
(intp (obj) && obj); // It's a bignum object.
+
obj = next_object (obj))
+
if (obj->`() == trampoline) break find_trampoline_object;
+
error ("Trampoline object not found.\n");
+
}
+
+
if (!obj) error ("Trampoline object false.\n");
+
if (!stringp (sprintf ("%O", obj)))
+
// The important part is to try to call the _sprintf lfun in the
+
// trampoline object, not to check what sprintf() returns.
+
error ("Failed to describe trampoline object.\n");
+
}]])
+
+
// local function tests
test_eq(120, [[ lambda() { int f(int i) { return i == 0 ? 1 : i*f(i-1); }; return f(5); }(); ]]) test_eq([[function f; for(int i = 0; i < 2; i++) { {int _i = i; f = lambda(int j) { return _i+j; }; } } return f(17);]], [[function f; for(int i = 0; i < 2; i++)
-
{ {int _i = i; f = lambda(int j) { return _i+j; }; } int FEL; }
+
{ {int _i = i; f = lambda(int j) { return _i+j; }; } int FEL;
FEL;
}
return f(17);]]);
-
+
test_any([[
+
int x,y,z;
+
function p;
+
void foo() { y+=7; };
+
void bar()
+
{
+
foo();
+
void gazonk()
+
{
+
foo();
+
void quux()
+
{
+
foo();
+
y+=4711;
+
};
+
p=quux;
+
};
+
+
gazonk();
+
gazonk();
+
};
+
foo();
+
bar();
+
p();
+
return y; x; z;
+
]], 7 * 5 + 4711 )
+
+
test_any([[
+
int x=1;
+
void for10(function f) { for(int e=0;e<10;e++) f(); };
+
for10(lambda() { x++; });
+
return x;
+
]], 11)
+
+
// implicit lambda tests
+
test_any([[
+
int x=1;
+
void for10(function f) { for(int e=0;e<10;e++) f(); };
+
for10() { x++; };
+
return x;
+
]], 11)
+
+
test_compile_error([[
+
int x=1;
+
void for10(function f) { for(int e=0;e<10;e++) f(); };
+
for10() { x++; }
+
return x;
+
]])
+
+
test_any([[
+
int x;
+
for(int i=5; i < 10; i++) x++;
+
return x;
+
]], 5)
+
test_true([[lambda(function f) {return 1;}(object_program(this_object()));]])
-
+
test_any([[
+
function my_lambda;
+
+
{
+
string foo = "foo", bar = "bar";
+
my_lambda = lambda() { return foo; };
+
}
+
+
int really_magic_var;
+
return my_lambda(); really_magic_var;
+
]],"foo")
+
test_eq([[class c { int `()(){ return 4711; } }()(); ]],4711) teste_eval_error(mixed foo=({}); sort(@foo); ) test_compile_error([[int foo() { return 1} ; constant foo=(["foo":foo]); return foo->foo();]]) test_compile_error([[class T{void p(object e,object f){lambda::create(f);}}]])
-
test_eval_error(
mixed
*
foo=({}); return mkmapping(foo,({1})); )
+
test_eval_error(
array
foo=({}); return mkmapping(foo,({1})); )
test_compile_error([[mapping (string:array(string:string)) foo=([]); ]]) test_compile_error([[int a() { switch(random(2)) { case 3: if(random(2)) { case 0: return 1; } else { case 1: return 2; } } }]])
-
test_true(encode_value(0))
+
test_true(encode_value(0)[0]=='\266') define(test_encode, [[ test_equal($1, decode_value(encode_value($1))) test_equal($1, decode_value(encode_value_canonic($1))) ]]) test_eq(replace("foobar","","X"),"fXoXoXbXaXr") test_encode(0) test_encode("") test_encode(0.0) test_encode(1.0) test_encode(-1.0) test_encode(12.0) test_encode(100000.0) test_encode(3.1875) test_encode(0.0000019073486328125) test_encode(({}))
-
+
// This should work both with and without bignums.
+
test_encode(({0xffffffff+1, 0xffffffff+2}))
test_encode(([])) test_encode("foobar") test_encode((<>)) test_encode("\7") test_encode("\77") test_encode("\777") test_encode("\7777") test_encode("\77777") test_encode("\777777") test_encode("\7777777")
pike.git/src/testsuite.in:1181:
test_equal(encode_value_canonic ((["en":1,"sv":2,"de":3])), encode_value_canonic ((["sv":2,"en":1,"de":3]))) test_equal(encode_value_canonic ((<"en","sv","de">)), encode_value_canonic ((<"en","de","sv">))) test_equal(encode_value_canonic ((<"en","sv","de">)), encode_value_canonic ((<"de","sv","en">))) test_equal(encode_value_canonic ((<"en","sv","de">)), encode_value_canonic ((<"sv","en","de">)))
+
test_any([[
+
// bug 3013
+
class Test
+
{
+
class Resolver (array c)
+
{
+
mixed resolv (string id)
+
{
+
if (id == "c") return c;
+
}
+
}
+
+
class Codec
+
{
+
mixed fooof (string name) {return all_constants()[name];}
+
function objectof = fooof;
+
function functionof = fooof;
+
function programof = fooof;
+
+
string nameof (mixed what)
+
{
+
if (string name = search (all_constants(), what)) return name;
+
return ([])[0];
+
}
+
+
mixed encode_object (object o) {}
+
void decode_object (object o, mixed d) {}
+
}
+
+
mixed main()
+
{
+
array c = ({"subres"});
+
object o = compile (
+
#"string res() {return `+(@((array(function(:string)))c)());}
+
string subres() {return \"foo\";}",
+
Resolver (c))();
+
for (int i = 0; i < sizeof (c); i++)
+
if (stringp (c[i])) c[i] = o[c[i] ];
+
#ifdef DEBUG
+
#define D ,1
+
#else
+
#define D
+
#endif
+
function e=encode_value;
+
function d=decode_value;
+
return d (e (o, Codec() D), Codec() D)->res();
+
}
+
};
+
return Test()->main();
+
]],"foo")
+
+
test_any([[
+
// bug 3014
+
class Test
+
{
+
class Codec
+
{
+
mixed nameof (mixed what)
+
{
+
return ([])[0];
+
}
+
mixed encode_object (object o) {}
+
void decode_object (object o, mixed d) {}
+
}
+
+
int main()
+
{
+
object o = compile_string (#"
+
constant x = ({0});
+
int f() {return 17;}
+
int g() {return ((array(function(:int)))x)[0]();}
+
")();
+
o->x[0] = o->f;
+
function e=encode_value;
+
function d=decode_value;
+
o = d (e (o, Codec()), Codec());
+
return function_object (o->x[0]) == o;
+
}
+
};
+
return Test()->main();
+
]],1);
+
+
test_any([[mixed s="foo"; return s++;]],"foo") test_any([[mixed s="foo"; s++; return s;]],"foo1") test_any([[mixed s="foo"; return ++s;]],"foo1") test_any([[float p=2.0; return p--;]],2.0); test_any([[float p=2.0; p--; return p;]],1.0) test_any([[float p=2.0; return --p;]],1.0) test_compile_error(int foo() { LJjjjjJJJ ; })
-
test_true(
clone(
class c { constant i=1; })->i)
-
test_true(
clone(
class c { constant i=0; mixed `->(string s) { if(s=="i") return 1; }})->i)
-
test_true(
clone(
class c { constant i=1; mixed `->(string s) { return 0; }})["i"])
-
test_true(
clone(
class c { constant i=0; mixed `[](string s) { if(s=="i") return 1; }})["i"])
-
test_true(
clone(
class c { optional constant i=0; mixed `[](string s) { if(s=="i") return 1; }})["i"])
-
test_true(
clone(
class c { mixed `[]=(mixed a, mixed b) { if(a!=b) throw(1); }})[1]=1)
-
test_true(
clone(
class c { mixed `->=(mixed a, mixed b) { if(a!=b) throw(1); }})->i="i")
+
test_true(class c { constant i=1; }
(
)->i)
+
test_true(class c { constant i=0; mixed `->(string s) { if(s=="i") return 1; }}
(
)->i)
+
test_true(class c { constant i=1; mixed `->(string s) { return 0; }}
(
)["i"])
+
test_true(class c { constant i=0; mixed `[](string s) { if(s=="i") return 1; }}
(
)["i"])
+
test_true(class c { optional constant i=0; mixed `[](string s) { if(s=="i") return 1; }}
(
)["i"])
+
test_true(class c { mixed `[]=(mixed a, mixed b) { if(a!=b) throw(1); }}
(
)[1]=1)
+
test_true(class c { mixed `->=(mixed a, mixed b) { if(a!=b) throw(1); }}
(
)->i="i")
-
+
test_do([[
+
#pragma strict_types
+
class A { int a; optional int x; };
+
class B { int a; };
+
A a = B();
+
return a;
+
]])
+
+
test_compile_error_any([[
+
#pragma strict_types
+
class A { int a; optional int x; };
+
class B { int b; };
+
A a = B();
+
return a;
+
]])
+
test_eq((["static":42])->static,42)
-
+
test_eq((["protected":42])->protected,42)
test_compile_any(class A {}; class B { inherit A; })
-
+
test_any([[
+
// Check that indexing of objects works as expected.
+
object m = master();
+
array(mixed) val = values(m);
+
foreach(indices(m); int i; string ind) {
+
if (m[ind] != val[i]) {
+
error("Indexing error: master()[%O]:%O != %O.\n",
+
ind, m[ind], val[i]);
+
}
+
}
+
]], 0)
+
+
// Automap tests
+
+
test_equal([[ ({10,20})[*] + 30 ]], [[ ({40, 50}) ]])
+
test_equal([[ 30 + ({10,20})[*] ]], [[ ({40, 50}) ]])
+
test_equal([[ ({1,2})[*] + ({10,20})[*] ]], [[ ({11, 22}) ]])
+
+
+
test_equal([[ ({ ({10,20}), ({30,40}) })[*][*] + 5 ]],
+
[[ ({ ({15,25}), ({35,45}) }) ]])
+
+
test_equal([[ 5 + ({ ({10,20}), ({30,40}) })[*][*] ]],
+
[[ ({ ({15,25}), ({35,45}) }) ]])
+
+
test_any_equal([[
+
array a=({ ({10,20}), ({30,40}) });
+
a[*][*] += 5;
+
return a;
+
]],
+
[[ ({ ({15,25}), ({35,45}) }) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
a[*] += -2;
+
return a;
+
]], [[ ({-1,0,1}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
a[*] += -1;
+
return a;
+
]], [[ ({0,1,2}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
a[*] += 0;
+
return a;
+
]], [[ ({1,2,3}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
a[*] += 1;
+
return a;
+
]], [[ ({2,3,4}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
a[*] += 2;
+
return a;
+
]], [[ ({3,4,5}) ]])
+
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
return a[*] += -2;
+
]], [[ ({-1,0,1}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
return a[*] += -1;
+
]], [[ ({0,1,2}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
return a[*] += 0;
+
]], [[ ({1,2,3}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
return a[*] += 1;
+
]], [[ ({2,3,4}) ]])
+
+
test_any_equal([[
+
mixed a=({1,2,3});
+
return a[*] += 2;
+
]], [[ ({3,4,5}) ]])
+
+
test_equal([[ "foo"[ ({ 2,0,1,2 })[*] ] ]],
+
[[ ({ 'o', 'f', 'o', 'o' }) ]])
+
+
test_equal([[ ({ ({1}), ({2}), ({3}) })[*][0] ]],
+
[[ ({ 1,2,3 }) ]])
+
+
test_equal([[ ({ ({1,2}), ({3,4}), ({5,6}) })[*][ ({0,1,1})[*] ] ]],
+
[[ ({ 1,4,6 }) ]])
+
+
// map tests
test_any_equal(array a = ({({1,0,0}),({1,1,0}),({0,1,1})}); return map(a,`[],1);, ({0,1,1})) test_any_equal(array a = ({({1,0,0}),({1,1,0}),({0,1,1})}); map(a,`[]=,1,0); return a;, ({({1,0,0}),({1,0,0}),({0,0,1})})) test_any_equal(array a = ({(<1>),(<1,2>),(<2,3>),(<1,3>)}); return map(a,`[],1);, ({1,1,0,1})) test_any_equal(array a = ({(<1>),(<1,2>),(<2,3>),(<1,3>)}); map(a,`[]=,1,0); return a;, ({(<>),(<2>),(<2,3>),(<3>)})) test_any_equal(array a = ({(<"a">),(<"b">),(<>)}); map(a,`->=,"a",1); return a;, ({(<"a">),(<"a","b">),(<"a">)}))
pike.git/src/testsuite.in:1350:
FNORD::`->= (var, val); } } }; object o = B(); object o2=o->Q(); o2->a += ({2}); return o->a; ]], ({1,2}))
+
dnl // Undefined behaviour, don't do this - Hubbe dnl test_any_equal([[ dnl class A { dnl array a = ({1}); dnl void `->= (string var, mixed val) {::`->= (var, val); a += ({17});} dnl }; dnl class B { dnl inherit A; dnl }; dnl object o = B();
pike.git/src/testsuite.in:1384:
inherit A; array a = ({1}); }; object o = B(); o->a += ({2}); return o->a + ({o->f}); ]], ({1,2,17})) ]]) test_true(mappingp(_memory_usage()))
+
test_any([[
+
int ret = 1;
+
foreach(_memory_usage(); string type; int value)
+
if(value<0)
+
{
+
werror("_memory_usage()->%s has value %d which is <0\n",
+
type, value);
+
ret = 0;
+
}
+
return ret;
+
]],1)
test_true(_refs("")); test_true(_refs(({}))); test_true(_refs(([]))); test_true(_refs(this_object()))
-
test_true(objectp( _next(this_object()) || _prev(this_object())))
+
test_true(arrayp( _next(({})) || _prev(({})))) test_do(object o=this_object(); while(o=_next(o))) test_do(object o=this_object(); while(o=_prev(o)))
-
+
test_any([[
+
object q=class {}();
+
object o=_next(this_object());
+
while(zero_type(o)) o=_next(o); /* skip destructed */
+
catch { if(objectp(o) || object_program(o)) return 1; };
+
o=_prev(this_object());
+
while(zero_type(o)) o=_prev(o); /* skip destructed */
+
catch { if(objectp(o) || object_program(o)) return 1; };
+
return 0;
+
]],1)
+
test_any([[object(Stdio.File) o=Stdio.File(); return objectp(o);]],1)
-
test_any([[object o=Regexp("foo"); return objectp(o);]],1)
-
test_any([[object o=Regexp("foo"); return object_program(o);]],Regexp)
+
test_any([[class Test {}; object(Test) o=Test(); return object_program(o);]],Test) test_define_program(test,[[constant foo = 1; int a() { return foo; }]])
-
test_true(
new(
test)->a())
+
test_true(
test
()->a())
test_program(inherit test;) test_program(inherit test; int a() { return foo; } ) test_define_program(test,[[class TEST { int a() { return 1; } }]]) test_program(inherit test; inherit TEST; )
-
+
test_do(add_constant("test");)
-
test_
compile
_
error
(class c { object(Stdio.File) foo=class {} ();})
-
test_compile
_error
(class c { object(Stdio.File) foo=class {} ();})
-
test_compile_error(class c { object(Stdio.File) foo=class
{}
();})
-
test_compile
_error
(class c { object(Stdio.File) foo=class
foobar
{}
();})
-
test_do(class c { object foo; object(
Regexp
) bar=foo; })
+
test_
any([[
+
/* don't save parent */
+
class Foo { };
+
return (!function
_
object
(
object_program(Foo()))) &&
+
(function_program(object_program(Foo())) ==
+
object_program(this_object()));
+
]], 1)
+
+
test_any([[
+
class
Foo { };
+
return function_name(object_program(Foo()));
+
]], "Foo")
+
+
test_any([[
+
int q;
+
return stringp(function_name( lambda() { return q; }));
+
]],1)
+
+
test_any([[
+
// Named lambda.
+
int foo(){};
+
return function_name(foo);
+
]], "foo")
+
+
test_any([[
+
// Named trampoline.
+
int q;
+
int foo() { return q; };
+
return function_name(foo);
+
]], "foo")
+
+
test_any([[
+
int q;
+
return function_object( lambda() { return q; });
+
]],[[this_object()]])
+
+
+
test_compile(class
c { object(Stdio.File) foo=class
foobar
{} ();})
+
test_compile(class c { object(Stdio.File) foo=class {} ();})
+
test_compile_error(class c { object(Stdio.File) foo=class
{float
is_file;}
();})
+
test_compile(class c { object(Stdio.File) foo=class
{
int
is_file;}
();})
+
test_do(class c { object foo; object(
Stdio.File
) bar=foo; })
+
test_do(class c { object foo; Stdio.File bar=foo; })
test_do(class c { object(Stdio.File) foo; object bar=foo; })
-
+
test_do(class c { Stdio.File foo; object bar=foo; })
test_any(if(int i=1) return i; return 0;,1) test_compile(for(int i=0;i<100;i++) return 0;)
-
test_compile(foreach(({}),mixed i)
{}
)
-
test_compile(sscanf("","",mixed foo))
-
test_compile_error(sscanf("","",float))
+
test_compile(foreach(({}),mixed i)
{i;}
)
+
test_compile(sscanf("","
%O
",mixed foo)
;foo;
)
+
test_compile_error(sscanf("","",
mixed foo);)
+
test_compile_error(sscanf("","%f",
float))
test_compile_error(sscanf("",float)) // ++ test_any([[int e; e++; return e;]],1) test_any([[int e; ++e; return e;]],1) test_any([[int e; return e++;]],0) test_any([[int e; return ++e;]],1) test_any([[int e; if(e++) return 0; return e;]],1) test_any([[string e=""; e++; return e;]],"1") // -- test_any([[int e; e--; return e;]],-1) test_any([[int e; --e; return e;]],-1) test_any([[int e; return e--;]],0) test_any([[int e; return --e;]],-1) test_any([[int e; if(e--) return 0; return e;]],-1)
-
test_compile_error_
low
(master()->add_precompiled_program(\"/test\",compile_string(\"int foo() { return 17; }\",\"62\")))
+
test_compile_error_
any
(master()->add_precompiled_program(\"/test\",compile_string(\"int foo() { return 17; }\",\"62\")))
test_any([[function f=random_seed; int t; foreach(allocate(1),t) f(t); return 1;]],1) test_compile([[while(0)if(0)continue;else;]]) test_compile([[do { break; } while (0);]]) test_program([[int b=1,c; int a() { c=b+2; return c==3; }]]) test_true([[ ("foobar"/"o") & ({ "foo" }) ]]) test_any([[ array a="foo bar"/" "; return sizeof(a & ({"foo"}))]],1)
-
// glob
-
test_false(glob("foo","bar"))
-
test_true(glob("foo","foo"))
-
test_true(glob("f?o","foo"))
-
test_true(glob("f??","foo"))
-
test_true(glob("?o?","foo"))
-
test_true(glob("f*","foo"))
-
test_true(glob("*o","foo"))
-
test_true(glob("*<<<*","<<<"))
-
test_true(glob("*<<<*","<<<foo"))
-
test_false(glob("*f","foo"))
-
test_false(glob("o*","foo"))
-
test_false(glob("?f?","foo"))
-
test_equal([[glob("?f?",({"ff","ffff","off","fff",""}))]],[[({"off","fff"})]])
-
test_equal([[glob("foo*bar",({"foobar","foobargazonk","","foofoobar","fobar","fooar"}))]],[[({"foobar","foofoobar"})]])
-
-
// localtime
-
cond([[all_constants()->localtime]],
-
[[
-
test_true(mappingp(localtime(0)))
-
]])
-
-
cond([[all_constants()->mktime]],
-
[[
-
test_true([[mktime( ([
-
"sec":58,
-
"isdst":1,
-
"year":98,
-
"mon":3,
-
"mday":26,
-
"hour":1,
-
"min":51
-
]))]])
-
-
test_eq([[mktime(58,51,1,26,3,98,1,0)]],[[mktime( ([
-
"sec":58,
-
"isdst":1,
-
"year":98,
-
"mon":3,
-
"mday":26,
-
"hour":1,
-
"min":51,
-
"timezone":0,
-
]) ) ]])
-
-
]])
-
-
cond([[all_constants()->localtime && all_constants()->mktime]],
-
[[
-
test_any([[int x=time(); return mktime(localtime(x)) == x;]], 1)
-
test_any([[int x=time(); for(int y=0;y<100;y++) if(mktime(localtime(x+y)) != x+y) return x+y; return 0;]], 0)
-
]])
-
+
cond([[all_constants()->_verify_internals]], [[ test_do(_verify_internals()) ]])
-
// sort
-
test
_
equal
(
sort(({1,3,2,4})),({1,2,3,4}))
-
test_equal(sort(({4,3,2,1})),({1,2,3,4}))
-
test_equal(
[[
lambda() {array(int) a=({1,2,3,4}); sort(({4,3,2,1}),a); return a; }()]],[[({4,3,2,1})]] )
-
test
_
equal
(
[[lambda(
)
{array(int) a=({1,2,3,4}), b=a+({}); sort(({4,3,2,1}),a,b); return b; }()
]]
,[[({4,3,2,1}
)
]] )
+
cond
_
begin
([[
all_constants
()
->thread
_
create
]])
-
cond([[all_constants()->thread_create]],
-
[[
+
// thread_create test_do(thread_create(lambda() { })) // /precompiled/mutex test_true(Thread.Mutex()) test_do(add_constant("_tmp_mutex",Thread.Mutex())) test_true(_tmp_mutex->lock()) test_true(_tmp_mutex->lock()) test_true(_tmp_mutex->trylock()) test_true(_tmp_mutex->trylock()) test_do(add_constant("_tmp_mutex_lock",_tmp_mutex->lock())) test_true(catch(_tmp_mutex->trylock())) test_do(add_constant("_tmp_mutex_lock")) test_true(_tmp_mutex->trylock()) test_do(add_constant("_tmp_mutex"))
-
test_any([[ object m = Thread.Mutex(); object k = m->lock(); thread_create(lambda(object k){ sleep(10); catch { destruct(k); }; }, k);if (catch{m->lock(); return 0;}) { return 1; } return 0; ]],1)
-
test_any([[ array data=({0,Thread.Mutex(),Thread.Mutex(),0}); data[3]=data[2]->lock(); thread_create(lambda(array data) {object o=data[1]->lock(); destruct(data[3]); sleep(10); data[0]=1; destruct(o); },data); object l=data[2]->lock(1); object ll=data[1]->lock(); return data[0]; ]],1)
+
test_any([[
-
+
object m = Thread.Mutex();
+
object k = m->lock();
+
thread_create(lambda(object k){
+
sleep(10);
+
catch { destruct(k); };
+
}, k);
+
if (catch{
+
m->lock();
+
return 0;
+
}) {
+
return 1;
+
}
+
return 0;
+
]],1)
+
+
test_any([[
+
array data=({0,Thread.Mutex(),Thread.Mutex(),0});
+
data[3]=data[2]->lock();
+
thread_create(lambda(array data) {
+
object o=data[1]->lock();
+
destruct(data[3]);
+
sleep(10);
+
data[0]=1;
+
destruct(o);
+
},data);
+
object l=data[2]->lock(1);
+
object ll=data[1]->lock();
+
return data[0];
+
]],1)
+
+
test_any([[
array data=({1, Thread.Mutex(), Thread.Condition(), 0});
-
for(int
e=0;e<3;e++)
{
data[3]++;
thread_create(lambda(mixed
*data)
{
-
for(int e
=
0;e<1000;e++)
{ object o=
data[1]->lock();
data[0]*=2;
-
for(int d=0;d<5;d++) { data[0]--; data[0]*=2; } data[0]--; destruct(o); }
-
data[3]--; data[2]->signal();}, data);}
-
while(data[3]) data[2]->wait(); return data[0];]],1)
+
object
key
= data[1]->lock();
-
+
for(int e=0;e<3;e++) {
+
data[3]++;
+
thread_create(lambda(array data) {
+
for(int e=0;e<1000;e++) {
+
object o=data[1]->lock();
+
data[0]*=2;
+
for(int d=0;d<5;d++) {
+
data[0]--;
+
data[0]*=2;
+
}
+
data[0]--;
+
destruct(o);
+
}
+
object o = data[1]->lock();
+
data[3]--;
+
data[2]->signal();
+
}, data);
+
}
+
+
while(data[3])
+
data[2]->wait(key);
+
return data[0];
+
]],1)
+
test_any([[
+
object lock = Thread.Mutex()->lock();
+
gc();
+
return objectp (lock);
+
]], 1)
+
// /precompiled/condition test_true(Thread.Condition()) test_do(Thread.Condition()->signal()) test_do(Thread.Condition()->broadcast())
-
test_true(objectp(
clone(
Thread.Fifo)))
-
test_true(objectp(
clone(
Thread.Queue)))
+
test_true(objectp(Thread.Fifo
(
)))
+
test_true(objectp(Thread.Queue
(
)))
-
test_any([[
object
o
=Thread.Queue();
thread
_
create(lambda(object
f)
{
for(
int
e
=0;
e<10000;e++)
f->
write(random(
4711
))
;
f->write(-1);
},o);
int
tmp
=
0;
while(o
->read() !=
-1
)
tmp++;
return
tmp;]],10000)
-
test_any([[object
o
=
Thread.Fifo
();
thread_create(lambda(object
f)
{
for(int
e=0;e<10000;e++)
f
-
>write(random(4711))
;
f
->write(-
1
);
},o);
int
tmp=0;
while(o->read()
!=
-1)
tmp++
; return
tmp
;]],
10000
)
+
// Check that Thread.Queue works on the basic level.
+
test_any([[
+
Thread.Queue q
=
Thread.Queue();
+
int to
_
write
=
100000;
+
int
to_read
=
0;
+
while (to_write + to_read
)
{
+
if (!to_
write
||
random(
4 * to_read
))
{
+
int
val
=
q
->read()
;
+
if (val
!=
(to_write + to_read
)
)
+
return
val
+
"
!
=
" +
(
to_write + to_read
);
+
to
_
read--;
+
} else
{
+
q
->write(
to_
write-
-
);
+
to_read++
;
+
}
+
}
+
return
0
;
+
]],
0
)
test_any([[
-
+
object o=Thread.Queue();
+
thread_create(lambda(object f) {
+
for(int e=0;e<10000;e++)
+
f->write(random(4711));
+
f->write(-1);
+
},o);
+
int tmp=0;
+
while(o->read() != -1)
+
tmp++;
+
return tmp;
+
]],10000)
+
+
test_any([[
+
object o=Thread.Fifo();
+
thread_create(lambda(object f) {
+
for(int e=0;e<10000;e++)
+
f->write(random(4711));
+
f->write(-1);
+
},o);
+
int tmp=0;
+
while(o->read() != -1)
+
tmp++;
+
return tmp;
+
]],10000)
+
+
dnl this will crash pike on out-of-address-space-related errors
+
dnl test_any([[ catch { allocate(10000,thread_create)(lambda() { sleep(1); })->wait(); } ]])
+
+
cond_end // thread_create
+
cond(0, [[
+
test_any([[
+
// Test that a loop relinquishes the interpreter lock every now and then.
+
//
+
// This test is unfortunately disabled since it fails too often.
+
// The subthread does really yield in the loop, but the main
+
// thread, which really is waiting, fails to run. My conclusion is
+
// that the problem is the unreliability of th_yield() - we need
+
// to replace it with something else. :(
+
// /mast
+
int count, stop, fail;
+
Thread.thread_create (lambda() {
+
int t_start = time();
+
// Note: We need sub-second precision.
+
float stop_time = 1.0 + time(t_start);
+
while (!stop) {
+
count++;
+
if (time(t_start) > stop_time) {
+
fail = 1;
+
break;
+
}
+
}
+
});
+
sleep (0.1);
+
stop = 1;
+
sleep (0.1);
+
return fail ? -1 : count > 0;
+
]], 1)
+
]])
+
cond_begin([[all_constants()->thread_create]])
+
+
// _disable_threads
+
test_any([[
+
#ifndef __NT__
+
// Using a named pipe here to make open() block. That doesn't exist on NT.
+
+
object t = class {
+
void log (function f, string msg)
+
{
+
#if 0
+
if (f == test) msg = "[T] " + msg;
+
else if (f == thread_disabler) msg = " " * 20 + "[D] " + msg;
+
else if (f == mutex_locker) msg = " " * 40 + "[L] " + msg;
+
log_msg (msg);
+
#endif
+
}
+
+
mixed err;
+
+
string fifo = "/tmp/testpipe." + getpid();
+
+
int started;
+
Thread.Mutex start_lock = Thread.Mutex();
+
Thread.Mutex locker_lock = Thread.Mutex();
+
Thread.Mutex locked_mutex = Thread.Mutex();
+
Thread.MutexKey locked_mutex_key;
+
+
void mutex_locker()
+
{
+
log (mutex_locker, "locker started\n");
+
started++;
+
Thread.MutexKey k = start_lock->lock();
+
k = 0;
+
+
k = locker_lock->lock();
+
k = 0;
+
+
log (mutex_locker, "locker running\n");
+
err = catch (k = locked_mutex->lock());
+
log (mutex_locker, "locker done, error: " + (err && describe_error (err)) + "\n");
+
k = 0;
+
}
+
+
void thread_disabler()
+
{
+
log (thread_disabler, "disabler started\n");
+
Thread.MutexKey locker_key = locker_lock->lock();
+
+
started++;
+
Thread.MutexKey k = start_lock->lock();
+
k = 0;
+
+
sleep (0.1);
+
log (thread_disabler, "disabling\n");
+
locker_key = 0;
+
// Race: Don't want mutex_locker to get the lock on locker_lock
+
// until we're in _disable_threads.
+
object disable = _disable_threads();
+
log (thread_disabler, "disabled\n");
+
sleep (0.1);
+
disable = 0;
+
log (thread_disabler, "disabler done\n");
+
}
+
+
void test()
+
{
+
locked_mutex_key = locked_mutex->lock();
+
started = 0;
+
+
Thread.MutexKey start_key = start_lock->lock();
+
object disabler = thread_create (thread_disabler);
+
object locker = thread_create (mutex_locker);
+
while (started < 2) sleep (0.1);
+
+
Process.Process writer = Process.create_process(
+
RUNPIKE_ARRAY + ({
+
"-e",
+
sprintf ("sleep(0.5); "
+
"Stdio.File f = Stdio.File(%O, \"w\"); "
+
"sleep(0.5); "
+
"f->close();", fifo)
+
}));
+
+
log (test, "opening pipe\n");
+
start_key = 0;
+
Stdio.File f = Stdio.File (fifo, "r");
+
log (test, "pipe opened\n");
+
locked_mutex_key = 0;
+
+
f->close();
+
disabler->wait();
+
locker->wait();
+
writer->wait();
+
log (test, "test done\n");
+
}
+
}();
+
+
rm (t->fifo);
+
Process.system ("mkfifo " + t->fifo);
+
for (int i = 0; i < 5; i++) {
+
t->test();
+
if (t->err) return 0;
+
t->log (0, "------------\n");
+
}
+
rm (t->fifo);
+
+
#endif
+
return 1;
+
]], 1);
+
+
test_do([[
+
object l = _disable_threads();
+
Thread.thread_create (lambda () {});
+
destruct (l);
+
]])
+
+
test_any([[
+
int run = 1;
+
+
mapping(string:int) rounds = ([]);
+
+
void imutex_locker (string id)
+
{
+
while (run) {
+
#ifdef __NT__
+
// Windows got an imutex in create_process. It doesn't have to
+
// be successful.
+
catch (Process.create_process (({""})));
+
#else
+
// Unix systems don't have an imutex in create_process, but
+
// they got the standard password functions.
+
getpwuid (0);
+
#endif
+
rounds[id]++;
+
//werror (id);
+
}
+
};
+
+
void threads_disabler (string id)
+
{
+
while (run) {
+
object l = _disable_threads();
+
rounds[id]++;
+
//werror (id);
+
l = 0;
+
}
+
};
+
+
array(Thread.Thread) t = ({
+
Thread.thread_create (imutex_locker, "0"),
+
Thread.thread_create (imutex_locker, "1"),
+
Thread.thread_create (imutex_locker, "2"),
+
Thread.thread_create (threads_disabler, "a"),
+
Thread.thread_create (threads_disabler, "b"),
+
});
+
sleep (5);
+
run = 0;
+
t->wait();
+
//werror ("%O\n", rounds);
+
+
#if 0
+
// The thread yielding is really bad - even the following very
+
// weak tests trig alarms: On FreeBSD 7.1-STABLE i386 the
+
// thread_disablers do over 1000 times more rounds than the
+
// imutex_lockers. On Linux 2.6.15-1.1833_FC4 x86_64 and Linux
+
// 2.6.24-23-server i686 they do over 100 times more. On SunOS
+
// 5.11 i86pc the thread_disablers do only 1-20 rounds in total.
+
+
int minimum = min (@values (rounds)), maximum = max (@values (rounds));
+
+
if (minimum < 10) {
+
werror ("A thread got stuck: %O\n", rounds);
+
return 0;
+
}
+
+
// This span is currently very generous, since the time slicing in
+
// threads.c:check_threads can be flaky on some systems.
+
if (minimum * 100 < maximum) {
+
werror ("Too uneven distribution between threads: %O\n", rounds);
+
return 0;
+
}
+
#endif
+
+
return 1;
+
]], 1)
+
+
test_any([[
+
Stdio.write_file ("testsuite_test.pike", #"\
+
int main()
+
{
+
Thread.Mutex m = Thread.Mutex();
+
Thread.MutexKey l = m->lock();
+
Thread.thread_create (lambda () {m->lock(); exit (0);});
+
call_out (destruct, 0, l);
+
return -1;
+
}");
+
return Process.system (RUNPIKE +" testsuite_test.pike");
+
]], 0)
+
+
cond_end // thread_create
+
+
cond([[0]],
+
[[
+
test_any([[
// test if read() hangs when fd is closed by other thread object f=Stdio.File(); object g=f->pipe(); object t=thread_create( lambda() { g->read(4); }); sleep(0.1); // yield g->close(); // close same side of pipe as we have in read above sleep(0.1); // yield if (!t->status()) return 0; // should be done now // if not, there's no way to kill that thread return 1;]],1); ]])
-
test_true(Getopt.find_option(({"","--foo"}),"p","foo"))
-
test_eq(Getopt.find_option(({"","--foo=bar"}),"p","foo",0,0),"bar")
-
test_eq(Getopt.find_option(({"","--foo","bar"}),"p","foo",0,0),"bar")
-
test_eq(Getopt.find_option(({"","--","--foo=bar"}),"p","foo",0,0),0)
-
-
test_true(Getopt.find_option(({"","-p"}),"p","foo"))
-
test_eq(Getopt.find_option(({"","-pbar"}),"p","foo",0,0),"bar")
-
test_eq(Getopt.find_option(({"","-p","bar"}),"p","foo",0,0),"bar")
-
test_eq(Getopt.find_option(({"","--","--p","bar"}),"p","foo",0,0),0)
-
-
test_equal(Getopt.get_args(({"",0,0,"sune","--","-foo"})),({"","sune","-foo"}))
-
-
test_true(objectp(clone(String.String_buffer)))
-
test_do(clone(String.String_buffer)->append("foo"))
-
test_do(add_constant("Flurp",clone(String.String_buffer)))
-
test_do(Flurp->append("test"))
-
test_do(Flurp->append("test"))
-
test_eq((string)Flurp,"testtest")
-
test_do(add_constant("Flurp"))
-
-
test_eq(String.strmult("foo",4),"foofoofoofoo")
-
+
// m_delete test_any_equal([[ mapping m=([1:1]); m_delete(m,0); return m; ]],[[ ([1:1]) ]]) test_any_equal([[ mapping m=([1:1,0:3]); m_delete(m,0); return m; ]],[[ ([1:1]) ]]) test_any([[mapping a=([1:1]); return m_delete(a,1)]],1) test_any([[mapping m=([]); m[1]++; return m[1];]],1) test_any([[mapping m=([1:1]); m[1]++; return m[1];]],2)
-
+
test_any([[mapping m=([1:1]); m[1]++; return m[1]++;]],2)
test_any([[mapping m=([]); m[1]++; m[1]++; return m[1];]],2)
-
+
ignore_warning("Bad argument 2 to m_delete.", [[
+
ignore_warning("Expected: string.", [[
+
ignore_warning("Got : int(17..17).", [[
+
test_any([[
+
#pike 7.6
+
mapping(string:int) x = ([]);
+
return zero_type (m_delete (x, 17));
+
]], 1)
+
]])]])]])
+
// multiset tests test_any([[multiset m=(<>);int e; for(e=0;e<1000;e++) m[e]=1; for(e=0;e<1000;e++) if(!m[e]) return e; return -1; ]],-1) test_any([[multiset m=(<>);int e; for(e=0;e<1000;e++) m[e]++;
pike.git/src/testsuite.in:1672:
for(e=0;e<1000;e++) { m[reverse(e)]=1; a[e]=reverse(e); } add_constant("mtest_m",m); add_constant("mtest_i",a); return 1; ]],1)
+
test_any([[
+
multiset m = set_weak_flag((<>), 1);
+
m[1] = 1;
+
return sizeof(m);
+
]], 1)
+
+
test_true([[
+
multiset m = set_weak_flag((<>), 1);
+
m[1] = 1;
+
return get_weak_flag(m);
+
]])
+
test_eq([[sizeof(mtest_m)]],sizeof(mtest_i)) test_equal(Array.sort_array(indices(mtest_m)),Array.sort_array(mtest_i)) test_equal(mtest_m,copy_value(mtest_m)) test_any([[multiset m=(<>);int e; mixed a; a=allocate(100); for(e=0;e<100;e++) { m[reverse(e-50)]=1; a[e]=reverse(e-50); if(sizeof(m)!=e+1) return e; } add_constant("mtest_m2",m); add_constant("mtest_i2",a); return -1; ]],-1)
-
+
test_any_equal([[
+
class X (float i)
+
{
+
protected int `< (X o) {return i < o->i;}
+
protected int id = ++all_constants()->cnt;
+
protected string _sprintf() {return "X(" + i + ")[" + id + "]";}
+
};
+
X x1 = X(1.0), x2 = X(1.0);
+
multiset m = (<x1, X(2.0), X(3.0)>);
+
m[x2] = 1;
+
add_constant ("cnt");
+
return ({m[x1], m[x2], m[X(0.5)]});
+
]], [[({1, 1, 0})]])
+
+
test_any_equal([[
+
class X (float i)
+
{
+
protected int `< (X o) {return i < o->i;}
+
protected int id = ++all_constants()->cnt;
+
protected string _sprintf() {return "X(" + i + ")[" + id + "]";}
+
};
+
X x1 = X(1.0), x2 = X(1.0);
+
multiset m = (<x1, X(2.0), X(3.0)>);
+
m[x2] = 1;
+
add_constant ("cnt");
+
return ({(m[x1] = 1, sizeof (m)),
+
(m[x2] = 1, sizeof (m)),
+
(m[X(0.5)] = 1, sizeof (m))});
+
]], [[({4, 4, 5})]])
+
+
test_do(add_constant("cnt");)
+
test_eq([[sizeof(mtest_m2)]],sizeof(mtest_i2)) test_any([[int e;multiset q=(<>),p=(<>); for(e=0;e<1000;e++) { p[reverse(e)]=1; q+=(<reverse(e)>); if(!equal(sort(indices(p)),sort(indices(q)))) return 0; } return 1;]],1) test_equal(sort(indices(mtest_m|mtest_m2)),sort(mtest_i|mtest_i2)) test_equal(sort(indices(mtest_m&mtest_m2)),sort(mtest_i&mtest_i2)) test_equal(sort(indices(mtest_m-mtest_m2)),sort(mtest_i-mtest_i2)) test_equal(sort(indices(mtest_m^mtest_m2)),sort(mtest_i^mtest_i2)) test_equal(sort(indices(mtest_m2|mtest_m)),sort(mtest_i2|mtest_i)) test_equal(sort(indices(mtest_m2&mtest_m)),sort(mtest_i2&mtest_i)) test_equal(sort(indices(mtest_m2-mtest_m)),sort(mtest_i2-mtest_i))
pike.git/src/testsuite.in:1720:
MTEST(3) MTEST(5) MTEST(8) MTEST(13) MTEST(21) MTEST(34) MTEST(55) define([[MTEST]])
+
test_equal([[lambda(multiset x){return ({x[17]++,x[17]++,x[17]++});}((<>))]],
+
[[({0,1,1})]])
+
+
test_any([[
+
object o1 = class{}(), o2 = class{}(), o3 = class{}();
+
multiset m = (<o1, o2, o3, 17>);
+
destruct (o1), destruct (o2), destruct (o3);
+
return m[17];
+
]], 1);
+
+
test_any_equal([[
+
object o1 = class{}(), o2 = class{}(), o3 = class{}();
+
multiset m = (<o1, o2, o3, 17>);
+
destruct (o1), destruct (o2), destruct (o3);
+
return copy_value (m);
+
]], (<17>));
+
+
test_do([[
+
multiset a = copy_value ((<(<1,2,3>), ({5,4}), ([1:2]), 1, ({}), (<1,2>), "foo">));
+
foreach (a; mixed i;)
+
if (!a[i]) error ("Can't find multiset member in itself: %O\n", i);
+
]])
+
+
test_any_equal([[
+
multiset m=(<"Stone","2","%70">);
+
foreach(m;string k;)
+
{
+
if(k=="%70")
+
{
+
m[k]=0;
+
break;
+
}
+
}
+
return sort ((array) (m - (<>)));
+
]], ({"2", "Stone"}))
+
+
test_any([[
+
class X (int i) {
+
int `< (mixed o) {return 0;}
+
int `== (mixed o) {return 0;}
+
};
+
multiset m = (<X(2)>);
+
m[X(4)] = 1;
+
m[X(1)] = 1;
+
m[X(3)] = 1;
+
return sizeof (m);
+
]], 4)
+
// mapping tests test_any([[mapping m=([]);int e; for(e=0;e<1000;e++) m[e]=e; for(e=0;e<1000;e++) if(m[e]!=e) return 0; return 1; ]],1) test_any([[mapping m=([]);int e; for(e=0;e<1000;e++) m[e]=e;
pike.git/src/testsuite.in:1815:
test_any([[mapping m=([]);int e; mixed a,b; a=allocate(100); b=allocate(100); for(e=0;e<100;e++) { m[reverse(e-50)]=e-50; a[e]=reverse(e-50);
-
b[e]=
reverse(
e-50
)
;
+
b[e]=e-50;
} add_constant("mtest_m2",m); add_constant("mtest_i2",a); add_constant("mtest_v2",b); return 1; ]],1) test_any([[int e;mapping q=([]),p=([]); for(e=0;e<1000;e++) { p[reverse(e)]=e; q+=([reverse(e):e]); if(!equal(sort(indices(p)),sort(indices(q)))) return 0; } return 1;]],1) test_any([[mapping m=([]); m+=(["foo":"bar"]); m+=(["bar":"foo"]); m+=(["foo":"foo"]); if(sizeof(m)==3) return 1; return m["foo"]=="foo" && m["bar"]=="foo"]],1) test_equal(sort(indices(mtest_m|mtest_m2)),sort(mtest_i|mtest_i2)) test_equal(sort(indices(mtest_m&mtest_m2)),sort(mtest_i&mtest_i2)) test_equal(sort(indices(mtest_m-mtest_m2)),sort(mtest_i-mtest_i2)) test_equal(sort(indices(mtest_m^mtest_m2)),sort(mtest_i^mtest_i2)) test_equal(sort(indices(mtest_m2|mtest_m)),sort(mtest_i2|mtest_i)) test_equal(sort(indices(mtest_m2&mtest_m)),sort(mtest_i2&mtest_i)) test_equal(sort(indices(mtest_m2-mtest_m)),sort(mtest_i2-mtest_i)) test_equal(sort(indices(mtest_m2^mtest_m)),sort(mtest_i2^mtest_i))
-
+
test_equal(sort(values(mtest_m|mtest_m2)),sort(map(mtest_i|mtest_i2,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m&mtest_m2)),sort(map(mtest_i&mtest_i2,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m-mtest_m2)),sort(map(mtest_i-mtest_i2,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m^mtest_m2)),sort(map(mtest_i^mtest_i2,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m2|mtest_m)),sort(map(mtest_i2|mtest_i,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m2&mtest_m)),sort(map(mtest_i2&mtest_i,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m2-mtest_m)),sort(map(mtest_i2-mtest_i,mtest_m|mtest_m2)))
+
test_equal(sort(values(mtest_m2^mtest_m)),sort(map(mtest_i2^mtest_i,mtest_m|mtest_m2)))
+
test_do(add_constant("mtest_m"); add_constant("mtest_i"); add_constant("mtest_v");) test_do(add_constant("mtest_m2"); add_constant("mtest_i2"); add_constant("mtest_v2");) define([[MTEST]],[[test_equal([[mkmapping(indices(allocate($1)),reverse(indices(allocate($1))))]],[[mkmapping(reverse(indices(allocate($1))),indices(allocate($1)))]])]]) MTEST(0) MTEST(1) MTEST(2) MTEST(3) MTEST(5) MTEST(8) MTEST(13) MTEST(21) MTEST(34) MTEST(55) define([[MTEST]])
-
+
test_do([[
+
+
class X {
+
mapping gurka;
+
+
class Tomat
+
{
+
int `==(mixed x)
+
{
+
/* make hash bigger */
+
for(int e=sizeof(gurka);e<1000;e++) gurka[e]=e;
+
return 0;
+
}
+
+
int __hash()
+
{
+
return 99999;
+
}
+
};
+
+
class Sallad
+
{
+
int __hash()
+
{
+
return 99999;
+
}
+
};
+
+
void create()
+
{
+
for(int x=1;x<255;x++)
+
{
+
gurka=([]);
+
for(int e=0;e<x;e++) gurka[~e]=e;
+
gurka[Sallad()]=-2;
+
gurka[Tomat()]=-3;
+
}
+
}
+
}();
+
+
]])
+
+
test_any([[
+
mapping m = ([ "foo" : 1 ]);
+
class A {
+
int __hash() { return hash_value("foo"); }
+
int `==(mixed o) { return o == "foo"; }
+
};
+
return m[A()];
+
]], 1)
+
+
test_any([[
+
mapping m = ([ "foo" : 1 ]);
+
class A {
+
int __hash() { return hash_value("foo"); }
+
int `==(mixed o) { return o == "foo"; }
+
};
+
return sizeof(m - ([ A() : 1 ]));
+
]], 0)
+
test_equal([[ `+( ([1:2]) )]],[[ ([1:2]) ]]) test_false( `+( ([1:2]) ) == ([1:2]) ) test_equal([[ `+( ([1:2]), ([1:2]) )]],[[ ([1:2]) ]]) test_equal([[ `+( ([1:2]), ([1:2]), ([2:3,4:5]) )]],[[ ([1:2,2:3,4:5]) ]]) test_equal([[ `+( ([1:2]), ([1:2]), ([2:3,4:5]), ([6:7,1:2]) )]],[[ ([1:2,2:3,4:5,6:7]) ]]) test_equal([[ `+( ([1:2]), ([1:2]), ([2:3,4:5]), ([6:7,1:2]),([8:9]) )]],[[ ([1:2,2:3,4:5,6:7,8:9]) ]] ) test_any([[mapping m=([1:2,3:2]); return search(m,2,search(m,2))!=-1;]],1) test_any([[mapping m=([]); for(int e=0;e<1000;e++) m[e&3]+=({e}); return sizeof(m)==4 && sizeof(m[0])==250;]],1)
-
+
test_any([[
+
mapping m = set_weak_flag (([1:1]), 1);
+
m_delete (m, 1);
+
return get_weak_flag (([]));
+
]], 0);
+
+
test_equal([[lambda(mapping x){return ({x[17]++,x[17]++,x[17]++});}(([]))]],
+
[[({0,1,2})]])
+
+
test_equal([[([1:2, 3:4]) - (<0, 1, 2>)]], ([3:4]))
+
test_equal([[([1:2, 3:4]) - ({0, 1, 2})]], ([3:4]))
+
test_equal([[([1:2, 3:4]) & (<0, 1, 2>)]], ([1:2]))
+
test_equal([[([1:2, 3:4]) & ({0, 1, 2})]], ([1:2]))
+
// destructed indices test_any([[{ object o = class{}(); mapping m = ([o: 1]); destruct (o); return equal (m, ([])) && equal (m, ([])); }]], 1) test_any([[{ object o = class{}(); mapping m = ([o: 1]), n = ([class{}(): 1]);
pike.git/src/testsuite.in:1890:
destruct (o); return sizeof (indices (m)) || sizeof (m); }]], 0) test_any([[{ object o = class{}(); mapping m = ([o: 1]); destruct (o); return sizeof (values (m)) || sizeof (m); }]], 0)
-
// rows
-
test_equal([[rows(({1,2,3,4,5,6,7,8,9}),({6,7,2}))]],[[({7,8,3})]])
-
test_equal([[rows(({1,2,3,4,5,6,7,8,9}),({0,4,1}))]],[[({1,5,2})]])
-
test_equal([[rows(({1,2,3,4,5,6,7,8,9}),({8,3,5}))]],[[({9,4,6})]])
-
-
// column
-
test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),0)]],[[({1,5,8})]])
-
test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),1)]],[[({2,6,9})]])
-
test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),2)]],[[({3,7,0})]])
-
-
+
// gc
-
ifefun(gc,
-
[[
+
test_true(intp(gc()));
-
+
test_true(mappingp (((function) Debug.gc_status)()))
test_any([[ array a=({0}); a[0]=a; gc(); a=0; return gc() > 0; ]],1);
-
test_any([[object o=class c {object o;}(); o->o=o; gc(); o=0; return gc() > 0; ]],1);
-
test_any([[object o=class c {object o;}(); o->o=o; gc(); o=0; return gc() > 0; ]],1);
+
test_any([[mapping m=([]); m[m]=m; gc(); m=0; return gc() > 0; ]],1); test_any([[multiset m=(<>); m[m]=1; gc(); m=0; return gc() > 0; ]],1); test_any([[{ #if !constant (_debug) int _debug (int d) {return 0;}; #endif // Must turn off debug in this test or else we'll get extra // references to p in the backlog. int dlevel = _debug (0); program p=compile_string("constant a=({0});"); object o=p(); o->a[0]=p; gc(); p=o=0; _debug (dlevel); return gc() > 0; }]], 1);
-
+
test_any([[
+
object o = class {function f; void foo() {}}();
+
o->f = o->foo;
+
gc();
+
o = 0;
+
return gc();
+
]], 0)
+
test_any([[
+
object o = class {object o;}();
+
o->o = o;
+
gc();
+
o = 0;
+
return gc();
+
]], 0)
+
test_any([[
+
class X {function f; void foo() {}};
+
object o1 = X(), o2 = X();
+
o1->f = o2->foo;
+
o2->f = o1->foo;
+
gc();
+
o1 = o2 = 0;
+
return gc();
+
]], 2)
+
test_any([[
+
class X {object o;};
+
object o1 = X(), o2 = X();
+
o1->o = o2;
+
o2->o = o1;
+
gc();
+
o1 = o2 = 0;
+
return gc();
+
]], 2)
+
test_any([[gc(); int q=lambda() { mixed foo; foo=lambda() { return foo; }; return 1; }(); return gc()>0; ]],1) test_true([[ object o = class{}(); mapping m = ([class{}(): o, o: class{}()]); set_weak_flag (m, 1); gc(); return !sizeof (m); ]]) test_true([[ object o = class{}();
-
+
mapping m = ([class{}(): o, o: class{}()]);
+
set_weak_flag (m, Pike.WEAK_INDICES);
+
gc();
+
return sizeof (m);
+
]])
+
test_true([[
+
object o = class{}();
+
mapping m = ([class{}(): o, o: class{}()]);
+
set_weak_flag (m, Pike.WEAK_VALUES);
+
gc();
+
return sizeof (m);
+
]])
+
test_true([[
+
object o = class{}();
multiset m = (<o>); set_weak_flag (m, 1); m[class{}()] = 1; m[o] = 0; gc(); return !sizeof (m); ]])
-
+
test_do([[
+
mixed eat_stack(int|void probe)
+
{
+
// Avoid eating as much C-stack by releasing the
+
// catch at every level.
+
if (probe) return 1;
+
if (catch(eat_stack(1))) return 1;
+
mixed err = 1;
+
if ((err = eat_stack()) != 10)
+
return intp(err) && err > 0 ? err + 1 : err;
+
if (err = catch {
+
class Foo
+
{
+
object foo;
+
protected void create(object o) {foo = o;}
+
};
+
Foo foo;
+
for(int i=0; i < 10000; i++)
+
foo = Foo(foo);
+
gc();
+
}) return err;
+
};
+
if (mixed err = eat_stack()) throw (err);
+
]])
+
test_any([[ mapping m=([]); m->self=m; mapping q=(["foo":"bar","gazonk":1]); m->q=q; q+=([]); m=0; gc(); return sizeof(q); ]],2)
-
]])
+
-
ifefun(gc,
-
[[
+
test_eq([[ int dummy; gc(); function f = lambda() { object o = class{}(); int i; return lambda() {return i;}; }(); lambda() {dummy++;}(); // Ensure refcount garbing is done. int n = gc();
pike.git/src/testsuite.in:2032:
object o = Dead(); o->o = Live(); o->o->o = o; gc(); o = 0; return gc() > 0; }]], 1) test_any([[{ class Dead {object o;}; class Live {object o; void destroy() {}}; object o = Live(); o->o = Dead(); o->o->o = o; gc(); o = 0; return gc() > 0; }]], 1)
-
-
]])
-
-
ifefun(gc,
-
[[
-
+
test_any_equal([[{ class Live {object o; void destroy() {}}; array a = set_weak_flag(({Live()}), 1);
-
gc(); return a;
+
gc();
+
return
set_weak_flag(
a
, 0)
;
}]], ({0})) test_any_equal([[{ class Live {object o; void destroy() {}}; multiset l = set_weak_flag((<Live()>), 1);
-
gc(); return l;
+
gc();
+
return
set_weak_flag(
l
, 0)
;
}]], (<>)) test_any_equal([[{ class Live {object o; void destroy() {}}; mapping m = set_weak_flag(([0: Live()]), 1);
-
gc(); return m;
+
gc();
+
return
set_weak_flag(
m
, 0)
;
}]], ([])) test_any_equal([[{ class Live {object o; void destroy() {}}; mapping m = set_weak_flag(([Live(): 0]), 1);
-
gc(); return m;
+
gc();
+
return
set_weak_flag(
m
, 0)
;
}]], ([])) test_any_equal([[{ array a = set_weak_flag(({4711, 0x54325827a124*0x12348795482485425}), 1);
-
gc(); return a;
+
gc();
+
return
set_weak_flag(
a
, 0)
;
}]], ({4711, 0x54325827a124*0x12348795482485425})) test_any_equal([[{ object o = class Live {
-
object
o
;
+
array
g
;
array a = ({17});
-
void create()
{o
=
this
_object();}
+
void create()
{g
=
({this
_object()
})
;}
void destroy() {all_constants()->kablutt = a;} }(); o = 0; gc(); return all_constants()->kablutt; }]], ({17})); test_any([[{ object o = class Live {
-
object
o
;
+
array
g
;
array a = set_weak_flag (({({17})}), 1);
-
void create()
{o
=
this
_object();}
+
void create()
{g
=
({this
_object()
})
;}
void destroy() { if (!equal (a, ({({17})}))) error ("Contents in weak array zapped: %O.\n", a); } }(); o = 0; return gc() >= 3; }]], 1); test_any_equal([[{ object o = class Live {
-
object
o
;
+
array
g
;
array a = set_weak_flag (({({17})}), 1);
-
void create()
{o
=
this
_object();}
+
void create()
{g
=
({this
_object()
})
;}
void destroy() {all_constants()->blatinka = a;} }(); o = 0; gc(); if (!equal (all_constants()->blatinka, ({({17})}))) error ("Contents in saved weak array zapped: %O.\n", all_constants()->blatinka); gc(); return all_constants()->blatinka; }]], ({0}));
-
]]
)
+
test_do(add_constant("kablutt"
)
;)
+
test_do(add_constant("blatinka");)
-
ifefun
(
gc,
-
[[
+
test_any
(
[[{
+
#if constant (_debug)
+
// Temporarily disable debug so we don't get references to p in
+
// the intepreter backlog.
+
int old_debug = _debug (0);
+
#endif
+
object o = class {program p; object o;}();
+
class Resolver (mixed x) {mixed resolv (string id) {return x;}};
+
program p = compile ("constant o = foo;", Resolver (o));
+
o->p = p;
+
o->o = p();
+
gc
();
+
o = p = 0;
+
#if constant (_debug)
+
_debug (old_debug);
+
#endif
+
return gc() > 0;
+
}]]
,
1)
test_any([[{ class Dead {object o;}; object o = Dead(); o->o = Dead(); array a = set_weak_flag(({o}), 1); gc(); o = 0; return gc() > 0; }]], 1) test_any([[{ class Dead {object o;}; class Live {object o; void destroy() {}};
pike.git/src/testsuite.in:2161:
}]], 1); test_any([[{ multiset a = (<>), b = (<a, set_weak_flag ((<a>), 1)>); multiset x = set_weak_flag ((<a>), 1); a[b] = 1; a = b = 0; gc(); return !sizeof (x); }]], 1);
-
]])
-
-
ifefun(gc,
-
[[
-
+
test_any([[{ class Foo {
-
Foo f =
this
_object();
+
array(
Foo
)
f =
({this
_object()
})
;
multiset(Foo) g = set_weak_flag((<this_object()>), 1); }; multiset(Foo) x = set_weak_flag ((<Foo()>), 1); gc(); return !sizeof (x); }]], 1); test_any([[{ class Foo {
-
Foo f =
this
_object();
+
array(
Foo
)
f =
({this
_object()
})
;
multiset(Foo) g = set_weak_flag((<this_object()>), 1); void destroy() {add_constant("beltbent_oblivion", 1);} }; multiset(Foo) x = set_weak_flag ((<Foo()>), 1); gc(); int res = all_constants()->beltbent_oblivion; add_constant("beltbent_oblivion"); return res; }]], 1); test_any([[{
-
+
gc();
array x = set_weak_flag (({0}), 1); x[0] = x; multiset b = set_weak_flag ((<x>), 1); array a = ({17}); b[a] = 1; x = 0;
-
return gc()
+ gc()
>= 1;
+
return gc() >= 1;
}]], 1); test_any([[{
-
+
gc();
array a = set_weak_flag (({0, this_object()}), 1); a[0] = a; a = 0;
-
return gc()
+ gc()
>= 1;
+
return gc() >= 1;
}]], 1); test_any([[{
-
+
gc();
array y = set_weak_flag (({0}), 1), z = set_weak_flag (({y}), 1); y[0] = z; y = z = 0;
-
return gc()
+ gc()
>= 2;
+
return gc() >= 2;
}]], 1); test_any([[{ class Live { array a;
-
object
o
=
this
_object();
+
array
g
=
({this
_object()
})
;
void create() { a = set_weak_flag (({0}), 1); array b = set_weak_flag (({a}), 1); a[0] = b; } void destroy() { if (!arrayp(a) || !arrayp(a[0]) || a[0][0] != a)
-
error
("GC garbed weak things too early.\n");
+
add_constant
("
my_little_error", "
GC garbed weak things too early.\n");
} };
-
+
gc();
object o = Live(); o = 0;
-
return
gc()
+
gc() >= 3;
+
int
res
=
gc() >= 3;
+
if (all_constants()->my_little_error)
+
error (all_constants()->my_little_error);
+
return res;
}]], 1);
-
]])
+
test_do([[{
+
class Live
+
{
+
Foo f;
+
void destroy()
+
{
+
if (!f->l || !f->a || !f->a[0
]
|| !f->a[1
])
+
add_constant ("my_little_error", "GC garbed live things.\n");
+
}
+
};
+
class Foo
+
{
+
int i;
+
class Bar
+
{
+
int j = i++; // Ensure parent pointer.
+
array a = ({j});
+
}
+
Live l;
+
void create (Live _l)
+
{
+
l = _l;
+
l->f = this_object();
+
}
+
array a = allocate (2, Bar)();
+
};
+
object o = Foo(Live());
+
o = 0;
+
gc(), gc();
+
if (all_constants()->my_little_error)
+
error (all_constants()->my_little_error);
+
}]]);
-
ifefun
(
gc,
-
[[
+
test_do
(
[[{
+
object o = compile_string(#"
+
class Foo
+
{
+
int i;
+
class Bar
+
{
+
int j = i++; // Ensure parent pointer.
+
}
+
inherit Bar;
+
}")();
+
o = 0;
+
gc
();
+
}]]);
test_do([[{ mapping a = ([1:({17}),2:3,4:5,6:7,8:9]), b = a + ([]); set_weak_flag (b, 1); gc(); }]]); test_do([[{ mapping a = ([1:({17})]), b = a + ([]); set_weak_flag (b, 1); gc();
pike.git/src/testsuite.in:2277:
mapping a = ([17:({17})]); for (int i = 0; i < 10; i++) a[class{}()] = i; mapping b = a + ([]); set_weak_flag (a, 1); set_weak_flag (b, 1); foreach (indices (a), mixed o) if (objectp (o)) destruct (o); gc(); return !sizeof (a) && !sizeof (b); }]], 1); test_any([[{
-
mapping a = ([17:
({17})
]);
+
mapping a = ([17:
17
]);
set_weak_flag (a, 1); for (int i = 0; i < 10; i++) a[class{}()] = i; mapping b = a + ([]); foreach (indices (a), mixed o) if (objectp (o)) destruct (o); gc(); return sizeof (a) == 1 && sizeof (b) == 1; }]], 1); test_any([[{ mapping a = set_weak_flag (([17: set_weak_flag (({({17})}), 1)]), 1); return gc() >= 2 && !sizeof (a); }]], 1);
-
]])
-
-
ifefun(gc,
-
[[
-
+
test_any([[{ object o = class{}(); mapping a = set_weak_flag ((["foo": o]), 1); gc(); return sizeof (a); }]], 1); test_any([[{ object o = class{}(); mapping a = set_weak_flag (([o: o]), 1); gc();
pike.git/src/testsuite.in:2334:
test_any([[{ object o = class{}(); mapping a = set_weak_flag (([o: class{}()]), 1); return gc() >= 1 && !sizeof (a); }]], 1); test_any([[{ mapping a = set_weak_flag (([class{}(): class{}()]), 1); return gc() >= 2 && !sizeof (a); }]], 1);
-
]])
-
-
ifefun(gc,
-
[[
-
+
test_any([[{ object o = class{}(); mapping a = set_weak_flag ((["foo": o]), 1); destruct (o); gc(); return !sizeof (a); }]], 1); test_any([[{ object o = class{}(); mapping a = set_weak_flag (([o: o]), 1);
pike.git/src/testsuite.in:2387:
return sizeof (a); }]], 1); test_any([[{ object o = class{}(); mapping a = set_weak_flag (([o: class{}()]), 0); destruct (o); gc(); return !sizeof (a); }]], 1);
-
]])
+
test_any_equal([[{
+
array a = set_weak_flag (({1, "foo", 3.14}), 1);
+
gc();
+
return set_weak_flag(a, 0);
+
}
]]
, ({1, "foo", 3.14}
)
);
+
test_any_equal([[{
+
multiset a = set_weak_flag ((<1, "foo", 3.14>), 1);
+
gc();
+
return set_weak_flag(a, 0);
+
}]], (<1, "foo", 3.14>));
+
test_any_equal([[{
+
mapping a = set_weak_flag (([1: 1, "foo": "foo", 3.14: 3.14]), 1);
+
gc();
+
return set_weak_flag(a, 0);
+
}]], ([1: 1, "foo": "foo", 3.14: 3.14]));
-
ifefun(gc,
-
[[
-
+
test_do([[{
-
int got_error = 0;
-
array(string) destruct_order;
-
add_constant ("destructing", lambda (string id) {destruct_order += ({id});});
-
add_constant ("my_error", lambda (string s, mixed... args) {
-
if (!got_error) werror ("\n");
-
werror (s, @args);
-
got_error = 1;
-
});
-
program Dead = compile_string (#"
-
string id;
-
void create (int i) {id = sprintf (\"dead[%d]\", i);}
-
mixed a = 1, b = 1; // Mustn't be zero at destruct time.
-
mixed x, y, z;
-
array v = set_weak_flag (({1}), 1); // Mustn't be zero at destruct time.
-
array w = set_weak_flag (({0, 0}), 1);
-
function(
object
:mixed)
checkfn;
-
void check_live (mapping(object:int) checked) {
-
//werror (\"check_live %s\\n\", id);
-
checked[this_object()]
=
1;
-
if (!a) my_error (id + \"->a got destructed too early.\\n\");
-
else if (!b) my_error (id + \"->b got destructed too early.\\n\");
-
else if (!v[0]) my_error (id + \"->v[0] got destructed too early.\\n\");
-
else if (functionp (checkfn) && !checkfn (this_object()))
-
my_error (id + \"->checkfn failed.\\n\");
-
else {
-
if (objectp (a) && !checked[a]) a->check_live (checked);
-
if (objectp (b) && !checked[b]) b->check_live (checked);
-
if (objectp (x) && !checked[x]) x->check_live (checked);
-
if (objectp (y) && !checked[y]) y->check_live (checked);
-
if (objectp (z) && !checked[z]) z->check_live (checked);
-
if (objectp (v[0]) && !checked[v[0] ]) v[0]->check_live (checked);
-
if (objectp (w[0]) && !checked[w[0] ]) w[0]->check_live (checked);
-
if (objectp (w[1]) && !checked[w[1] ]) w[1]->check_live (checked);
-
}
-
//werror (\"check_live %s done\\n\", id);
-
}
-
");
-
add_constant ("Dead", Dead);
-
program Live = compile_string (#"
-
inherit Dead;
-
void create (int i) {id = sprintf (\"live[%d]\", i);}
-
void destroy() {
-
destructing (id);
-
//werror (\"destroy %s\\n\", id);
-
check_live (([]));
-
}
-
");
-
add_constant ("Live", Live);
-
program LiveNested = compile_string (#"
-
inherit Live;
-
string id = \"live_nested[0]\";
-
void create() {}
-
void check_live_0 (mapping(object:int) checked) {check_live (checked);}
-
class
LiveNested1
+
object
f
= class
{
-
inherit Live;
-
string id
=
\"live_nested[1]\";
-
void create
()
{}
-
void
check
_
live
(
mapping
(
object:int
)
checked
)
{
-
checked[
this_object()
] = 1
;
-
if
(
catch
(check_live_0
(
checked
)
))
-
my_error
(
\"Parent for %s got destructed too early.\\n\", id
);
-
else ::check_live
(
checked
);
-
}
-
void check
_
live_1
(
mapping(object:int) checked) {check_live (checked);}
-
class
LiveNested2
+
object
o
=
class
{}
()
;
+
array
a
=
set
_
weak_flag
((
{o}
)
,
1
)
;
+
object
this
=
this_object();
+
void
create
(
)
{destruct
(
o
)
;}
+
}
();
+
f
=
0;
+
gc
();
+
}
]]);
+
test
_
do
(
[[{
+
object
f
=
class
{
-
inherit Live;
-
string id
=
\"live_nested[2]\";
-
void create
()
{}
-
void check
_
live
(
mapping
(
object
:
int
)
checked
)
{
-
checked[
this_object()
] = 1
;
-
if
(
catch
(check_live_1
(
checked
)
))
-
my_error
(
\"Parent for %s got destructed too early.\\n\", id
);
-
else ::check_live
(
checked
);
-
}
-
}
-
class
LiveNested3
+
object
o
=
class
{}
()
;
+
mapping
m
=
set
_
weak_flag
((
[1
:
o]
)
,
1
)
;
+
object
this
=
this_object();
+
void
create
(
)
{destruct
(
o
)
;}
+
}
();
+
f
=
0;
+
gc
();
+
}
]]);
+
test_do([[{
+
object
f
=
class
{
-
inherit Live;
-
string id
=
\"live_nested[3]\";
-
void create
()
{}
-
void check
_
live
(
mapping
(
object
:
int
)
checked
)
{
-
checked[
this_object()
] = 1
;
-
if
(
catch (check_live_1 (checked
)
))
-
my_error
(
\"Parent for %s got destructed too early.\\n\", id
);
-
else ::check_live (checked);
-
}
-
}
-
}
-
"
);
-
program
DeadNested
=
compile_string (#"
-
inherit Dead;
-
string id = \"dead_nested[
0
]\"
;
-
void create
()
{}
-
void check_live_0 (mapping(object:int
)
checked)
{check
_
live
(
checked);}
-
class
DeadNested1
+
object
o
=
class
{}
()
;
+
mapping
m
=
set
_
weak_flag
((
[o
:
1]
)
,
1
)
;
+
object
this
=
this_object();
+
void
create
(
)
{destruct
(
o
)
;}
+
}
();
+
f
=
0;
+
gc
();
+
}
]]
);
+
test
_
do
([
[{
+
object
f
=
class
{
-
inherit Dead;
-
string id
=
\"dead_nested[1]\";
-
void create()
{}
-
void check_live
(
mapping(object:int
)
checked) {
-
checked[this_object()]
=
1;
-
if (catch (check
_
live
_
0
(
checked)))
-
my_error
(
\"Parent for %s got destructed too early.\\n\"
,
id
);
-
else ::check_live (checked);
-
}
-
void check_live_1 (mapping(
object
:int)
checked)
{check_live (checked);}
-
class DeadNested2
-
{
-
inherit Dead;
-
string id
=
\"dead_nested[2]\";
-
void create() {}
-
void check_live (mapping(object:int) checked) {
-
checked[
this_object()
] = 1
;
-
if
(
catch (check_live_1 (checked
)
))
-
my_error
(
\"Parent for %s got destructed too early.\\n\", id
);
-
else ::check_live (checked);
-
}
-
}
-
class DeadNested3
-
{
-
inherit Dead;
-
string id = \"dead_nested[3]\";
-
void create
()
{}
-
void check_live (mapping(object:int) checked) {
-
checked[this_object()]
=
1
;
-
if
(
catch (check_live_1 (checked
)
))
-
my_error (\"Parent for %s got destructed too early.\\n\", id)
;
-
else ::check_live (checked);
-
}
-
}
-
}
-
"
);
-
add_constant ("destructing");
-
add_constant ("my_error");
-
add_constant ("Dead");
-
add_constant ("Live");
+
object
o
=
class
{}()
;
+
multiset
m
=
set
_
weak
_
flag
(
(<o>
),
1
);
+
object
this
= this_object();
+
void
create
()
{destruct
(
o
);}
+
}()
;
+
f
=
0
;
+
gc
();
+
}
]]
);
-
array(object) live, dead, live
_
nested, dead_nested;
-
array(array) destruct_order_
tests
=
(
{
-
({3, // Wanted number of live objects.
-
0, // Wanted number of dead objects.
-
0, // Wanted live nested objects.
-
0, // Wanted dead nested objects.
-
lambda() { // Function to connect them.
-
live
[
0]->x = live
[
1],
live[0
]
->a = live[2
]
;
-
live
[
1]->x = live
[
0];
-
}}),
-
({2, 2, 0, 0, lambda() {
/
/ 1
-
live[0]->x = live[1], live[0]->a = dead[0];
-
live[1]->x = live[0];
-
dead[0]->a = dead[1];
-
dead[1]->a = dead[0];
-
}}),
-
({1, 2, 0, 0, lambda() { // 2
-
live[0]->a = live[0], live[0]->b = dead[0];
-
dead[0]->a = dead[1];
-
dead[1]->a = dead[0];
-
}}),
-
({0, 3, 0, 0, lambda() { // 3
-
dead[0]->a = dead[1];
-
dead[1]->a = dead[0];
-
dead[2]->a = dead[0], dead[2]->b = dead[2];
-
}}),
-
({3, 0, 0, 0, lambda() { // 4
-
live[0]->a = live[0], live[0]->b = live[1];
-
live[1]->a = live[2];
-
}}),
-
({1, 2, 0, 0, lambda() { // 5
-
live[0]->a = live[0], live[0]->b = dead[0];
-
dead[0]->a = dead[1];
-
}}),
-
({1, 2, 0, 0, lambda() { // 6
-
live[0]->a = live[0], live[0]->b = dead[1];
-
dead[0]->a = dead[0], dead[0]->b = dead[1];
-
dead[1]->a = dead[1];
-
}}),
-
({2, 2, 0, 0, lambda() { // 7
-
live[0]->a = live[0], live[0]->b = live[1];
-
dead[0]->a = dead[0];
-
dead[0]->b = live[1];
-
live[1]->a = dead[1];
-
dead[1]->a = dead[1];
-
}}),
-
({1, 3, 0, 0, lambda() { // 8
-
live[0]->a = live[0], live[0]->b = dead[2];
-
dead[0]->a = dead[0];
-
dead[0]->b = dead[2];
-
dead[2]->a = dead[1];
-
dead[1]->a = dead[1];
-
}}),
-
({3, 1, 0, 0, lambda() { // 9
-
live[0]->a = live[0], live[0]->b = live[1];
-
dead[0]->a = dead[0], dead[0]->b = live[1];
-
live[1]->a = live[2];
-
}}),
-
({1, 3, 0, 0, lambda() { // 10
-
live[0]->a = live[0], live[0]->b = dead[1];
-
dead[0]->a = dead[0], dead[0]->b = dead[1];
-
dead[1]->a = dead[2];
-
}}),
-
({1, 3, 0, 0, lambda() { // 11
-
live[0]->a = live[0], live[0]->b = dead[1];
-
dead[0]->a = dead[0], dead[0]->b = dead[1];
-
dead[1]->a = dead[1], dead[1]->b = dead[2];
-
dead[2]->a = dead[2];
-
}}),
-
({5, 0, 0, 0, lambda() { // 12
-
live[0]->x = live[1];
-
live[1]->x = live[0], live[1]->a = live[2];
-
live[2]->x = live[3];
-
live[3]->x = live[2], live[3]->a = live[4];
-
live[4]->a = live[4];
-
}}),
-
({3, 0, 0, 0, lambda() { // 13
-
live[0]->x = live[1], live[0]->y = live[2];
-
live[1]->x = live[2];
-
live[2]->x = live[0];
-
}}),
-
({2, 0, 0, 0, lambda() { // 14
-
live[0]->a = live[1], live[0]->b = live[0];
-
live[1]->w[0] = live[0];
-
}}),
-
({2, 0, 0, 0, lambda() { // 15
-
live[0]->a = live[0], live[0]->b = live[1];
-
live[1]->w[0] = live[0];
-
}}),
-
({2, 0, 0, 0, lambda() { // 16
-
live[0]->a = live[0], live[0]->w[0] = live[1];
-
live[1]->x = live[0];
-
}}),
-
({3, 0, 0, 0, lambda() { // 17
-
live[0]->a = live[0], live[0]->b = live[1];
-
live[1]->w[0] = live[2];
-
live[2]->a = live[2], live[2]->b = live[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 18
-
live[0]->a = live[1], live[0]->x = live[2];
-
live[1]->w[0] = live[2];
-
live[2]->x = live[0];
-
}}),
-
({4, 0, 0, 0, lambda() { // 19
-
live[0]->x = live[0], live[0]->a = live[1], live[0]->b = live[2];
-
live[1]->a = live[3];
-
live[2]->a = live[3];
-
live[3]->w[0] = live[0];
-
}}),
-
({3, 0, 0, 0, lambda() { // 20
-
live[0]->x = live[1];
-
live[1]->x = live[0], live[1]->a = live[2];
-
live[2]->w[0] = live[1];
-
}}),
-
({4, 0, 0, 0, lambda() { // 21
-
live[0]->w[0] = live[1], live[0]->a = live[3];
-
live[1]->w[0] = live[2];
-
live[2]->a = live[0], live[2]->b = live[3], live[2]->x = live[2];
-
live[3]->a = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 22
-
live[0]->a = dead[0], live[0]->x = live[1];
-
live[1]->x = live[0];
-
dead[0]->w[0] = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 23
-
live[0]->a = live[1], live[0]->b = dead[0];
-
live[1]->w[0] = dead[0];
-
dead[0]->x = live[0];
-
}}),
-
({3, 0, 0, 0, lambda() { // 24
-
live[0]->x = live[0], live[0]->a = live[1], live[0]->b = live[2];
-
live[1]->w[0] = live[0], live[1]->w[1] = live[2];
-
live[2]->a = live[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 25
-
live[0]->a = live[1];
-
live[1]->w[0] = live[2];
-
live[2]->x = live[2], live[2]->a = live[0], live[2]->b = live[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 26
-
live[0]->w[0] = live[1], live[0]->a = live[2];
-
live[1]->x = live[1], live[1]->a = live[0], live[1]->b = live[2];
-
live[2]->w[0] = live[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 27
-
live[0]->w[0] = live[1];
-
live[1]->x = live[1], live[1]->a = live[0], live[1]->b = live[2];
-
live[2]->a = live[0];
-
}}),
-
({3, 0, 0, 0, lambda() { // 28
-
live[0]->a = live[0], live[0]->v[0] = live[1];
-
live[1]->a = live[1], live[1]->v[0] = live[2];
-
live[2]->a = live[2];
-
}}),
-
({2, 2, 0, 0, lambda() { // 29
-
live[0]->x = live[1], live[0]->v[0] = dead[0];
-
live[1]->x = live[0];
-
dead[0]->a = dead[1];
-
dead[1]->a = dead[0];
-
}}),
-
({4, 0, 0, 0, lambda() { // 30
-
live[0]->a = live[1], live[0]->b = live[2], live[0]->v[0] = live[3];
-
live[1]->w[0] = live[0];
-
live[2]->a = live[3];
-
live[3]->w[0] = live[2];
-
}}),
-
({2, 1, 0, 0, lambda() { // 31
-
live[0]->a = dead[0];
-
dead[0]->a = live[0], dead[0]->b = live[1];
-
live[1]->a = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 32
-
live[0]->a = live[0], live[0]->b = dead[0];
-
live[1]->a = dead[0];
-
dead[0]->a = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 33
-
dead[0]->a = live[0];
-
live[0]->a = dead[0], live[0]->b = live[1];
-
live[1]->a = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 34
-
live[0]->a = dead[0];
-
dead[0]->b = live[0], dead[0]->a = live[1];
-
live[1]->a = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 35
-
live[0]->b = live[0], live[0]->a = dead[0];
-
live[1]->a = dead[0];
-
dead[0]->a = live[1];
-
}}),
-
({2, 1, 0, 0, lambda() { // 36
-
dead[0]->a = live[0];
-
live[0]->b = dead[0], live[0]->a = live[1];
-
live[1]->a = live[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 37
-
live[0]->a = live[0], live[0]->v[0] = live[1];
-
live[0]->checkfn = lambda (object o) {
-
return o->v[0]->w[0];
-
};
-
live[1]->w[0] = live[2];
-
live[2]->a = live[1], live[2]->b = live[2];
-
}}),
-
({4, 0, 0, 0, lambda() { // 38
-
live[0]->x = live[1];
-
live[1]->x = live[2];
-
live[2]->x = live[0], live[2]->w[0] = live[3];
-
live[3]->a = live[1], live[3]->b = live[3];
-
}}),
-
({0, 2, 2, 0, lambda() { // 39
-
dead[0]->x = dead[0], dead[0]->a = live
_
nested[0];
-
dead[1]->x = dead[1], dead[1]->a = live_nested[1];
-
live_nested[0]->x = live_nested[1];
-
}}),
-
({0, 2, 2, 0, lambda() { // 40
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
dead[1]->x = dead[1], dead[1]->a = live_nested[1];
-
live_nested[0]->w[0] = live_nested[1];
-
}}),
-
({3, 0, 3, 0, lambda() { // 41
-
live[0]->x = live[0], live[0]->a = live_nested[0];
-
live[1]->x = live[1], live[1]->a = live_nested[2];
-
live[2]->x = live[2], live[2]->a = live_nested[1];
-
live_nested[0]->x = live_nested[2];
-
}}),
-
({4, 0, 4, 0, lambda() { // 42
-
live[0]->x = live[0], live[0]->a = live_nested[0];
-
live[1]->x = live[1], live[1]->a = live_nested[1];
-
live[2]->x = live[2], live[2]->a = live_nested[2];
-
live[3]->x = live[3], live[3]->a = live_nested[3];
-
live_nested[0]->x = live_nested[3];
-
}}),
-
({3, 0, 2, 0, lambda() { // 43
-
live[0]->x = live[0], live[0]->a = live_nested[0];
-
live[1]->x = live[1], live[1]->a = live_nested[1];
-
live_nested[0]->a = live[2];
-
live[2]->x = live_nested[1];
-
}}),
-
({3, 0, 3, 0, lambda() { // 44
-
live[0]->x = live[0], live[0]->a = live_nested[0];
-
live[1]->x = live[1], live[1]->a = live_nested[2];
-
live[2]->x = live[2], live[2]->a = live_nested[1];
-
live_nested[0]->x = live_nested[2];
-
live_nested[1]->a = live[0];
-
}}),
-
({0, 2, 0, 2, lambda() { // 45
-
dead[0]->x = dead[0], dead[0]->a = dead_nested[0];
-
dead[1]->x = dead[1], dead[1]->a = dead_nested[1];
-
dead_nested[0]->x = dead_nested[1];
-
}}),
-
({0, 2, 0, 2, lambda() { // 46
-
dead[0]->x = dead[0], dead[0]->a = dead_nested[0];
-
dead[1]->x = dead[1], dead[1]->a = dead_nested[1];
-
dead_nested[0]->w[0] = dead_nested[1];
-
}}),
-
({3, 0, 0, 3, lambda() { // 47
-
live[0]->x = live[0], live[0]->a = dead_nested[0];
-
live[1]->x = live[1], live[1]->a = dead_nested[2];
-
live[2]->x = live[2], live[2]->a = dead_nested[1];
-
dead_nested[0]->x = dead_nested[2];
-
}}),
-
({4, 0, 0, 4, lambda() { // 48
-
live[0]->x = live[0], live[0]->a = dead_nested[0];
-
live[1]->x = live[1], live[1]->a = dead_nested[1];
-
live[2]->x = live[2], live[2]->a = dead_nested[2];
-
live[3]->x = live[3], live[3]->a = dead_nested[3];
-
dead_nested[0]->x = dead_nested[3];
-
}}),
-
({3, 0, 0, 2, lambda() { // 49
-
live[0]->x = live[0], live[0]->a = dead_nested[0];
-
live[1]->x = live[1], live[1]->a = dead_nested[1];
-
dead_nested[0]->a = live[2];
-
live[2]->x = dead_nested[1];
-
}}),
-
({3, 0, 0, 3, lambda() { // 50
-
live[0]->x = live[0], live[0]->a = dead_nested[0];
-
live[1]->x = live[1], live[1]->a = dead_nested[2];
-
live[2]->x = live[2], live[2]->a = dead_nested[1];
-
dead_nested[0]->x = dead_nested[2];
-
dead_nested[1]->a = live[0];
-
}}),
-
({0, 4, 2, 2, lambda() { // 51
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
dead[1]->x = dead[1], dead[1]->a = live_nested[1];
-
dead[2]->x = dead[2], dead[2]->a = dead_nested[0];
-
dead[3]->x = dead[3], dead[3]->a = dead_nested[1];
-
live_nested[0]->x = dead_nested[1];
-
dead_nested[0]->x = live_nested[1];
-
}}),
-
({4, 0, 0, 0, lambda() { // 52
-
live[0]->w[0] = live[1];
-
live[1]->x = live[1], live[1]->a = live[0], live[1]->b = live[2];
-
live[2]->w[0] = live[3];
-
live[3]->x = live[3], live[3]->a = live[0];
-
}}),
-
({4, 0, 0, 0, lambda() { // 53
-
live[0]->w[0] = live[1];
-
live[1]->x = live[1], live[1]->b = live[0], live[1]->a = live[2];
-
live[2]->w[0] = live[3];
-
live[3]->x = live[3], live[3]->a = live[0];
-
}}),
-
({4, 0, 0, 0, lambda() { // 54
-
live[0]->x = live[0], live[0]->w[0] = live[1];
-
live[1]->w[0] = live[2];
-
live[2]->x = live[2], live[2]->a = live[1], live[2]->b = live[3];
-
live[3]->x = live[3], live[3]->a = live[0];
-
}}),
-
({4, 0, 0, 0, lambda() { // 55
-
live[0]->x = live[0], live[0]->w[0] = live[1];
-
live[1]->w[0] = live[2];
-
live[2]->x = live[2], live[2]->b = live[1], live[2]->a = live[3];
-
live[3]->x = live[3], live[3]->a = live[0];
-
}}),
-
({3, 0, 0, 0, lambda() { // 56
-
live[0]->a = live[2];
-
live[1]->x = live[1], live[1]->a = live[0], live[1]->b = live[2];
-
}}),
-
({3, 0, 0, 0, lambda() { // 57
-
live[0]->a = live[2];
-
live[1]->x = live[1], live[1]->b = live[0], live[1]->a = live[2];
-
}}),
-
({2, 1, 0, 0, lambda() { // 58
-
live[0]->x = live[1], live[0]->y = dead[0];
-
live[0]->checkfn = lambda (object o) {
-
return o->y;
-
};
-
live[1]->x = live[0];
-
dead[0]->x = dead[0];
-
}}),
-
({2, 1, 0, 0, lambda() { // 59
-
live[0]->y = live[1], live[0]->x = dead[0];
-
live[0]->checkfn = lambda (object o) {
-
return o->x;
-
};
-
live[1]->x = live[0];
-
dead[0]->x = dead[0];
-
}}),
-
({1, 2, 0, 2, lambda() { // 60
-
live[0]->x = dead_nested[0], live[0]->y = dead_nested[0];
-
dead[0]->x = dead[0], dead[0]->y = dead_nested[0];
-
dead[1]->x = dead[1], dead[1]->y = dead_nested[1];
-
dead_nested[0]->x = live[0], dead_nested[0]->y = dead_nested[1];
-
}}),
-
({1, 2, 0, 2, lambda() { // 61
-
live[0]->x = dead_nested[0], live[0]->y = dead_nested[0];
-
dead[0]->x = dead[0], dead[0]->y = dead_nested[0];
-
dead[1]->x = dead[1], dead[1]->y = dead_nested[1];
-
dead_nested[0]->y = live[0], dead_nested[0]->x = dead_nested[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 62
-
live[0]->x = live[1];
-
live[1]->x = live[0], live[1]->y = live[2];
-
live[2]->x = live[1];
-
}}),
-
({3, 0, 0, 0, lambda() { // 63
-
live[0]->x = live[1];
-
live[1]->y = live[0], live[1]->x = live[2];
-
live[2]->x = live[1];
-
}}),
-
({2, 0, 2, 0, lambda() { // 64
-
live[0]->x = live[1], live[0]->y = live_nested[1];
-
live[1]->w[0] = live_nested[0];
-
live_nested[0]->y = live[0];
-
}}),
-
({2, 0, 2, 0, lambda() { // 65
-
live[0]->y = live[1], live[0]->x = live_nested[1];
-
live[1]->w[0] = live_nested[0];
-
live_nested[0]->y = live[0];
-
}}),
-
({1, 1, 3, 0, lambda() { // 66
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->x = live[0], live_nested[0]->y = live_nested[2];
-
live[0]->x = live_nested[1];
-
}}),
-
({1, 1, 3, 0, lambda() { // 67
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->y = live[0], live_nested[0]->x = live_nested[2];
-
live[0]->x = live_nested[1];
-
}}),
-
({0, 1, 2, 2, lambda() { // 68
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->y = live_nested[1], live_nested[0]->x = dead_nested[0];
-
live_nested[1]->x = dead_nested[1];
-
dead_nested[0]->x = live_nested[1];
-
}}),
-
({0, 1, 2, 2, lambda() { // 69
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->x = live_nested[1], live_nested[0]->y = dead_nested[0];
-
live_nested[1]->x = dead_nested[1];
-
dead_nested[0]->x = live_nested[1];
-
}}),
-
({0, 1, 2, 2, lambda() { // 70
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->x = live_nested[1], live_nested[0]->y = dead_nested[1];
-
live_nested[1]->x = dead_nested[0];
-
dead_nested[0]->x = live_nested[0];
-
}}),
-
({0, 1, 2, 2, lambda() { // 71
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->y = live_nested[1], live_nested[0]->x = dead_nested[1];
-
live_nested[1]->x = dead_nested[0];
-
dead_nested[0]->x = live_nested[0];
-
}}),
-
({2, 0, 2, 0, lambda() { // 72
-
live[0]->x = live[1];
-
live[1]->x = live_nested[1];
-
live_nested[1]->x = live[0];
-
live_nested[0]->x = live[1];
-
}}),
-
({2, 0, 4, 0, lambda() { // 73
-
live[0]->x = live[1], live[0]->y = live_nested[2], live[0]->z = live_nested[3];
-
live[1]->x = live[0];
-
live_nested[1]->x = live[0];
-
}}),
-
({2, 0, 4, 0, lambda() { // 74
-
live[0]->y = live[1], live[0]->z = live_nested[2], live[0]->x = live_nested[3];
-
live[1]->x = live[0];
-
live_nested[1]->x = live[0];
-
}}),
-
({2, 0, 4, 0, lambda() { // 75
-
live[0]->z = live[1], live[0]->x = live_nested[2], live[0]->y = live_nested[3];
-
live[1]->x = live[0];
-
live_nested[1]->x = live[0];
-
}}),
-
({2, 1, 2, 0, lambda() { // 76
-
dead[0]->x = dead[0], dead[0]->a = live_nested[0];
-
live_nested[0]->y = live_nested[1], live_nested[0]->x = live[1];
-
live_nested[1]->x = live[0];
-
live[0]->x = live_nested[0];
-
live[1]->x = live[0];
-
}}),
-
// ({3, 0, 0, 0, lambda() { // Not possible without weak refs directly in objects
.
-
// live[0]->x = live[0], live[0]->v[0] = live[1]
;
-
// live[1
]
->x = live[1
]
, live[1]->w[0] = live[2];
-
// live[2]->x = live[2], live[2]->a = live[0];
-
// }}
)
,
-
});
+
test
_tests([[
inherit
"
]]
SRCDIR
[[/
test
_
gc
.
pike"
;]])
-
int
quiet
;
-
string testargs=getenv
()
->TESTARGS
;
-
if(
testargs &&
-
(
has_value(testargs/" ", "-
q
"
)
||
-
has
_
value
(
testargs/" "
,
"-quiet"
) ) )
-
quiet=1
;
-
return
1
;
+
test_any([[mapping
q=([
"t":class
{} ()])
;
gc
(); if(
!objectp
(
q
-
>t
)
)
return
-1;
set
_
weak_flag
(
q
,
1
)
;
gc(
)
;
if(objectp(q->t
)
)
return
-2
; return
0
;
]],0);
-
int
test_failed
=
0
;
-
for
(int
test
= 0; test
<
sizeof
(
destruct
_
order
_
tests
);
test++
)
{
-
[
int
nlive
,
int
ndead,
int
nlnested,
int
ndnested,
function
(
void:void
)
setup
]
=
-
destruct
_
order
_
tests
[
test
];
-
int
objs
=
nlive
+ ndead
;
-
array
(
int
)
idx
=
indices
(
allocate
(
objs
));
-
int
n
=
1
;
-
for
(
int
f
=
nlive
+
ndead
;
f
>
1
;
f--
)
n
*
=
f
;
-
if
(
!quiet
)
-
werror
("
GC
destruct
order
test
%d,
%d
permutations
\r"
, test
,
n
);
-
while
(
n--
)
{
-
array
(
int
)
alloc
_
order
=
Array.permute
(
idx
,
n
);
-
array
(
int
)
create
_
order
= (
{}
);
-
live
=
allocate
(
nlive
);
-
dead
=
allocate
(
ndead
);
-
if
(
nlnested
>
=
1
)
{
-
//
Creating
these
before
the
Dead
and
Live
objects
below
assumes
-
//
that
the
gc
will
start
with
the
last
created
object
first
,
so
-
//
the
order
can
be
controlled
with
those
objects
.
-
live
_
nested
= (
{LiveNested
()
}
);
-
if
(
nlnested
>=
2
)
live
_
nested
+
= (
{live_nested
[
0
]
->LiveNested1
()
}
);
-
if
(
nlnested
>
=
3
)
live
_
nested
+
= (
{live_nested
[
1
]->
LiveNested2
()});
-
if
(
nlnested
>
=
4
)
live
_
nested
+
= (
{live_nested
[1]
->LiveNested3
()});
+
test_do([[class
bar
{
object
foo; void create(void|object tmp) { foo
=
tmp;
} }
;
+
object o=bar
(
),o2=o;
+
for(
int
e=0;e<10000;e++)
o
=
bar(o);
+
o2->foo=o;
+
o=o2=
0;
+
gc();
+
]])
+
+
test
_any([[
+
object o = class{}
(
);
+
mapping m = set
_
weak
_
flag (([o: "x"]
)
, Pike.WEAK_INDICES)
;
+
gc(
)
;
+
return sizeof (m);
+
]],
1)
+
test_any([[
+
object o = class{}();
+
mapping m = set_weak_flag ((
[
o:
"x"])
,
Pike.WEAK_VALUES);
+
gc();
+
return sizeof
(
m
)
;
+
]
],
1)
+
test_any([[
+
object o
=
class{}();
+
mapping
m
=
set
_
weak
_
flag ((
[
"x": o
]
), Pike.WEAK_INDICES)
;
+
gc();
+
return
sizeof
(m)
;
+
]],
1)
+
test_any([[
+
object o = class{}
()
;
+
mapping m
=
set_weak_flag
(
(["x":
o]), Pike.WEAK_VALUES);
+
gc
()
;
+
return sizeof (m
);
+
]],
1)
+
test_any([[
+
mapping m
=
set_weak_flag (([class{}(): "x"]), Pike.WEAK_INDICES)
;
+
gc();
+
return sizeof
(
m);
+
]], 0)
+
test_any([[
+
mapping m
=
set_weak_flag
(([class{}():
"x"]), Pike.WEAK_VALUES)
;
+
gc()
;
+
return sizeof (m
)
;
+
]], 1)
+
test_any([[
+
mapping m
=
set_weak_flag ((["x": class{}()]), Pike.WEAK_INDICES)
;
+
gc();
+
return sizeof
(
m
)
;
+
]],
1)
+
test_any([[
+
mapping m = set_weak_flag
(
([
"
x":
class{}()]),
Pike.WEAK_VALUES);
+
gc();
+
return
sizeof
(m);
+
]]
,
0)
+
test
_any([[
+
object o = class{}(
);
+
mapping
m
=
set_weak_flag
(
([o: o]
)
,
Pike.WEAK_INDICES);
+
o
=
0;
+
gc
()
;
+
return sizeof (m);
+
]], 1)
+
test
_
any([[
+
object o
=
class{}();
+
mapping m = set_weak_flag
(
([o: o])
,
Pike.WEAK_VALUES
);
+
o
=
0;
+
gc
()
;
+
return sizeof (m);
+
]], 1)
+
test
_
any([[
+
object o
=
class{}
();
+
mapping
m
=
set_weak_flag
(([o:
o]), Pike.WEAK);
+
o
=
0;
+
gc
();
+
return
sizeof
(m);
+
]],
0)
+
test_any([[
+
object o
=
class{}();
+
mapping m = set_weak_flag
(
([o: "x"]
)
, Pike.WEAK_INDICES)
;
+
destruct
(o);
+
gc
(
);
+
return sizeof (m);
+
]], 0)
+
test_any([[
+
object o
=
class{}(
)
;
+
mapping m = set_weak_flag (([o: "x"]), Pike.WEAK_VALUES);
+
destruct
(o);
+
gc();
+
return
sizeof
(m);
+
]],
0)
+
test_any([[
+
object
o
=
class{}();
+
mapping
m
= ([o: "x"]);
+
destruct (o);
+
gc
();
+
return
sizeof
(m);
+
]]
,
0)
+
test_any([[
+
object
o
=
class{}();
+
mapping
m
=
set_weak_flag
((["x":
o]), Pike
.
WEAK_INDICES);
+
destruct
(o);
+
gc();
+
return sizeof (m);
+
]], 1)
+
test
_
any([[
+
object o
=
class{}
(
);
+
mapping m = set_weak_flag
(
(["x": o]
)
, Pike.WEAK_VALUES
);
+
destruct
(o);
+
gc();
+
return sizeof
(
m);
+
]], 0
)
+
test
_
any([[
+
object o
=
class{}
(
);
+
mapping m = (
[
"x": o
]
);
+
destruct
(
o
)
;
+
gc(
);
+
return
sizeof
(m);
+
]],
1)
+
+
test_do
(
[[
+
mapping m
=
set_weak_flag (([]
)
,
Pike.WEAK
_
INDICES);
+
object o
=
class {object o;}
(
);
+
m
[
o
]
= ({1});
+
o
->
o = o;
+
o = 0;
+
gc
()
;
+
]])
+
+
test_do([[
+
mapping m = set_weak_flag (([]), Pike.WEAK_INDICES);
+
object o = class {object o;
}
(
);
+
m[o]
=
({1});
+
array
a = set_weak_flag
(
({class
(object o) {} (o)}), 1);
+
o
=
0;
+
gc(
)
;
+
]])
+
+
test
_
any([[
+
return class {
+
mapping x;
+
int test()
+
{
+
object o
=
class {
+
mapping a =
([1
: this_object()
]
);
+
void destroy
()
{x = a;
}
+
}(
);
+
o = 0;
+
gc();
+
return x && !x[1];
}
-
if
(
ndnested
>=
1)
{
-
dead_nested
=
(
{DeadNested(
)
});
-
if
(ndnested
>
=
2)
dead_nested
+
= (
{dead
_
nested[0]->DeadNested1
()
}
);
-
if
(ndnested
>=
3
)
dead_nested
+
= (
{dead_nested[1]->DeadNested2(
)
})
;
-
if
(ndnested
>=
4
)
dead_nested
+
=
(
{dead_nested[1]-
>
DeadNested3(
)
}
);
+
}()->test();
+
]],
1)
+
test_any
(
[[
+
return class
{
+
multiset
x;
+
int test
()
+
{
+
object o
=
class
{
+
multiset a
= (
<this
_
object
()
>
);
+
void destroy
(
)
{x
=
a;}
+
}(
)
;
+
o
=
0;
+
gc
();
+
return
x
&&
!sizeof
(
indices
(x
+ (
<
>))
)
;
}
-
for
(
int
i
=
0;
i
<
objs
;
i++
) {
-
int
p
=
alloc
_
order[i]
;
-
if
(p
<
nlive
)
live[p]
=
Live
(p),
create_order
+=
(
{p}
);
-
else
p
-=
nlive,
dead[p]
=
Dead
(
p
)
,
create_order
+=
({-p
-
1})
;
+
}()->test();
+
]],
1)
+
test_any
(
[[
+
return
class
{
+
array x
;
+
int test(
)
+
{
+
object
o
=
class
{
+
array a
=
({this
_
object()})
;
+
void
destroy(
)
{x
=
a;}
+
}
();
+
o
=
0;
+
gc
()
;
+
return x && !x[0]
;
}
-
destruct_order = ({""
}
); // Using
(
{}
)
would alloc a new array in destructing
()
.
-
setup(
)
;
-
live = dead = live
_
nested = dead_nested = 0;
-
int garbed = gc
(
) + gc(); // Second gc to garb live object leftovers.
-
destruct_order = destruct_order[1..];
-
if
(
!got_error
&&
(got_error
= sizeof
(
destruct_order
)
!= nlive + nlnested))
-
werror ("\nGC should garb %d live objects, "
-
"but took %d.\n", nlive + nlnested, sizeof (destruct_order))
;
-
if
(
!got_error && (got_error = garbed < 3 * (objs + nlnested + ndnested
)
))
-
werror ("\nGC should garb at least %d things, "
-
"but took only %d.\n", 3 * (objs + nlnested + ndnested), garbed);
-
if (got_error)
{
-
werror
("Create
order
was:
"
+
-
map
(
create
_
order, lambda
(
int i
)
{
-
if
(
i < 0
)
return
"dead["
+ (-i - 1) + "]"
;
-
else return "live[" + i + "]";
-
})
* ", " + "\n"
-
"Destruct order was: " + destruct_order * ", " + "\n")
;
-
test_failed
=
1
;
-
got_error = 0
;
-
break
;
+
}()
->test
()
;
+
]],
1
)
+
test
_
any
(
[[
+
return
class
{
+
class
Obj
(
object
o)
{void
destroy
()
{}}
+
Obj
x
;
+
int
test
()
+
{
+
object
o
=
class
{
+
Obj
a
=
Obj
(
this
_
object
()
);
+
void
destroy
()
{x
=
a
;
}
+
}
(
);
+
o
=
0
;
+
gc()
;
+
return
!x
;
}
-
+
}()->test();
+
]], 1)
+
test_any([[
+
return class {
+
class Obj (object o) {}
+
Obj x;
+
int test()
+
{
+
object o = class {
+
Obj a = Obj (this_object());
+
void destroy() {x = a;}
+
}();
+
o = 0;
+
gc();
+
return x && !x->o;
}
-
}
-
if
(
test_failed
)
error ("GC destruct order
test
failed.\n");
-
werror
(
"%60s\r", ""
);
-
}
]])
+
}()
->
test();
+
]]
, 1
)
-
+
// Pike.count_memory
+
test_do([[
+
add_constant ("count_memory_stats",
+
lambda (int|mapping opts, mixed... things) {
+
if (intp (opts))
+
opts = (["lookahead": opts, "collect_stats": 1]);
+
else
+
opts += (["collect_stats": 1]);
+
Pike.count_memory (opts, @things);
+
return sprintf ("i:%d,c:%d,e:%d,v:%d,r:%d,rnd:%d",
+
opts->internal, opts->cyclic, opts->external,
+
opts->visits, opts->revisits, opts->rounds);
+
})
]])
-
+
// time(1) is used below to avoid constants with extra refs.
+
test_true([[Pike.count_memory (-1) == 0]])
+
test_true([[Pike.count_memory (-1, ({})) > 0]])
+
test_true([[Pike.count_memory (-1, ({time(1)})) > 0]])
+
test_true([[Pike.count_memory (-1, (<>)) > 0]])
+
test_true([[Pike.count_memory (-1, (<time(1)>)) >
+
Pike.count_memory (-1, (<>))]])
+
test_true([[Pike.count_memory (-1, (<time(1)>)) >
+
Pike.count_memory (-1, (<1>))]])
+
test_true([[Pike.count_memory (-1, ([])) > 0]])
+
test_true([[Pike.count_memory (-1, ([1: time(1)])) >
+
Pike.count_memory (-1, ([]))]])
+
test_true([[Pike.count_memory (-1, ([1: time(1)])) >
+
Pike.count_memory (-1, ([1: 2]))]])
+
test_true([[Pike.count_memory (-1, class {}) > 0]])
+
test_true([[Pike.count_memory (-1, class {float f;}) >
+
Pike.count_memory (-1, class {})]])
+
test_true([[Pike.count_memory (-1, class {constant f = 0.0;}) >
+
Pike.count_memory (-1, class {})]])
+
test_true([[Pike.count_memory (-1, class {}()) > 0]])
+
test_true([[Pike.count_memory (-1, class {float f;}()) >
+
Pike.count_memory (-1, class {}())]])
+
test_true([[Pike.count_memory (-1, class {constant f = 0.0;}()) ==
+
Pike.count_memory (-1, class {}())]])
+
test_true([[Pike.count_memory (-1, "foo") > 0]])
+
test_true([[Pike.count_memory (-1, typeof (map)) > 0]])
+
test_true([[Pike.count_memory (-1, 17) == 0]])
+
test_true([[Pike.count_memory (-1, ({"some string with no other ref in memory "+
+
Standards.UUID.make_version4()->str()})) ==
+
Pike.count_memory (-1, ({""}))]])
+
test_true([[Pike.count_memory (0, ({"some string with no other ref in memory " +
+
Standards.UUID.make_version4()->str()})) >
+
Pike.count_memory (0, ({""}))]])
+
test_true([[Pike.count_memory (-1, ({time(1)})) +
+
Pike.count_memory (-1, ([1: time(1)])) ==
+
Pike.count_memory (0, ({([1: time(1)])}))]])
+
test_true([[Pike.count_memory (0, class X {mapping(X:array(int)) x;}) >
+
Pike.count_memory (0, class Y {int x;})]])
+
test_true([[Pike.count_memory (0, ({compile (
+
"constant x = ([1: " + time(1) +
+
"]);")})) >
+
Pike.count_memory (0, ({([1: time(1)])}))]])
+
test_eq([[count_memory_stats (-1, ({time(1)}))]],
+
[["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_eq([[count_memory_stats (-1, (<time(1)>))]],
+
[["i:1,c:0,e:0,v:2,r:0,rnd:1"]])
+
test_eq([[count_memory_stats (-1, ([1: time(1)]))]],
+
[["i:1,c:0,e:0,v:2,r:0,rnd:1"]])
+
test_eq([[count_memory_stats (-1, class {float f;})]],
+
[["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_eq([[count_memory_stats (-1, class {float f;}())]],
+
[["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_eq([[count_memory_stats (-1, "foo")]],
+
[["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_eq([[count_memory_stats (-1, typeof(all_constants()))]],
+
[["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_any([[
+
array a1 = ({({time(1)})}), a2 = ({a1[0]});
+
return Pike.count_memory (0, a1, a2) >
+
Pike.count_memory (0, a1) + Pike.count_memory (0, a2);
+
]], 1)
+
test_any([[
+
mapping m = ([1: time(1)]);
+
return Pike.count_memory (0, ({m})) == Pike.count_memory (0, ({0}));
+
]], 1)
+
test_any([[
+
array a = ({([1: time(1)])});
+
return Pike.count_memory (0, a) > Pike.count_memory (0, ({([])}));
+
]], 1)
+
test_any([[
+
program p = class {};
+
return Pike.count_memory (0, p) > Pike.count_memory (0, p());
+
]], 1)
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X());
+
return count_memory_stats (0, o);
+
]], [["i:2,c:0,e:0,v:2,r:0,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o;
+
return count_memory_stats (0, o);
+
]], [["i:3,c:0,e:0,v:3,r:0,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
return count_memory_stats (2, o);
+
]], [["i:3,c:2,e:0,v:7,r:4,rnd:2"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
return count_memory_stats (1, o);
+
]], [["i:1,c:0,e:1,v:3,r:1,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
int size = Pike.count_memory (0, o);
+
o->a->a->a = o->a;
+
return Pike.count_memory ((["lookahead": 2]), o) == size;
+
]], 1)
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
return count_memory_stats ((["block_objects": 1]), o);
+
]], [["i:3,c:0,e:0,v:3,r:0,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
return count_memory_stats ((["lookahead": 2, "block_objects": 1]), o);
+
]], [["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
X r = o->a->a;
+
return count_memory_stats (10, o);
+
]], [["i:1,c:0,e:2,v:7,r:4,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
X r = o->a->a;
+
return count_memory_stats (2, o);
+
]], [["i:1,c:0,e:2,v:7,r:4,rnd:1"]])
+
test_any([[
+
class X (void|object a) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
X r = o->a;
+
return count_memory_stats (2, o);
+
]], [["i:1,c:0,e:2,v:5,r:2,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
return count_memory_stats (1, o);
+
]], [["i:1,c:0,e:1,v:3,r:1,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
return count_memory_stats (2, o);
+
]], [["i:6,c:5,e:0,v:19,r:13,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
X p = o->a->a->a->a;
+
return count_memory_stats (2, o);
+
]], [["i:1,c:0,e:5,v:17,r:11,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {constant pike_cycle_depth = 2;};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
return count_memory_stats (0, o);
+
]], [["i:6,c:5,e:0,v:19,r:13,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {constant pike_cycle_depth = 1;};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
return count_memory_stats (0, o);
+
]], [["i:1,c:0,e:1,v:3,r:1,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {constant pike_cycle_depth = 0;};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
return count_memory_stats (2, o);
+
]], [["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {constant pike_cycle_depth = 2;};
+
X o = X (X (X (X (X (X ())))));
+
o->a->b = o;
+
o->a->a->b = o->a;
+
o->a->a->a->b = o->a->a;
+
o->a->a->a->a->b = o->a->a->a;
+
o->a->a->a->a->a->b = o->a->a->a->a;
+
return count_memory_stats ((["block_pike_cycle_depth": 1]), o);
+
]], [["i:1,c:0,e:0,v:1,r:0,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {constant pike_cycle_depth = 4;};
+
class Y (void|object a) {constant pike_cycle_depth = 0;};
+
X o = X (X(), X());
+
o->a->a = o->b;
+
o->b->a = o->a;
+
o->a->b = o->b->b = Y (Y());
+
return count_memory_stats (0, o);
+
]], [["i:5,c:2,e:0,v:8,r:3,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {constant pike_cycle_depth = 4;};
+
class Y (void|object a) {constant pike_cycle_depth = 0;};
+
X o = X (X(), X());
+
o->a->a = o->b;
+
o->b->a = o->a;
+
o->a->b = o->b->b = Y (Y());
+
o->a->b->a->a = o->a->b;
+
return count_memory_stats (0, o);
+
]], [["i:3,c:2,e:0,v:6,r:3,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
X o2 = X();
+
o->b = o2;
+
o2->a = o->a->a;
+
o2 = 0;
+
return count_memory_stats (2, o);
+
]], [["i:4,c:2,e:0,v:7,r:3,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X (X()));
+
o->a->a->a = o->a;
+
X o2 = X();
+
o->b = o2;
+
o2->a = o->a->a;
+
return count_memory_stats (2, o);
+
]], [["i:1,c:0,e:3,v:9,r:5,rnd:1"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X(), X());
+
o->a->b = o->b;
+
o->b->a = o->a;
+
o->a->a = o->b->b = X();
+
return count_memory_stats (2, o);
+
]], [["i:4,c:3,e:0,v:8,r:4,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X(), X());
+
o->a->b = o->b;
+
o->b->a = o->a;
+
X o2 = X (X(), X());
+
o2->a->b = o2->b;
+
o2->b->a = o2->a;
+
o2->a->a = o2->b->b = X();
+
o->a->a = o->b->b = o2;
+
o2 = 0;
+
return count_memory_stats (1, o);
+
]], [["i:7,c:6,e:0,v:15,r:8,rnd:2"]])
+
test_any([[
+
class X (void|object a, void|object b) {};
+
X o = X (X(), X());
+
o->a->b = o->b;
+
o->b->a = o->a;
+
X o2 = X (X(), X());
+
o2->a->b = o2->b;
+
o2->b->a = o2->a;
+
o2->a->a = o2->b->b = X();
+
o->a->a = o->b->b = o2;
+
o2 = o2->b;
+
mapping m = (["lookahead": 1,
+
"collect_stats": 1,
+
"collect_direct_externals": 1]);
+
Pike.count_memory (m, o);
+
//werror ("%O\n", m);
+
return m->internal == 4 && m->cyclic == 3 && m->external == 3 &&
+
equal (m->collect_direct_externals, ({o2}));
+
]], 1)
+
test_any([[
+
mixed r = ([]), p = r;
+
p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = 0;
+
return count_memory_stats (1, r);
+
]], [["i:1,c:0,e:1,v:6,r:2,rnd:1"]])
+
test_any([[
+
mixed r = ([]), p = r;
+
p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = 0;
+
return count_memory_stats (2, r);
+
]], [["i:6,c:5,e:0,v:38,r:26,rnd:2"]])
+
test_any([[
+
mixed r = ([]), p = r;
+
p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = p->next; p->next = ([]); p->next->prev = p;
+
p = 0;
+
return Pike.count_memory ((["lookahead": 2, "return_count": 1]), r);
+
]], 6)
+
test_any([[
+
class X (void|array|object a, void|array|object b) {};
+
array a = ({X (X())});
+
object o = a[0];
+
o->a->a = o; o->b = ({X (X())}); o = o->b[0];
+
o->a->a = o; o->b = ({X (X())}); o = o->b[0];
+
o->a->a = o; o->b = ({X (X())}); o = o->b[0];
+
o->a->a = o; o->b = ({X (X())}); o = o->b[0];
+
o->a->a = o; o = 0;
+
return count_memory_stats ((["lookahead": 2, "block_arrays": 1]), a);
+
]], [["i:15,c:10,e:0,v:35,r:20,rnd:6"]])
+
test_any([[
+
class X (void|array|object a, void|array|object b) {};
+
array a = ({X (X())});
+
object o = a[0];
+
o->a->a = o; o->a->b = ({X (X())}); o = o->a->b[0];
+
o->a->a = o; o->a->b = ({X (X())}); o = o->a->b[0];
+
o->a->a = o; o->a->b = ({X (X())}); o = o->a->b[0];
+
o->a->a = o; o->a->b = ({X (X())}); o = o->a->b[0];
+
o->a->a = o; o = 0;
+
return count_memory_stats ((["lookahead": 2, "block_arrays": 1]), a);
+
]], [["i:15,c:10,e:0,v:35,r:20,rnd:6"]])
+
test_true([[Pike.count_memory (Int.NATIVE_MAX, ({master()})) ==
+
Pike.count_memory (-1, ({0}))]])
+
test_any([[
+
mapping m = (["lookahead": Int.NATIVE_MAX,
+
"block_programs": 0,
+
"collect_stats": 1]);
+
Pike.count_memory (m, master());
+
return m->rounds;
+
]], 2)
+
test_true([[Pike.count_memory (-1, Int.NATIVE_MAX + 1) >
+
Pike.count_memory (-1, 17)]])
+
test_true([[Pike.count_memory (-1, Int.NATIVE_MAX << 100) >
+
Pike.count_memory (-1, Int.NATIVE_MAX + 1)]])
+
test_do([[add_constant("count_memory_stats")]])
-
ifefun
(
gc,
-
[[
+
test_program
([[
+
function ff()
+
{
+
array x;
+
array b() {return x;};
+
x = ({b});
+
return b;
+
}
-
test_any([[mapping
q=
(
[ "t":class {} (
)
]); gc(); if(!objectp(q->t)) return -1; set_weak_flag(q,1); gc(); if(objectp(q->t)) return -2; return 0;]],0);
-
-
test_do([[class bar
{
object foo; void create(void|object tmp) { foo=tmp; } };
-
object o
=
bar
()
,o2=o
;
-
for
(
int e=
0
;e<10000;e++)
o=bar
(
o
);
-
o2->foo
=
o;
-
o=o2=
0;
+
int
a
()
+
{
+
function
f
=
ff
();
+
int
s
=
Pike.count_memory
(0
,
f
()
)
;
+
f
= 0;
gc();
-
+
return s > 0;
+
}
]])
-
]])
+
-
cond
([[
sizeof(
cpp
(
"
__
AUTO
_
BIGNUM
__
"
)
/"
__
AUTO
_
BIGNUM
__
"
) == 1 ]]
,
-
[[
+
// Numerical limits.
+
test_true
([[
Int.NATIVE_MIN
<= -2147483648]])
+
test_true
(
[[Int.NATIVE_MAX
>= 2147483647]])
+
test_true
(
[[Float.DIGITS
_
10 >= 6]])
+
test
_
true([[Float.MIN
_
10
_
EXP <= -37]]
)
+
test
_
true([[Float.MAX
_
10
_
EXP >= 37]])
+
test
_
true([[Float.MIN <= 1e-37]])
+
test
_
true([[Float.MAX
>= 1e37]]
)
+
test_true([[Float.EPSILON
<
=
1e-5]])
+
test_true([[1 <
= 1
.0]])
+
test_true([[1
>= 1.0
]]
)
+
test_true(
[[
1.0 <= 1]])
+
test_true([[1.0 >= 1]])
+
// Test the lexer. test_eq("2147483648", [[ (string)0x80000000 ]]) test_eq("2147483649", [[ (string)0x80000001 ]]) test_eq("-2147483648", [[ (string)-0x80000000 ]]) test_eq("-2147483649", [[ (string)-0x80000001 ]]) test_eq("2147483648", [[ (string)-(-0x80000000) ]]) test_eq("2147483649", [[ (string)-(-0x80000001) ]])
-
+
test_eq("9223372036854775808", [[ (string)0x8000000000000000 ]])
+
test_eq("9223372036854775809", [[ (string)0x8000000000000001 ]])
+
test_eq("-9223372036854775808", [[ (string)-0x8000000000000000 ]])
+
test_eq("-9223372036854775809", [[ (string)-0x8000000000000001 ]])
+
test_eq("9223372036854775808", [[ (string)-(-0x8000000000000000) ]])
+
test_eq("9223372036854775809", [[ (string)-(-0x8000000000000001) ]])
test_eq("123456789123456789", [[ (string)123456789123456789 ]]) test_eq("-123456789123456789", [[ (string)-123456789123456789 ]]) test_eq("335812727629498640265", [[ (string)0x123456789123456789 ]]) test_eq("-335812727629498640265", [[ (string)-0x123456789123456789 ]]) test_eq("718046312823", [[ (string)012345671234567 ]]) test_eq("-718046312823", [[ (string)-012345671234567 ]]) test_eq("1125899906842624", [[ (string)0b100000000000000000000000000000000000000000000000000 ]]) test_eq("-1125899906842624", [[ (string)-0b100000000000000000000000000000000000000000000000000 ]])
-
+
test_eq(500000000 * 10, 5000000000)
+
test_eq(5000000000000000000 * 10, 50000000000000000000)
-
//
These
numbers
should
be
ordinary
integers.
-
test
_false([[
objectp(-0x80000000)
]])
-
test_
false
([[
objectp
(
-0x7fffffff
) ]])
-
test_
false
([[
objectp
(
0x7fffffff
) ]])
+
//
Numbers
that
shouldn't
be
native
integers.
Has to resort to
+
//
strange
methods to
test
this
since bignums behave like native
+
//
integers
in almost every way.
+
test_
do
([[
_next
(
(mixed
)
Int.NATIVE_MAX + 1)
]])
+
test_
do
([[
_next
(
(mixed)
Int.NATIVE_MIN - 1
) ]])
-
+
// These numbers should be native integers.
+
test_eval_error([[ _next ((mixed) -0x80000000) ]])
+
test_eval_error([[ _next ((mixed) -0x7fffffff) ]])
+
test_eval_error([[ _next ((mixed) 0x7fffffff) ]])
+
test_eval_error([[ _next ((mixed) Int.NATIVE_MAX) ]])
+
test_eval_error([[ _next ((mixed) Int.NATIVE_MIN) ]])
+
// Test incrementations (FIXME: More cases?). test_eq("2147483648", [[ (string)(class { int f(int x) { x++; return x; } })()->f(0x7fffffff) ]]) test_eq("2147483648", [[ (string)(class { int f(int x) { ++x; return x; } })()->f(0x7fffffff) ]]) test_eq("2147483648", [[ (string)(class { int x=0x7fffffff;int f() { ++x;return x; } })()->f() ]]) test_eq("2147483648", [[ (string)(class { int x=0x7fffffff;int f() { x++;return x; } })()->f() ]]) test_eq("2147483648", [[ (string)(class { int f() { int x=0x7fffffff;++x;return x; } })()->f() ]]) test_eq("2147483648", [[ (string)(class { int f() { int x=0x7fffffff;x++;return x; } })()->f() ]])
-
+
test_eq("9223372036854775808",
+
[[ (string)(class { int f(int x) { x++; return x; } })()->f(0x7fffffffffffffff) ]])
+
test_eq("9223372036854775808",
+
[[ (string)(class { int f(int x) { ++x; return x; } })()->f(0x7fffffffffffffff) ]])
+
test_eq("9223372036854775808",
+
[[ (string)(class { int x=0x7fffffffffffffff;int f() { ++x;return x; } })()->f() ]])
+
test_eq("9223372036854775808",
+
[[ (string)(class { int x=0x7fffffffffffffff;int f() { x++;return x; } })()->f() ]])
+
test_eq("9223372036854775808",
+
[[ (string)(class { int f() { int x=0x7fffffffffffffff;++x;return x; } })()->f() ]])
+
test_eq("9223372036854775808",
+
[[ (string)(class { int f() { int x=0x7fffffffffffffff;x++;return x; } })()->f() ]])
// Test decrementations (FIXME: More cases?). test_eq("-2147483649", [[ (string)(class { int f(int x) { x--; return x; } })()->f(-0x80000000) ]]) test_eq("-2147483649", [[ (string)(class { int f(int x) { --x; return x; } })()->f(-0x80000000) ]]) test_eq("-2147483649", [[ (string)(class { int x=-0x80000000;int f() { --x;return x; } })()->f()]]) test_eq("-2147483649", [[ (string)(class { int x=-0x80000000;int f() { x--;return x; } })()->f()]]) test_eq("-2147483649", [[ (string)(class { int f() { int x=-0x80000000;--x;return x; } })()->f()]]) test_eq("-2147483649", [[ (string)(class { int f() { int x=-0x80000000;x--;return x; } })()->f()]])
-
+
test_eq("-9223372036854775809",
+
[[ (string)(class { int f(int x) { x--; return x; } })()->f(-0x8000000000000000) ]])
+
test_eq("-9223372036854775809",
+
[[ (string)(class { int f(int x) { --x; return x; } })()->f(-0x8000000000000000) ]])
+
test_eq("-9223372036854775809",
+
[[ (string)(class { int x=-0x8000000000000000;int f() { --x;return x; } })()->f()]])
+
test_eq("-9223372036854775809",
+
[[ (string)(class { int x=-0x8000000000000000;int f() { x--;return x; } })()->f()]])
+
test_eq("-9223372036854775809",
+
[[ (string)(class { int f() { int x=-0x8000000000000000;--x;return x; } })()->f()]])
+
test_eq("-9223372036854775809",
+
[[ (string)(class { int f() { int x=-0x8000000000000000;x--;return x; } })()->f()]])
test_encode(1<<99);
-
]])
+
-
cond([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]],
-
[[
+
// - Left shift. test_eq("1073741824", [[ (string)(1<<30) ]]) test_eq("2147483648", [[ (string)(1<<31) ]]) test_eq("4294967296", [[ (string)(1<<32) ]]) test_eq("8589934592", [[ (string)(1<<33) ]]) test_eq("1267650600228229401496703205376", [[ (string)(1<<100) ]])
-
+
test_eval_error(return 1<<100000000000000000000)
+
test_eval_error(return (-1)<<100000000000000000000)
+
test_eq(0<<100000000000000000000, 0)
+
test_eval_error(return 100000000000000000000<<100000000000000000000)
+
test_eval_error(return (-100000000000000000000)<<100000000000000000000)
+
// - Right shift. test_eq("53265209898187398182", [[ (string)((int)"54543574935743895738479">>10) ]]) test_false([[ objectp((int)"54543574935743895738479">>60) ]]) test_eq(0, [[ 25>>30 ]]) test_eq(0, [[ 25>>31 ]]) test_eq(0, [[ 25>>32 ]]) test_eq(0, [[ 25>>33 ]])
-
+
test_eq(1>>100000000000000000000, 0)
+
test_eq(-1>>100000000000000000000, -1)
+
test_eq(0>>100000000000000000000, 0)
+
test_eq(100000000000000000000>>100000000000000000000, 0)
+
test_eq((-100000000000000000000)>>100000000000000000000, -1)
+
// - abs. test_eq("2147483648", [[ (string)abs(-0x80000000) ]]) test_eq("2147483648", [[ (string)abs(0x80000000) ]]) test_eq("2147483649", [[ (string)abs(0x80000001) ]]) test_eq("2147483649", [[ (string)abs(-0x80000001) ]])
-
+
test_eq("9223372036854775808", [[ (string)abs(-0x8000000000000000) ]])
+
test_eq("9223372036854775808", [[ (string)abs(0x8000000000000000) ]])
+
test_eq("9223372036854775809", [[ (string)abs(0x8000000000000001) ]])
+
test_eq("9223372036854775809", [[ (string)abs(-0x8000000000000001) ]])
// - Add. test_eq("2147483648", [[ (string)(0x7fffffff + 1) ]]) test_eq("2147483649", [[ (string)(0x7fffffff + 2) ]])
-
+
test_eq("-2147483648", [[ (string)((-0x80000001) + 1) ]])
+
test_eq("9223372036854775808", [[ (string)(0x7fffffffffffffff + 1) ]])
+
test_eq("9223372036854775809", [[ (string)(0x7fffffffffffffff + 2) ]])
+
test_eq("-9223372036854775808", [[ (string)((-0x8000000000000001) + 1) ]])
test_eq("2684354560", [[ (string)(0x50000000 + 0x50000000) ]]) test_eq("-2684354560", [[ (string)((-0x50000000) + (-0x50000000)) ]])
-
test_eq("-2147483648", [[ (string)((-0x80000001) + 1) ]])
+
test_false([[ objectp((-0x80000001) + 1) ]]) // - Add-eq. test_eq([[lambda() { int a=0x100000000; int b = a; a += 1; return b+a; }()]], [[0x200000001]]) // - Sub. test_eq("-2147483648", [[ (string)(-0x7fffffff - 1) ]]) test_eq("-2147483649", [[ (string)(-0x80000000 - 1) ]]) test_eq("2147483647", [[ (string)(0x80000000 - 1) ]])
-
+
test_eq("-9223372036854775808", [[ (string)(-0x7fffffffffffffff - 1) ]])
+
test_eq("-9223372036854775809", [[ (string)(-0x8000000000000000 - 1) ]])
+
test_eq("9223372036854775807", [[ (string)(0x8000000000000000 - 1) ]])
test_false([[ objectp(0x80000000 - 1) ]]) // - Multiplication. test_eq("6442450941", [[ (string)(0x7fffffff * 3) ]]) test_eq("-6442450941", [[ (string)(0x7fffffff * -3) ]]) test_eq(-2147483648*-1,2147483648)
-
+
test_eq(-9223372036854775808*-1,9223372036854775808)
// Division. test_eq("1073741824", [[ (string)((int)"2147483648" / 2) ]]) test_false([[ objectp((int)"2147483648" / 2) ]]) test_eq("13934998268672547360069539025", [[ (string)(48324683476346278246238462784624627348 / 3467864333) ]])
-
]])
+
// sprintf (and the describe stuff in the master)
+
test_do([[sprintf ("%O", 10->pow);
]])
-
cond([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]],
-
[[
-
+
// - sscanf. test_eq("12345678901234567890", [[ (string)array_sscanf("12345678901234567890", "%d")[0] ]]) test_eq("1375488932614371410344080", [[ (string)array_sscanf("123456789F01234567890", "%x")[0] ]]) test_eq("1375488932614371410344080",
-
+
[[ (string)array_sscanf("0x123456789F01234567890", "%x")[0] ]])
+
test_eq("1375488932614371410344080",
+
[[ (string)array_sscanf("0X123456789F01234567890", "%x")[0] ]])
+
test_eq("1375488932614371410344080",
[[ (string)array_sscanf("0x123456789F01234567890", "%i")[0] ]])
-
+
test_eq("1375488932614371410344080",
+
[[ (string)array_sscanf("0X123456789F01234567890", "%i")[0] ]])
test_eq("45954944846776", [[ (string)array_sscanf("1234567012345670", "%o")[0] ]]) test_eq("45954944846776", [[ (string)array_sscanf("01234567012345670", "%i")[0] ]]) test_eq("11", [[ (string)array_sscanf("1011", "%b")[0] ]]) test_eq("1125968643114208", [[ (string)array_sscanf("100000000000001000000000001000000000100010011100000", "%b")[0] ]]) test_eq("11", [[ (string)array_sscanf("0b1011", "%i")[0] ]]) test_eq("1125968643114208", [[ (string)array_sscanf("0b100000000000001000000000001000000000100010011100000", "%i")[0] ]]) test_eq("-12345678901234567890",
pike.git/src/testsuite.in:3208:
test_eq("-1125968643114208", [[ (string)array_sscanf("-100000000000001000000000001000000000100010011100000", "%b")[0] ]]) test_eq("-11", [[ (string)array_sscanf("-0b1011", "%i")[0] ]]) test_eq("-1125968643114208", [[ (string)array_sscanf("-0b100000000000001000000000001000000000100010011100000", "%i")[0] ]]) test_eq([[ sprintf("%x", @array_sscanf("\0\0\0\0\1\2\3\4", "%4c")) ]], "0") test_eq([[ sprintf("%x", @array_sscanf("\0\0\0\0\1\2\3\4", "%8c")) ]], "1020304") test_eq([[ sprintf("%08x", @array_sscanf("\0\0\0\0\1\2\3\4", "%8c")) ]], "01020304") test_eq([[ sprintf("%08x", @array_sscanf("\0\0\0\5\1\2\3\4", "%8c")) ]], "501020304") test_eq([[ sprintf("%08x", @array_sscanf("\0\0\6\5\1\2\3\4", "%8c")) ]], "60501020304") test_eq([[ sprintf("%08x", @array_sscanf("\0\7\6\5\1\2\3\4", "%8c")) ]], "7060501020304")
-
test_eq([[ sprintf("%08x", @array_sscanf("
\8\7\6\5\1\2\3\4
", "%8c")) ]], "3807060501020304")
+
test_eq([[ sprintf("%08x", @array_sscanf("
8\7\6\5\1\2\3\4
", "%8c")) ]], "3807060501020304")
test_eq([[ sprintf("%08x", @array_sscanf("\010\7\6\5\1\2\3\4", "%8c")) ]], "807060501020304")
-
test_equal([[ ({
0,
118 }) ]], [[ array_sscanf("0x76", "%
xx%
x") ]])
-
test_equal([[ (
{
0
,
557239244978618154304871
}) ]],
-
[[ array_sscanf("0x76000000000001234567", "%
xx%
x") ]])
+
test_equal([[ ({ 118 }) ]], [[ array_sscanf("0x76", "%x") ]])
+
test_equal([[
({42
}) ]], [[ array_sscanf("101010", "%b") ]])
+
test_equal([[ (
{42
}) ]]
,
[[
array_sscanf("0b101010", "%b") ]])
+
test_equal([[ ({42
}) ]],
[[ array_sscanf("0B101010", "%b") ]])
+
test_equal([[
({
557239244978618154304871
})
]],
+
[[ array_sscanf("0x76000000000001234567", "%x") ]])
-
+
test_equal([[array_sscanf("foo \12345 bar <fie>","%[^<]")]],
+
[[ ({"foo \12345 bar " }) ]])
+
test_equal(471100000000000000000000000000000000000000000000042, (int)(mixed)471100000000000000000000000000000000000000000000042) test_eq(6745697846498645967, [[ Gmp.mpz("6745697846498645967")->cast_to_int(); ]])
-
]])
+
-
cond([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]],
-
[[
+
test_eq(0x7fffffff, [[ decode_value(encode_value(0x7fffffff)) ]]) test_eq(0x7ffffffff, [[ decode_value(encode_value(0x7ffffffff)) ]]) test_eq(0x7fffffffff, [[ decode_value(encode_value(0x7fffffffff)) ]]) test_eq(0x7ffffffffff, [[ decode_value(encode_value(0x7ffffffffff)) ]]) test_eq(0x7fffffffffff, [[ decode_value(encode_value(0x7fffffffffff)) ]]) test_eq(0x7ffffffffffff, [[ decode_value(encode_value(0x7ffffffffffff)) ]]) test_eq(0x80000000, [[ decode_value(encode_value(0x80000000)) ]]) test_eq(0x800000000, [[ decode_value(encode_value(0x800000000)) ]]) test_eq(0x8000000000, [[ decode_value(encode_value(0x8000000000)) ]]) test_eq(0x80000000000, [[ decode_value(encode_value(0x80000000000)) ]])
pike.git/src/testsuite.in:3260:
test_eq(-0x8000000000, [[ decode_value(encode_value(-0x8000000000)) ]]) test_eq(-0x80000000000, [[ decode_value(encode_value(-0x80000000000)) ]]) test_eq(-0x800000000000, [[ decode_value(encode_value(-0x800000000000)) ]]) test_eq(-0x8000000000000, [[ decode_value(encode_value(-0x8000000000000))]]) test_eq(-0x12345678, [[ decode_value(encode_value(-0x12345678)) ]]) test_eq(-0x123456780, [[ decode_value(encode_value(-0x123456780)) ]]) test_eq(-0x1234567801, [[ decode_value(encode_value(-0x1234567801)) ]]) test_eq(-0x12345678012, [[ decode_value(encode_value(-0x12345678012)) ]]) test_eq(-0x123456780123, [[ decode_value(encode_value(-0x123456780123)) ]]) test_eq(-0x1234567801234, [[ decode_value(encode_value(-0x1234567801234))]])
-
]])
+
-
cond
([[
sizeof
(
cpp
(
"
__
AUTO
_
BIGNUM
__
"
)
/"
__
AUTO
_
BIGNUM
__
"
)
==
1 ]]
,
-
[[
+
test_eval_error
([[
_next
(
(mixed)
decode_value
(
encode
_
value (Int.NATIVE
_
MAX))) ]])
+
test
_
eval
_
error([[
_
next ((mixed
)
decode
_
value (encode
_
value (Int.NATIVE
_
MIN))) ]])
+
test
_
do([[
_
next
((mixed
)
decode_value
(encode_value (Int.NATIVE_MAX +
1
)))
]]
)
+
test_do(
[[
_next ((mixed) decode_value (encode_value (Int.NATIVE_MIN - 1))) ]])
test_eq(2147483648, -2147483648/-1) test_eq(2147483648, -2147483648*-1) test_true([[ random(0x7fffffff)+1 ]]) test_true([[ random(0x7ffffffff)+1 ]]) test_true([[ sqrt(0x7fffffff)+1 ]]) test_true([[ sqrt(0x7ffffffff)+1 ]]) test_true([[ catch { destruct((mixed)0x4783647824687234628462); } ]]) test_any_equal([[ array a = ({4711, 0x54325827a124*0x12348795482485425}); set_weak_flag (a, 1); gc();
-
return a;
+
return
set_weak_flag(
a
, 0)
;
]], [[ ({4711, 0x54325827a124*0x12348795482485425}) ]]) test_any_equal([[ mapping m = ([ 4711: 0x54325827a124*0x12348795482485425, 0x54325827124*0x1234879548a2485425: 1174, ]); set_weak_flag (m, 1); gc();
-
return m;
+
return
set_weak_flag(
m
, 0)
;
]], [[ ([ 4711: 0x54325827a124*0x12348795482485425, 0x54325827124*0x1234879548a2485425: 1174, ]) ]])
-
]])
+
-
cond([[ sizeof( cpp("__AUTO_BIGNUM__")/"__AUTO_BIGNUM__" ) == 1 ]],
-
[[
+
test_any([[int a=2147483648; a=a+17; return a]], 2147483665) test_any([[int a=2147483648; a=a-17; return a]], 2147483631) test_any([[int a=2147483648; a=a*17; return a]], 36507222016) test_any([[int a=2147483648; a=a/17; return a]], 126322567) test_any([[int a=2147483648; a=a%17; return a]], 9) test_any([[int a=2147483648; a=a^17; return a]], 2147483665) test_any([[int a=2147483648; a=a&17; return a]], 0) test_any([[int a=2147483648; a=a|17; return a]], 2147483665) test_any([[int a=2147483648; a=a<<17; return a]], 281474976710656) test_any([[int a=2147483648; a=a>>17; return a]], 16384)
pike.git/src/testsuite.in:3323:
test_eq([[2147483648^17 ]], 2147483665) test_eq([[2147483648&17 ]], 0) test_eq([[2147483648|17 ]], 2147483665) test_eq([[2147483648<<17]], 281474976710656) test_eq([[2147483648>>17]], 16384) test_true([[ floatp((1<<99)/3.14) ]]); test_true([[ floatp((1<<99)*3.14) ]]); test_true([[ floatp((1<<99)-3.14) ]]); test_true([[ floatp((1<<99)+3.14) ]]);
-
]])
+
-
cond
([[
sizeof
(
cpp
(
"
__
AUTO
_
BIGNUM
__
"
)/
"
__
AUTO
_
BIGNUM
__
"
)
==
1
]],
-
[[
+
test_eq
([[(
12)+
(
3)]],0xf);
+
test
_
eq([[(12)+(3*(1<<32))]],0x30000000c);
+
test
_
eq([[(12)+(3*(1<<64))]],0x3000000000000000c);
+
test
_
eq([[(12)+(3*(1<<128))]],0x30000000000000000000000000000000c);
+
test
_
eq([[(12*(1<<32))+(3)]],0xc00000003);
+
test
_
eq([[(12*(1<<32
)
)+(3*(1<<32))]],0xf00000000);
+
test_eq([[(12*(1<<32))+(3*(1<<64))]],0x30000000c00000000);
+
test_eq([[(12*(1<<32))+(3*(1<<128))]],0x300000000000000000000000c00000000);
+
test_eq([[(12*(1<<64))+(3)]],0xc0000000000000003);
+
test_eq([[(12*(1<<64))+(3*(1<<32))]],0xc0000000300000000);
+
test_eq([[(12*(1<<64))+(3*(1<<64))]],0xf0000000000000000);
+
test_eq([[(12*(1<<64))+(3*(1<<128))]],0x3000000000000000c0000000000000000);
+
test_eq([[(12*(1<<128))+(3)]],0xc00000000000000000000000000000003);
+
test_eq([[(12*(1<<128))+(3*(1<<32))]],0xc00000000000000000000000300000000);
+
test_eq([[(12*(1<<128))+(3*(1<<64))]],0xc00000000000000030000000000000000);
+
test_eq([[(12*(1<<128))+(3*(1<<128))]],0xf00000000000000000000000000000000);
+
test_eq([[(12)-(3)]],0x9);
+
test_eq([[(12)-(3*(1<<32))]],-0x2fffffff4);
+
test_eq([[(12)-(3*(1<<64))]],-0x2fffffffffffffff4);
+
test_eq([[(12)-(3*(1<<128))]],-0x2fffffffffffffffffffffffffffffff4);
+
test_eq([[(12*(1<<32))-(3)]],0xbfffffffd);
+
test_eq([[(12*(1<<32))-(3*(1<<32))]],0x900000000);
+
test_eq([[(12*(1<<32))-(3*(1<<64))]],-0x2fffffff400000000);
+
test_eq([[(12*(1<<32))-(3*(1<<128))]],-0x2fffffffffffffffffffffff400000000);
+
test_eq([[(12*(1<<64))-(3)]],0xbfffffffffffffffd);
+
test_eq([[(12*(1<<64))-(3*(1<<32))]],0xbfffffffd00000000);
+
test_eq([[(12*(1<<64))-(3*(1<<64))]],0x90000000000000000);
+
test_eq([[(12*(1<<64))-(3*(1<<128))]],-0x2fffffffffffffff40000000000000000);
+
test_eq([[(12*(1<<128))-(3)]],0xbfffffffffffffffffffffffffffffffd);
+
test_eq([[(12*(1<<128))-(3*(1<<32))]],0xbfffffffffffffffffffffffd00000000);
+
test_eq([[(12*(1<<128))-(3*(1<<64))]],0xbfffffffffffffffd0000000000000000);
+
test_eq([[(12*(1<<128))-(3*(1<<128))]],0x900000000000000000000000000000000);
+
+
test_eq([[(12)*(3)]],0x24);
+
test_eq([[(12)*(3*(1<<32))]],0x2400000000);
+
test_eq([[(12)*(3*(1<<64))]],0x240000000000000000);
+
test_eq([[(12)*(3*(1<<128))]],0x2400000000000000000000000000000000);
+
test_eq([[(12*(1<<32))*(3)]],0x2400000000);
+
test_eq([[(12*(1<<32))*(3*(1<<32))]],0x240000000000000000);
+
test_eq([[(12*(1<<32))*(3*(1<<64))]],0x24000000000000000000000000);
+
test_eq([[(12*(1<<32))*(3*(1<<128))]],0x240000000000000000000000000000000000000000);
+
test_eq([[(12*(1<<64))*(3)]],0x240000000000000000);
+
test_eq([[(12*(1<<64))*(3*(1<<32))]],0x24000000000000000000000000);
+
test_eq([[(12*(1<<64))*(3*(1<<64))]],0x2400000000000000000000000000000000);
+
test_eq([[(12*(1<<64))*(3*(1<<128))]],0x24000000000000000000000000000000000000000000000000);
+
test_eq([[(12*(1<<128))*(3)]],0x2400000000000000000000000000000000);
+
test_eq([[(12*(1<<128))*(3*(1<<32))]],0x240000000000000000000000000000000000000000);
+
test_eq([[(12*(1<<128))*(3*(1<<64))]],0x24000000000000000000000000000000000000000000000000);
+
test_eq([[(12*(1<<128))*(3*(1<<128))]],0x240000000000000000000000000000000000000000000000000000000000000000);
+
test_eq([[(12)
/
(3)]],0x4);
+
test
_
eq([[(12)/(3*(1<<32))]],0x0);
+
test
_
eq([[(12)/(3*(1<<64))]],0x0);
+
test
_
eq([[(12)/(3*(1<<128))]],0x0);
+
test
_
eq([[(12*(1<<32))/(3*(1<<32))]],0x4);
+
test
_
eq([[(12*(1<<32))/(3*(1<<64))]],0x0);
+
test_eq([[(12*(1<<32))/(3*(1<<128))]],0x0);
+
test_eq([[(12*(1<<64))/(3*(1<<64))]],0x4);
+
test_eq([[(12*(1<<64))/(3*(1<<128))]],0x0);
+
test_eq([[(12*(1<<128))/(3*(1<<128))]],0x4);
+
test_eq([[(17+12)%(3)]],0x2);
+
test_eq([[(17+12)%(3*(1<<32))]],0x1d);
+
test_eq([[(17+12)%(3*(1<<64))]],0x1d);
+
test_eq([[(17+12)%(3*(1<<128))]],0x1d);
+
test_eq([[(17+12*(1<<32))%(3*(1<<32))]],0x11);
+
test_eq([[(17+12*(1<<32))%(3*(1<<64))]],0xc00000011);
+
test_eq([[(17+12*(1<<32))%(3*(1<<128))]],0xc00000011);
+
test_eq([[(17+12*(1<<64))%(3*(1<<64))]],0x11);
+
test_eq([[(17+12*(1<<64))%(3*(1<<128))]],0xc0000000000000011);
+
test_eq([[(17+12*(1<<128))%(3*(1<<128))]],0x11);
+
+
test_eq([[Gmp.mpz(68719476736)/Gmp.mpz(12884901888)]],5);
+
test_eq([[Gmp.mpz(123456789012345678901234567890)/Gmp.mpz(12884901888)]],
+
Gmp.mpz(9581507883061474724
)
);
+
test_eq([[Gmp.mpz(123456789012345678901234567890)/
+
Gmp.mpz(67890123456789012345)
]],
1818479371);
+
test_eq(
[[
Gmp.mpz(123456789012345678901234567890)/
+
Gmp.mpz(67890123456789)]],Gmp.mpz(1818479371169857));
+
test_any([[int a=10->pow(30); int b=1000000000000000000000000000000; return ([a:1])[b]]],1); test_any([[int a=10->pow(30); int b=1000000000000000000000000000000; return (<a>)[b]]],1); test_any([[int a=10->pow(30); int b=1000000000000000000000000000000; return sizeof( ({a})-({b}) )]],0); test_any([[int a=10->pow(30); int b=1000000000000000000000000000000; return sizeof( ({a})&({b}) )]],1); test_any([[int k=10->pow(30); array a=({k+17,k+16,k+13,k+14,k+12,k,k+9}); return sort(a)[0]==k && sort(a)[-1]==k+17]],1)
-
+
test_do([[
+
// This is a memleak test
+
rm("testsuite_test.pike");
+
Stdio.write_file("testsuite_test.pike",
+
"constant Q=10000000000000000;\n"
+
"int main() {}\n");
+
Process.system(RUNPIKE +" testsuite_test.pike");
+
rm("testsuite_test.pike");
+
]])
+
// test the corresponding integer operations first test_any([[int k=100; int j=k+1; array a=({k+17,k+16,k+13,k+14,k+12,k,k+9}); array b=({j+16,j+15,j+12,j+13,j+11,j-1,j+8}); return sizeof( a&b )]],7); test_any([[int k=100; int j=k+1; array a=({k+17,k+16,k+13,k+14,k+12,k,k+9}); array b=({j+13,j+11,j-1,j+8,j+16,j+15,j+12}); return sizeof( a-b )]],0); // now the bignum ones test_any([[int k=10->pow(30); int j=k+1; array a=({k+17,k+16,k+13,k+14,k+12,k,k+9}); array b=({j+16,j+15,j+12,j+13,j+11,j-1,j+8}); return sizeof( a&b )]],7); test_any([[int k=10->pow(30); int j=k+1; array a=({k+17,k+16,k+13,k+14,k+12,k,k+9}); array b=({j+13,j+11,j-1,j+8,j+16,j+15,j+12}); return sizeof( a-b )]],0);
-
]])
-
+
cond([[all_constants()->_verify_internals]], [[ test_do(_verify_internals()) ]]) test_eq("\377"[0],255)
-
test_do(add_constant("foo",
clone(
class c {int i;})))
+
test_do(add_constant("foo",class c {int i;}
(
)))
test_eq(foo->i,0) test_do(foo->i=17) test_eq(foo->i,17) test_do(add_constant("foo"));
-
test_do(add_constant("foo",
clone(
class c {array(int) i=({0});})))
+
test_do(add_constant("foo",class c {array(int) i=({0});}
(
)))
test_eq(foo->i[0],0) test_do(foo->i[0]=17) test_eq(foo->i[0],17) test_do(add_constant("foo")); // signum, signame test_true(intp(signum("SIGKILL"))) // kill, signal, getpid test_true(intp(getpid()))
pike.git/src/testsuite.in:3396:
test_do(kill(getpid(),signum("SIGFPE"))) test_do(sleep(2)) test_eq(AFJLLAF,17) test_do(add_constant("AFJLLAF")) test_do(signal(signum("SIGFPE"), 0)) test_do(signal(signum("SIGFPE"))) ]]) // typeof test_eq(sprintf("%O", typeof(1)),"int(1..1)")
-
test_eq(sprintf("%O", typeof("")),"string")
-
test_
eq
(sprintf("%
O
", typeof(""[0])),"
int
")
+
test_eq(sprintf("%O", typeof("")),"string
(zero)
")
+
test_
any
(
[[
+
// Suppress warnings.
+
class handler {
+
void compile_warning (string file, int line, string err) {};
+
};
+
return compile_string("string s =
sprintf(
\
"%
O\
", typeof(
\
"
\
"[0]))
;"
,
+
"
-
"
, handler(
)
)()->s;
+
]], "zero")
test_eq(sprintf("%O", typeof(0.0)),"float") test_eq(sprintf("%O", typeof(all_constants()["all_constants"])),"mixed") // _typeof test_eq(sprintf("%O", _typeof(1)),"int(1..1)")
-
test_eq(sprintf("%O", _typeof("")),"string")
+
test_eq(sprintf("%O", _typeof("")),"string
(zero)
")
test_eq(sprintf("%O", _typeof("x"[0])),"int(120..120)") test_eq(sprintf("%O", _typeof(0.0)),"float")
-
test_eq(sprintf("%
O
", _typeof(this_object))-" ","function(:object)")
+
test_eq(
[[sscanf(
sprintf("%
Ox
", _typeof(this_object))-" ",
+
"function(
void|int(0..%*[0-9])
:object)
%*c
")
]], 2)
// class test_true(programp(class c {}))
-
test_true(functionp(
clone(
class c { int foo() { return 1; }})->foo))
-
test_true(
clone(
class c { int foo() { return 1; }})->foo())
-
test_true(
clone(
class c { int i=1; })->i)
-
test_false(
clone(
class c { int foo() { return 1; }})->bar)
-
test_eq(
clone(clone(
class c { program foo=class c { int i=20; }; })->foo)->i,20)
+
test_true(functionp(class c { int foo() { return 1; }}
(
)->foo))
+
test_true(class c { int foo() { return 1; }}
(
)->foo())
+
test_true(class c { int i=1; }
(
)->i)
+
test_false(class c { int foo() { return 1; }}
(
)->bar)
+
test_eq(class c { program foo=class c { int i=20; }; }
(
)->foo
(
)->i,20)
// class() test_true(programp(class c(){}))
-
test_equal(indices(class c(string a,
static
int b){}("foo",0)), ({"a"}))
-
test_equal(values(class c(string a,
static
int b){}("foo",0)), ({"foo"}))
+
test_equal(indices(class c(string a,
protected
int b){}("foo",0)), ({"a"}))
+
test_equal(values(class c(string a,
protected
int b){}("foo",0)), ({"foo"}))
+
test_true(programp(class c(string ... a){}))
+
test_equal(indices(class c(string a,protected int ... b){}("foo",0)), ({"a"}))
+
test_equal(values(class c(protected string a, int ... b){}("foo",0)), ({({0})}))
-
+
test_do([[
+
class A (int i) {};
+
class B (int i, int j) {inherit A;};
+
class C {inherit B;};
+
C (1,1);
+
]])
+
// type checks test_compile_error([[} int foo() { return]]); test_compile_error([[} void foo() { return 1]]); test_compile([[mapping a; int b; a = b = 0;]]); test_compile_error([[mapping a; int b; a = b = 1;]]); test_compile_any([[void a(int q){} void b(function(int:void) f){} void c(){b(a);}]]);
-
test_compile_error_
low
([[void a(int i){} void b(function(:void) f){} void c(){b(a);}]]);
+
test_compile_error_
any
([[void a(int i){} void b(function(:void) f){} void c(){b(a);}]]);
test_compile_any([[void a(){} function(int:void) b = a;]]);
-
test_compile_error_
low
([[void a(int i){} function(:void) b = a;]]);
+
test_compile_error_
any
([[void a(int i){} function(:void) b = a;]]);
// Duplicate local variable test_compile_error([[void f() {int i; int i;}]]); test_compile_error([[void f() {int i; mapping i;}]]); test_compile_error([[void f() {int i; void i() {};}]]); test_compile_error([[void f (int i) {string i;}]]); // Not yet cataloged
-
test_any(int i=10; { int i; } return i, 10)
-
test_program(void foo(int a
,int b)
;
function(int,int:void) a() { return foo; })
-
test_program(void foo(int a, int ... b)
;
function(int,int ...:void) a() { return foo; })
-
test_program(void foo()
;
function(:void) a() { return foo; })
-
test_compile_error([[} void foo()
;
function(:string) a() { return foo;]])
+
test_any(int i=10; { int i
=0
; } return i, 10)
+
test_program(void foo(int a
,
int b)
{}
function(int,int:void) a() { return foo; })
+
test_program(void foo(int a, int ... b)
{}
function(int,int ...:void) a() { return foo; })
+
test_program(void foo()
{}
function(:void) a() { return foo; })
+
test_compile_error([[} void foo()
{}
function(:string) a() { return foo;]])
test_do(lambda(){return;}()) test_equal( ({ lambda() { return 3; } , lambda() { return 7; }, lambda() { return 9; } })(), ({ 3,7,9 })) test_any(array(int) a=({10}); a[0]++; return a[0], 11) test_any(mapping a=([10:11]); a[10]++; return a[10], 12) test_equal(mkmapping( ({3,6,2}), ({"3","6","2"})), ([3:"3", 6:"6", 2:"2"])) test_equal(`+(([3:"3", 6:"6", 2:"2"])), ([3:"3", 6:"6", 2:"2"])) test_true(`+(([3:"3", 6:"6", 2:"2"])) != ([3:"3", 6:"6", 2:"2"])) test_true(predef::stringp(""))
pike.git/src/testsuite.in:3473:
test_equal("abcd"/"" & indices("abcd"),({})) test_eq(sizeof("abcd"/"" & "de"/""),1) test_equal( ({0,0,0,0,0}), ({0,0,0,0,0})) test_equal( ({"object","object","object","object","object"}), allocate(5,"object")) test_equal(mkmapping("abcd"/"","jklm"/"") | mkmapping("jclm"/"","alcd"/""), mkmapping("abcdjlm"/"","jklmacd"/"")) test_program(int foo() { return 17;} mixed a() { return foo() == 17; }) test_any([[mixed a; a=2; a=a*3; return a]],6) test_any([[mixed a = ({1}); a=a+({2}); return equal(a,({1,2}))]],1) test_define_program(test,[[int foo() { return 17; }]])
-
test_any(function bar=
clone(
test)->foo; return bar(),17)
+
test_any(function bar=
test
()->foo; return bar(),17)
+
test_do(add_constant("test"))
// sscanf test_any([[mixed a; return sscanf("11","%d",a)]],1)
-
+
test_any([[return sscanf("11","%*d")]],1)
+
test_any([[mixed a; return sscanf("11","_%d",a)]],0)
+
test_any([[mixed a,b,c; return sscanf("11","%1d%1d%1d",a,b,c)]],2)
-
+
test_any([[mixed a; sscanf("11","%b",a); return a]],0b11)
test_any([[mixed a; sscanf("11","%d",a); return a]],11) test_any([[mixed a; sscanf("11","%o",a); return a]],011) test_any([[mixed a; sscanf("11","%x",a); return a]],0x11) test_any([[mixed a; sscanf("11","%D",a); return a]],11)
-
+
test_any([[mixed a; sscanf("11","%2b",a); return a]],0b11)
test_any([[mixed a; sscanf("11","%2d",a); return a]],11) test_any([[mixed a; sscanf("11","%2o",a); return a]],011) test_any([[mixed a; sscanf("11","%2x",a); return a]],0x11) test_any([[mixed a; sscanf("11","%2D",a); return a]],11)
-
+
test_any([[mixed a; sscanf("11","%4711b",a); return a]],0b11)
test_any([[mixed a; sscanf("11","%4711d",a); return a]],11) test_any([[mixed a; sscanf("11","%4711o",a); return a]],011) test_any([[mixed a; sscanf("11","%4711x",a); return a]],0x11) test_any([[mixed a; sscanf("11","%4711D",a); return a]],11)
-
+
test_any([[mixed a; sscanf("11","%1b",a); return a]],1)
test_any([[mixed a; sscanf("11","%1d",a); return a]],1) test_any([[mixed a; sscanf("11","%1o",a); return a]],1) test_any([[mixed a; sscanf("11","%1x",a); return a]],1) test_any([[mixed a; sscanf("11","%1D",a); return a]],1) test_any([[mixed a; sscanf("0x11","%D",a); return a]],0x11) test_any([[mixed a; sscanf("011","%D",a); return a]],011)
-
test_any([[mixed a
,b
; return sscanf("11foo","%dfoo",a)]],1)
-
test_any([[mixed a
,b
; sscanf("11foo","%dfoo",a); return a]],11)
+
test_any([[mixed a; return sscanf("11foo","%dfoo",a)]],1)
+
test_any([[mixed a; sscanf("11foo","%dfoo",a); return a]],11)
test_any([[mixed a,b; return sscanf("11foo","%d%s",a,b)]],2) test_any([[mixed a,b; sscanf("11foo","%d%s",a,b); return b]],"foo") test_any([[mixed a,b; return sscanf("foo","%c%s",b,a)]],2) test_any([[mixed a,b; sscanf("foo","%c%s",b,a); return b]],'f') test_any([[mixed a,b; sscanf("foo","%c%s",b,a); return a]],"oo")
-
test_any([[mixed a
,b
; return sscanf("1.0","%f",a),a]],1.0)
-
test_any([[mixed a
,b
; return sscanf("-1.0","%f",a),a]],-1.0)
-
test_any([[mixed a
,b
; return sscanf("1.25","%f",a),a]],1.25)
-
test_any([[mixed a
,b
; return sscanf("-1.25","%f",a),a]],-1.25)
-
test_any([[mixed a
,b
; return sscanf("1.25e3","%f",a),a]],1.25e3)
-
test_any([[mixed a
,b
; return sscanf("-1.25e3","%f",a),a]],-1.25e3)
-
test_any([[mixed a
,b
; return sscanf("1.25e-3","%f",a),a]],1.25e-3)
-
test_any([[mixed a
,b
; return sscanf("-1.25e-3","%f",a),a]],-1.25e-3)
-
test_any([[mixed a
,b
; sscanf("1.0","%f",a); return a]],1.0)
+
test_any([[mixed a; return sscanf("1.0","%f",a),a]],1.0)
+
test_any([[mixed a; return sscanf("-1.0","%f",a),a]],-1.0)
+
test_any([[mixed a; return sscanf("1.25","%f",a),a]],1.25)
+
test_any([[mixed a; return sscanf("-1.25","%f",a),a]],-1.25)
+
test_any([[mixed a; return sscanf("1.25e3","%f",a),a]],1.25e3)
+
test_any([[mixed a; return sscanf("-1.25e3","%f",a),a]],-1.25e3)
+
test_any([[mixed a; return sscanf("1.25e-3","%f",a),a]],1.25e-3)
+
test_any([[mixed a; return sscanf("-1.25e-3","%f",a),a]],-1.25e-3)
+
test_any([[mixed a; sscanf("1.0","%f",a); return a]],1.0)
test_any([[mixed a,b; sscanf("-z ","%[-z]%s",a,b); return a]],"-z") test_any([[mixed a,b; sscanf("-z ","%[z-]%s",a,b); return a]],"-z") test_any([[mixed a,b; sscanf("abcdeFGji","%[a-z]%s",a,b); return a]],"abcde") test_any([[mixed a,b; sscanf("abcdeFGji","%[a-z]%s",a,b); return b]],"FGji") test_any([[mixed a,b; return sscanf("foo-%-bar","%s-%%-%s",a,b);]],2) test_any([[mixed a,b; sscanf("foo-%-bar","%s-%%-%s",a,b); return a]],"foo") test_any([[mixed a,b; sscanf("foo-%-bar","%s-%%-%s",a,b); return b]],"bar") test_any([[mixed a; sscanf("ab","%2c",a); return a]],'a'*256+'b') test_any([[mixed a; sscanf("abc","%3c",a); return a]],'a'*256*256+'b'*256+'c')
pike.git/src/testsuite.in:3547:
test_any([[mixed a; sscanf("a93","%s%*x",a); return a]],"") test_any([[mixed a; sscanf("a93","%*s%x",a); return a]],0xa93) test_any([[mixed a; sscanf("f","f%n",a); return a]],1) test_any([[mixed a; sscanf("\102\052\100\000","%F",a); return a]],42.5625) test_any([[mixed a; sscanf("\102\052\100\000","%4F",a); return a]],42.5625) test_any([[mixed a; sscanf("\100\105\110\000\0\0\0\0","%8F",a); return a]],42.5625) test_any([[mixed a; sscanf("\275\007\053\002","%4F",a); return a]],-0.032999999821186065673828125) test_any([[mixed a; sscanf("\277\240\345\140\100\0\0\0","%8F",a); return a]],-0.032999999821186065673828125)
+
// Inf
test_any([[mixed a; sscanf("\177\200\0\0","%4F",a); return a>0.0]],1) test_any([[mixed a; sscanf("\177\200\0\0","%4F",a); return (a/2)==a]],1)
-
+
// -Inf
test_any([[mixed a; sscanf("\377\200\0\0","%4F",a); return a<0.0]],1) test_any([[mixed a; sscanf("\377\200\0\0","%4F",a); return (a/2)==a]],1)
-
+
// NaN
test_any([[mixed a; sscanf("\177\300\0\0","%4F",a); return a>0.0]],0) test_any([[mixed a; sscanf("\177\300\0\0","%4F",a); return a<0.0]],0) test_any([[mixed a; sscanf("\177\300\0\0","%4F",a); return a==0.0]],0)
-
+
// -NaN
test_any([[mixed a; sscanf("\377\300\0\0","%4F",a); return a>0.0]],0) test_any([[mixed a; sscanf("\377\300\0\0","%4F",a); return a<0.0]],0) test_any([[mixed a; sscanf("\377\300\0\0","%4F",a); return a==0.0]],0)
-
+
// Inf
test_any([[mixed a; sscanf("\177\360\0\0\0\0\0\0","%8F",a); return a>0.0]],1) test_any([[mixed a; sscanf("\177\360\0\0\0\0\0\0","%8F",a); return(a/2)==a]],1)
-
+
// -Inf
test_any([[mixed a; sscanf("\377\360\0\0\0\0\0\0","%8F",a); return a<0.0]],1) test_any([[mixed a; sscanf("\377\360\0\0\0\0\0\0","%8F",a); return(a/2)==a]],1)
-
+
// NaN
test_any([[mixed a; sscanf("\177\370\0\0\0\0\0\0","%8F",a); return a>0.0]],0) test_any([[mixed a; sscanf("\177\370\0\0\0\0\0\0","%8F",a); return a<0.0]],0) test_any([[mixed a; sscanf("\177\370\0\0\0\0\0\0","%8F",a); return a==0.0]],0)
-
+
// -NaN
test_any([[mixed a; sscanf("\377\370\0\0\0\0\0\0","%8F",a); return a>0.0]],0) test_any([[mixed a; sscanf("\377\370\0\0\0\0\0\0","%8F",a); return a<0.0]],0) test_any([[mixed a; sscanf("\377\370\0\0\0\0\0\0","%8F",a); return a==0.0]],0) test_equal([[array_sscanf("10 20 30","%d %d %d")]],[[({10,20,30})]]) test_equal([[array_sscanf("1 2 3 4 5 6 7 8 9","%d %d %d %d %d %d %d %d %s")]],[[({1,2,3,4,5,6,7,8,"9"})]]) test_equal([[array_sscanf("abc","%{%c%}")]],[[ ({ ({ ({'a'}), ({'b'}), ({'c'}) }) }) ]]) test_equal([[array_sscanf("\x7fffffab#", "%c%c")]], [[ ({ 0x7fffffab, '#' }) ]]) test_equal([[array_sscanf("\x7fffffab#", "%1c%1c")]], [[ ({ }) ]]) test_true([[array_sscanf("(02323) 23455 344","%{%*[^0-9]%[0-9]%}")]]) test_eq([[ array_sscanf(sprintf("%4c",16909060),"%4c")[0] ]],16909060) test_eq([[ array_sscanf(sprintf("%-4c",16909060),"%-4c")[0] ]],16909060)
-
+
test_eq([[ array_sscanf(sprintf("%4c",16909060),"%+4c")[0] ]],16909060)
+
test_eq([[ array_sscanf(sprintf("%-4c",16909060),"%+-4c")[0] ]],16909060)
+
test_eq([[ array_sscanf(sprintf("%4c",-16909060),"%+4c")[0] ]],-16909060)
+
test_eq([[ array_sscanf(sprintf("%-4c",-16909060),"%+-4c")[0] ]],-16909060)
test_equal([[array_sscanf("\1000\1001\2000","%[\1000-\1111]%s")]], [[ ({ "\1000\1001", "\2000" }) ]]) test_equal([[array_sscanf("foo\1000\1001\1111\1110\2000","%s%[\1000-\1111]%s")]], [[ ({ "foo", "\1000\1001\1111\1110", "\2000" }) ]]) test_equal([[array_sscanf("\2000\1000\1111\1001\1110foo","%s%[\1000-\1111]%s")]], [[ ({ "\2000", "\1000\1111\1001\1110", "foo"}) ]]) test_equal([[ array_sscanf("02 00 DC 00 0B","%{%x%*[\0-/:-@]%}")[0] ]], [[ ({ ({2}), ({0}), ({220}),({0}), ({11}) }) ]]) test_equal([[ array_sscanf("\51726\30212\66610\30131", "%*[ \t]%s")[0] ]], [[ "\51726\30212\66610\30131" ]])
-
+
test_equal([[ array_sscanf("hej","%s") ]], [[ ({ "hej" }) ]])
+
test_equal([[ array_sscanf("hej","%s%n") ]], [[ ({ "hej", 3 }) ]])
+
test_equal([[ array_sscanf("hejhopp", "%*!3s%s%n") ]], [[ ({ "hopp", 4 }) ]])
+
test_eval_error([[ function f=array_sscanf; f("hej","%s% ") ]])
+
+
test_equal([[ array_sscanf("\x304b\x3066\x3044\x308a\x3087\x3046\x308a", "%[^\x3042\x3044\x3046\x3048\x304a]")[0] ]],
+
[[ "\x304b\x3066" ]])
+
+
test_equal( array_sscanf("xfoox", "%sfoo%s"), ({ "x", "x" }) )
+
test_equal( array_sscanf("xfoox", "%sfo\400%s"), ({}) )
+
test_equal( array_sscanf("xfoox", "%sfo\200000%s"), ({}) )
+
test_equal( array_sscanf("xfo\400x", "%sfoo%s"), ({}) )
+
test_equal( array_sscanf("xfo\400x", "%sfo\400%s"), ({ "x", "x" }) )
+
test_equal( array_sscanf("xfo\400x", "%sfo\200000%s"), ({}) )
+
test_equal( array_sscanf("xfo\200000x", "%sfoo%s"), ({}) )
+
test_equal( array_sscanf("xfo\200000x", "%sfo\400%s"), ({}) )
+
test_equal( array_sscanf("xfo\200000x", "%sfo\200000%s"), ({ "x", "x" }) )
+
+
test_any([[mixed a; sscanf("","%H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0","%H",a); return a]],"")
+
test_any([[mixed a; sscanf("\4","%H",a); return a]],0)
+
test_any([[mixed a; sscanf("\4hello","%H",a); return a]],"hell")
+
test_eval_error([[mixed a; sscanf("","%0H",a); return a]])
+
test_eval_error([[mixed a; sscanf("\0","%0H",a); return a]])
+
test_eval_error([[mixed a; sscanf("\4","%0H",a); return a]])
+
test_eval_error([[mixed a; sscanf("\4hello","%0H",a); return a]])
+
test_any([[mixed a; sscanf("","%1H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0","%1H",a); return a]],"")
+
test_any([[mixed a; sscanf("\4","%1H",a); return a]],0)
+
test_any([[mixed a; sscanf("\4hello","%1H",a); return a]],"hell")
+
test_any([[mixed a; sscanf("","%-1H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0","%-1H",a); return a]],"")
+
test_any([[mixed a; sscanf("\4","%-1H",a); return a]],0)
+
test_any([[mixed a; sscanf("\4hello","%-1H",a); return a]],"hell")
+
test_any([[mixed a; sscanf("","%2H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0\0","%2H",a); return a]],"")
+
test_any([[mixed a; sscanf("\0","%2H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0\4","%2H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0\4hello","%2H",a); return a]],"hell")
+
test_any([[mixed a; sscanf("","%-2H",a); return a]],0)
+
test_any([[mixed a; sscanf("\0\0","%-2H",a); return a]],"")
+
test_any([[mixed a; sscanf("\4","%-2H",a); return a]],0)
+
test_any([[mixed a; sscanf("\4\0","%-2H",a); return a]],0)
+
test_any([[mixed a; sscanf("\4\0hello","%-2H",a); return a]],"hell")
+
test_any([[ class Bar { string sum = ""; void bar(string s) { sum += s; } string foo() { foreach(({ "foo ", "bar ", "baz " }), string s) { sscanf(s, "%*[\t ]%[^ \t]", s);
pike.git/src/testsuite.in:3618:
bar(s); break; } } return sum; } }; return Bar()->foo() ]], "foobarbaz")
+
test_equal( array_sscanf("^^;|", "%[^-|]%s"), ({ "^^", ";|" }) )
+
test_any([[mixed a; sscanf("^^;|","%[^-|]",a); return a]],"^^")
-
+
ignore_warning("Bad argument 3 to sscanf_76.", [[
+
ignore_warning("Expected: string.", [[
+
ignore_warning("Got : int.", [[
+
test_any([[
+
#pike 7.6
+
int foo;
+
sscanf ("11", "%s", foo);
+
return foo;
+
]], "11")
+
]])]])]])
+
+
ignore_warning("Too many arguments to sscanf_76 (expected 2 arguments).", [[
+
ignore_warning("Got : string.", [[
+
test_any([[
+
#pike 7.6
+
string s;
+
sscanf ("foo", "%*s", s);
+
return s;
+
]], 0)
+
]])]])
+
+
// sscanf %O -------------------------------------------------------------
+
+
define(test_percent_o_raw, [[
+
test_equal(array_sscanf(]]$3[[,]]$1[[),[[$2]])
+
]])
+
define(test_percent_o_fmt, [[
+
test_percent_o_raw(]]$1[[,]]$2[[,sprintf(]]$1[[,@]]$2[[))
+
]])
+
define(test_percent_o_char, [[
+
dnl patsubst doesn't exist on all m4's (it's a gnuism?)
+
ifdef(patsubst,[[
+
test_percent_o_raw("%O",({']]$1[['}),"']]patsubst($1,\\,\\\\)[['"))
+
test_percent_o_raw("%O%s",({']]$1[[',"abc"}),"']]patsubst($1,\\,\\\\)[['abc"))
+
]])]])
+
ifdef(patsubst,[[
+
define(test_percent_o_string, [[
+
test_percent_o_raw("%O",({"]]$1[["}),"\"]]patsubst($1,\\,\\\\)[[\""))
+
test_percent_o_raw("%O%s",({"]]$1[[","abc"}),"\"]]patsubst($1,\\,\\\\)[[\"abc"))
+
]])]])
+
+
test_percent_o_fmt("%O",({10}))
+
test_percent_o_fmt("%O%s",({10,"abc"}))
+
+
test_percent_o_char([[a]])
+
test_percent_o_char([[\a]])
+
test_percent_o_char([[\123]])
+
test_percent_o_char([[\x4711]])
+
test_percent_o_char([[\d4711]])
+
+
test_percent_o_string([[a]])
+
test_percent_o_string([[\a]])
+
test_percent_o_string([[\123]])
+
test_percent_o_string([[\x4711]])
+
test_percent_o_string([[\d4711]])
+
+
test_percent_o_fmt("%O %O %O",({10,20,30}))
+
test_percent_o_fmt("%O %O %s",({10,20,"30"}))
+
+
// -------------------------------------------------------------
+
+
+
// Basics test_true(1) test_true("") test_true(!0) test_true(!(!1)) test_true(this_object()) test_true(a) // a is the test function test_true(0.0) test_true(([])) test_true(({}))
pike.git/src/testsuite.in:3716:
test_eq(1.0+1,2.0) test_eq(1+1.0,2.0) test_eq(1+(-1.0),0.0) test_eq(1.0+(-1),0.0) test_eq((-1)+(-1.0),-2.0) test_eq((-1.0)+(-1),-2.0) test_equal(({1,2,3})+({4,5,6}),({1,2,3,4,5,6})) test_equal((<1,2,3,4>)+(<4,5,6>),(<1,2,3,4,4,5,6>)) test_equal(([0:1,3:6])+([5:2,3:6]),([0:1,3:6,3:6,5:2])) test_eval_error(return this_object() + this_object())
+
test_any(return((1+2+3)-(1+2-3)), 6)
-
+
// testing - test_eq(10-3,7) test_eq(3-10,-7) test_eq(10.0-3.0,7.0) test_eq(3.0-10.0,-7.0) test_eq(10-3.0,7.0) test_eq(3-10.0,-7.0) test_eq(10.0-3,7.0) test_eq(3.0-10,-7.0) test_eq(034567 - 10000,4711) test_eq("foobargazonk"-"o","fbargaznk") test_equal(({"foo","bar","gazonk"})-({"foo","gazonk"}),({"bar"})) test_equal(({"c","foo","bar","gazonk","a","b",})-({"foo","gazonk"}),({"c","bar","a","b"})) test_equal((<"foo","bar","gazonk">)-(<"foo","gazonk">),(<"bar">)) test_equal((["foo":3,"bar":4,"gazonk":5])-(["foo":3,"gazonk":8]),(["bar":4]))
-
+
test_any([[string s="\57070 abcdefghijklmnopqrstuvwxyz012345678"; return strlen(s-s[1..35])]],37-35)
+
// testing ~ test_eq(-1-4,~4) test_eq(-1-627893874,~627893874) test_eq(~1.0,-2.0) test_eq(~"\x55","\xaa") // testing * test_eq(3*4,12) test_eq(4*3,12) test_eq(2*2*2*2*2,32) test_eq(3.0*4.0,12.0) test_eq(4.0*3.0,12.0) test_eq(2.0*2.0*2.0*2.0*2.0,32.0) test_eq(3*4.0,12.0) test_eq(4*3.0,12.0) test_eq(2*2.0*2.0*2.0*2.0,32.0) test_eq(3.0*4,12.0) test_eq(4.0*3,12.0) test_eq(2.0*2*2.0*2*2.0,32.0)
-
+
test_eq([[({})*""]],"")
+
test_eq([[({"foo",0,"bar"})*"-"]],"foo-bar")
+
test_eq([[({"f","o","o"})*""]],"foo")
+
test_eq(({"foo","bar","gazonk"})*"-","foo-bar-gazonk") test_eq(({"f\777\777","bar","gaz\777nk"})*"-","f\777\777-bar-gaz\777nk") test_eq(({"f\7777777\7777777","bar","gaz\7777777nk"})*"-","f\7777777\7777777-bar-gaz\7777777nk") test_eq(({"foo","bar","gazonk"})*"\777","foo\777bar\777gazonk") test_eq(({"f\777\777","bar","gaz\777nk"})*"\777","f\777\777\777bar\777gaz\777nk") test_eq(({"f\7777777\7777777","bar","gaz\7777777nk"})*"\777","f\7777777\7777777\777bar\777gaz\7777777nk") test_eq(({"foo","bar","gazonk"})*"\7777777","foo\7777777bar\7777777gazonk") test_eq(({"f\777\777","bar","gaz\777nk"})*"\7777777","f\777\777\7777777bar\7777777gaz\777nk")
pike.git/src/testsuite.in:3804:
test_eq(14/4.0,3.5) test_eq(15/3.0,5.0) test_eq(12.0/3,4.0) test_eq(14.0/4,3.5) test_eq(15.0/3,5.0) test_eval_error(return 15.0/0.0) test_equal("foo-bar-gazonk"/"-",({"foo","bar","gazonk"})) test_equal("foobargazonk"/"",({"f","o","o","b","a","r","g","a","z","o","n","k"})) test_equal(({1,0,1,2,1,2,2,2,1,1,1})/({2}),({ ({1,0,1}), ({1}), ({}), ({}), ({1,1,1}) })) test_equal(({1,2,3,4})/({}),({ ({1}), ({2}), ({3}), ({4}) }))
+
test_eq(sizeof(allocate(119)/({})), 119)
+
test_eq(sizeof(allocate(120)/({})), 120)
+
test_eq(sizeof(allocate(121)/({})), 121)
+
test_eq(sizeof(allocate(122)/({})), 122)
test_equal(({1,0,1,2,1,2,2,2,1,1,1})/({2,1}),({ ({1,0,1}), ({2,2}), ({1,1}) })) test_equal( ({1,2,3})/({2,3}), ({ ({1}), ({}) }) ) test_eq([[`/(20,2,2)]],5) test_eq([[`/(13,2,3)]],2) test_equal("foobargazonk"/1,"foobargazonk"/"") test_equal("foobargazonk"/2,({"fo","ob","ar","ga","zo","nk"})) test_equal("foobargazonk"/3,({"foo","bar","gaz","onk"})) test_equal("foobargazonk"/4,({"foob","arga","zonk"})) test_equal("foobargazonk"/5,({"fooba","rgazo"})) test_equal("foobargazonk"/-6,({"foobar","gazonk"})) test_equal("foobargazonk"/-7,({"rgazonk"}))
-
+
test_eq(({})/100.0, ({}));
+
test_eq(({})/100, ({}));
test_equal("foobargazonk"/5.0,({"fooba","rgazo","nk"})) test_equal("foobargazonk"/-5.0,({"fo","obarg","azonk"})) test_equal("foobargazonk"/2.5,({"foo","ba","rga","zo","nk"})) test_equal("foo"/2.6,({"foo",""})) test_equal("\1233oo"/2.6,({"\1233oo",""})) test_equal("f\777\777bargaz\777nk"/1,"f\777\777bargaz\777nk"/"") test_equal("f\777\777bargaz\777nk"/2,({"f\777","\777b","ar","ga","z\777","nk"})) test_equal("f\777\777bargaz\777nk"/3,({"f\777\777","bar","gaz","\777nk"})) test_equal("f\777\777bargaz\777nk"/4,({"f\777\777b","arga","z\777nk"})) test_equal("f\777\777bargaz\777nk"/5,({"f\777\777ba","rgaz\777"})) test_equal("f\777\777bargaz\777nk"/-6,({"f\777\777bar","gaz\777nk"})) test_equal("f\777\777bargaz\777nk"/-7,({"rgaz\777nk"})) test_equal("f\777\777bargaz\777nk"/5.0,({"f\777\777ba","rgaz\777","nk"})) test_equal("f\777\777bargaz\777nk"/-5.0,({"f\777","\777barg","az\777nk"})) test_equal("f\777\777bargaz\777nk"/2.5,({"f\777\777","ba","rga","z\777","nk"}))
-
+
test_equal(""/"hej", ({""}))
+
test_equal("hej"/"hej", ({"",""}))
test_equal("f\7777777\7777777bargaz\7777777nk"/1,"f\7777777\7777777bargaz\7777777nk"/"") test_equal("f\7777777\7777777bargaz\7777777nk"/2,({"f\7777777","\7777777b","ar","ga","z\7777777","nk"})) test_equal("f\7777777\7777777bargaz\7777777nk"/3,({"f\7777777\7777777","bar","gaz","\7777777nk"})) test_equal("f\7777777\7777777bargaz\7777777nk"/4,({"f\7777777\7777777b","arga","z\7777777nk"})) test_equal("f\7777777\7777777bargaz\7777777nk"/5,({"f\7777777\7777777ba","rgaz\7777777"})) test_equal("f\7777777\7777777bargaz\7777777nk"/-6,({"f\7777777\7777777bar","gaz\7777777nk"})) test_equal("f\7777777\7777777bargaz\7777777nk"/-7,({"rgaz\7777777nk"})) test_equal("f\7777777\7777777bargaz\7777777nk"/5.0,({"f\7777777\7777777ba","rgaz\7777777","nk"})) test_equal("f\7777777\7777777bargaz\7777777nk"/-5.0,({"f\7777777","\7777777barg","az\7777777nk"}))
pike.git/src/testsuite.in:3912:
test_eq(0 || 0,0) test_eq(1 || 1,1) test_eq(78 || 1,78) test_eq(78 || 0,78) // testing | test_eq(0 | 0,0) test_eq(1 | 1,1) test_eq(4 | 1,5) test_eq(1 | 9,9)
-
test_equal( ({1,2,3,4,4}) | ({3,5,6}), ({1,2,4,4,
3,
5,6}))
+
test_
eq([[ "\007" | "\023"]],"\027")
+
test_eq([[ "\177777x" | "ab" ]], "\177777z")
+
test_
equal( ({1,2,3,4,4}) | ({3,5,6}), ({1,2,
3,
4,4,5,6}))
test_equal( (<4,5,6>) | (<5,5,5>), (<4,5,5,5,6>) ) test_equal( ([-4:8,8:7]) | ([3:3,8:3]), ([-4:8,8:3,3:3]) ) test_any([[ class Foo {int `< (object o) {return 0;}}; return sizeof (({Foo()}) | ({Foo()})); ]], 2) // testing & test_eq(0 & 0,0) test_eq(1 & 1,1) test_eq(4 & 1,0) test_eq(1 & 9,1)
-
+
test_eq([[ "\007" & "\023"]],"\003")
+
test_eq([[ "\177777x" & "ab" ]], "a`")
test_equal( ({1,2,3,4,4}) & ({3,5,6}), ({3})) test_equal( (<4,5,6>) & (<5,5,5>), (<5>) ) test_equal( ([-4:8,8:7]) & ([3:3,8:3]), ([8:3]) )
-
+
test_equal(({1,2,1}) & ({1,2}), ({1,2}))
+
test_equal(({2,1,2}) & ({1,2}), ({2,1}))
+
test_equal(({1,2,1,2,2}) & ({1,2}), ({1,2}))
+
test_equal(({2,1,2,1,2}) & ({1,2}), ({2,1}))
// testing ^ test_eq(0 ^ 0,0) test_eq(1 ^ 1,0) test_eq(4 ^ 1,5) test_eq(1 ^ 9,8)
-
test_
equal
(
Array.sort
( ({1,2,3,4,4}) ^ ({3,5,6})
)
, ({1,2,4,4,5,6}))
+
test_
eq
(
[[
"\007" ^ "\023"]],"\024")
+
test_eq
(
[[
"\177777x" ^ "ab" ]], "\177636\32")
+
test_equal
(
(
{1,2,3,4,4}) ^ ({3,5,6}) , ({1,2,4,4,5,6}))
test_equal( (<4,5,6>) ^ (<5,5,5>), (<4,5,5,6>) ) test_equal( ([-4:8,8:7]) ^ ([3:3,8:3]), ([-4:8,3:3]) )
-
+
test_equal(({1,3,3,3,4}) ^ ({2,3,3,5}), ({1,3,4,2,5}))
+
test_equal(({1,3,3,4}) ^ ({2,3,3,3,5}), ({1,4,2,3,5}))
// testing << test_eq(1<<0,1) test_eq(1<<1,2) test_eq(1<<10,1024) test_eq(5<<3,40)
-
+
test_eval_error(return 17<<-10)
// testing >> test_eq(9>>2,2) test_eq(1>>1,0) test_eq(1024>>10,1) test_eq(47>>3,5)
-
+
test_eq(-10>>10000,-1)
+
test_eval_error(return 17>>-10)
// testing ? : test_true(0?0:1) test_true(1?1:0) test_true(""?1:0) test_true(!0?1:0) test_true(!(!1)?1:0) test_true(this_object()?1:0) test_true(a?1:0) // a is the test function test_true(0.0?1:0) test_true(([])?1:0) test_true(({})?1:0) test_true((<>)?1:0) test_true(object_program(this_object())?1:0) test_eq(1 ? "a" : 1 ? "b" : 1, "a") test_eq(0 ? "a" : 1 ? "b" : 1 ? "c" : 1, "b") test_eq(0 ? "a" : 0 ? "b" : 1 ? "c" : 1, "c")
-
+
// testing overflow checks
+
test_eq(-1 - 0x7fffffff, -0x80000000)
+
test_eq(Int.NATIVE_MIN % -1, 0)
+
test_eq(Int.NATIVE_MAX % Int.NATIVE_MIN, -1)
+
// testing indexing test_eq("foo"[0],'f') test_eq("foo"[1],'o') test_eq("foo"[2],'o') test_eq("foo"[-1],'o') test_eq("foo"[-2],'o') test_eq("foo"[-3],'f') test_eq("f\777\777"[0],'f') test_eq("f\777\777"[1],'\777')
pike.git/src/testsuite.in:3998:
test_eq(({'f','o','o'})[0],'f') test_eq(({'f','o','o'})[1],'o') test_eq(({'f','o','o'})[2],'o') test_eq(({'f','o','o'})[-1],'o') test_eq(({'f','o','o'})[-2],'o') test_eq(({'f','o','o'})[-3],'f') test_eq(([0:'f',1:'o',2:'o'])[0],'f') test_eq(([0:'f',1:'o',2:'o'])[1],'o') test_eq(([0:'f',1:'o',2:'o'])[2],'o')
-
test_eq(([0:'f',1:'o',2:'o'])[
3
],0)
-
test_eq(([0:'f',1:'o',2:'o'])[-1],0)
+
test_eq(([0:'f',1:'o',2:'o'])[
random(0)+3
],0)
+
test_eq(([0:'f',1:'o',2:'o'])[
random(0)
-1],0)
test_eq((<'f','o','o'>)['o'],1) test_eq((<'f','o','o'>)['f'],1)
-
test_eq((<'f','o','o'>)['b'],0)
+
test_eq((<'f','o','o'>)[
random(0)+
'b'],0)
test_eq((<'f','o','o'>)[-1],0) test_eq([[class Z { mixed `->(mixed x) { return this_object()[x]; } int foo() { return 1; }}()->foo()]],1)
-
+
// Test some indexing opcodes.
+
test_eval_error([[return ({1})[1];]])
+
test_eval_error([[int i = 1; return ({1})[i];]])
+
test_eval_error([[array a = ({ 1 }); return a[1];]])
+
test_eval_error([[array a = ({ 1 }); int i = 1; return a[i];]])
+
// index assigning test_any(mixed a=({1}); a[0]=2; return equal(a,({2})),1) test_any(mixed a=(<1>); a[1]=2; return equal(a,(<1>)),1) test_any(mixed a=(<1>); a[0]=2; return equal(a,(<1,0>)),1) test_any(mixed a=(<1>); a[1]=0; return equal(a,(<>)),1) test_any(mixed a=(<1>); a[0]=0; return equal(a,(<1>)),1) test_any(mixed a=([1:1]); a[0]=0; return equal(a,([1:1,0:0])),1) test_any(mixed a=([1:1]); a[1]=0; return equal(a,([1:0])),1)
-
+
test_any(mixed a="hej"; a[1]='o'; return a,"hoj")
+
test_do( string x=" "*73; x[64]=1; x[65]=1; )
test_define_program(test,[[public int q,w,e,r; mixed t; mixed getw() { return w; } void setw(int _) { w=_; }]])
-
test_eq(
clone(
test)->q,0)
-
test_eq(
clone(
test)->w,0)
-
test_eq(
clone(
test)->e,0)
-
test_eq(
clone(
test)->r,0)
-
test_eq(
clone(
test)->getw(),0)
-
test_any(object o=
clone(
test); o->setw(17); return o->w,17)
-
test_any(object o=
clone(
test); o->w=17; return o->getw(),17)
+
test_eq(
test
()->q,0)
+
test_eq(
test
()->w,0)
+
test_eq(
test
()->e,0)
+
test_eq(
test
()->r,0)
+
test_eq(
test
()->getw(),0)
+
test_any(object o=
test
(); o->setw(17); return o->w,17)
+
test_any(object o=
test
(); o->w=17; return o->getw(),17)
-
test_eq(
clone(
test)["q"],0)
-
test_eq(
clone(
test)["w"],0)
-
test_eq(
clone(
test)["e"],0)
-
test_eq(
clone(
test)["r"],0)
-
test_eq(
clone(
test)["getw"](),0)
-
test_any(object o=
clone(
test); o["setw"](17); return o["w"],17)
-
test_any(object o=
clone(
test); o["w"]=17; return o["getw"](),17)
+
test_eq(
test
()["q"],0)
+
test_eq(
test
()["w"],0)
+
test_eq(
test
()["e"],0)
+
test_eq(
test
()["r"],0)
+
test_eq(
test
()["getw"](),0)
+
test_any(object o=
test
(); o["setw"](17); return o["w"],17)
+
test_any(object o=
test
(); o["w"]=17; return o["getw"](),17)
+
test_do(add_constant("test");)
// testing range test_eq("foObar"[0..0],"f") test_eq("foobargazonk"[3..5],"bar") test_eq("foo"[1..10],"oo") test_eq("foo"[-100..0],"f") test_eq("foo"[-100..100],"foo")
-
test_
eq
("foo"[1..0],"")
-
test_
eq
("foo"[0..
-100
],"")
+
ignore_warning("Range is always empty.", [[
+
test_
any
(
return
"foo"[1..0]
;
,"")
+
]])
+
test_
any
(
int u=-100; return
"foo"[0..
u
]
;
,"")
dnl Use variable to avoid warning.
test_eq("foobargazonk"[0..],"foobargazonk") test_eq("foobargazonk"[1..],"oobargazonk") test_eq("foobargazonk"[5..],"rgazonk") test_eq("foobargazonk"[..2],"foo") test_eq("foobargazonk"[..5],"foobar")
-
+
test_eq("1234"[..Int.NATIVE_MAX], "1234")
+
test_eq("1234"[..Int.NATIVE_MAX - 1], "1234")
+
test_eq("1234"[Int.NATIVE_MIN..], "1234")
+
test_eq("1234"[Int.NATIVE_MIN + 1..], "1234")
test_eq("f\7777\7777bargaz\7777nk"[0..],"f\7777\7777bargaz\7777nk") test_eq("f\7777\7777bargaz\7777nk"[1..],"\7777\7777bargaz\7777nk") test_eq("f\7777\7777bargaz\7777nk"[5..],"rgaz\7777nk") test_eq("f\7777\7777bargaz\7777nk"[..2],"f\7777\7777") test_eq("f\7777\7777bargaz\7777nk"[..5],"f\7777\7777bar") test_eq("f\77777777\77777777bargaz\77777777nk"[0..],"f\77777777\77777777bargaz\77777777nk") test_eq("f\77777777\77777777bargaz\77777777nk"[1..],"\77777777\77777777bargaz\77777777nk") test_eq("f\77777777\77777777bargaz\77777777nk"[5..],"rgaz\77777777nk") test_eq("f\77777777\77777777bargaz\77777777nk"[..2],"f\77777777\77777777") test_eq("f\77777777\77777777bargaz\77777777nk"[..5],"f\77777777\77777777bar") test_equal(({1,2,3})[0..0],({1})) test_equal(({1,2,3})[1..2],({2,3})) test_equal(({1,2,3})[2..10],({3})) test_equal(({1,2,3})[-100..0],({1})) test_equal(({1,2,3})[-100..100],({1,2,3}))
-
test_equal(({1,2,3})[1..0],({}))
-
test_equal(({1,2,3})[0..
-100
],({}))
+
ignore_warning("Range is always empty.", [[
+
test_
any_
equal(
return
({1,2,3})[1..0]
;
,({}))
+
]])
+
test_
any_
equal(
int u=-100; return
({1,2,3})[0..
u
]
;
,({}))
dnl Use variable to avoid warning.
-
+
test_eq("abcdef"[1..3], "bcd")
+
test_eq("abcdef"[1..<3], "bc")
+
test_eq("abcdef"[1..], "bcdef")
+
test_eq("abcdef"[<1..3], "")
+
test_eq("abcdef"[<1..<3], "")
+
test_eq("abcdef"[<1..], "ef")
+
test_eq("abcdef"[<3..3], "cd")
+
test_eq("abcdef"[<3..<3], "c")
+
test_eq("abcdef"[<3..], "cdef")
+
test_eq("abcdef"[..3], "abcd")
+
test_eq("abcdef"[..<3], "abc")
+
ignore_warning("Redundant range operator.", [[
+
test_eq("abcdef"[..], "abcdef")
+
]])
+
+
test_equal(`[..] ("abcdef"/"", 1, Pike.INDEX_FROM_BEG, 3, Pike.INDEX_FROM_BEG), "bcd"/"");
+
test_equal(`[..] ("abcdef"/"", 1, Pike.INDEX_FROM_BEG, 3, Pike.INDEX_FROM_END), "bc"/"");
+
test_equal(`[..] ("abcdef"/"", 1, Pike.INDEX_FROM_BEG, 3, Pike.OPEN_BOUND), "bcdef"/"");
+
test_equal(`[..] ("abcdef"/"", 3, Pike.INDEX_FROM_END, 3, Pike.INDEX_FROM_BEG), "cd"/"");
+
test_equal(`[..] ("abcdef"/"", 3, Pike.INDEX_FROM_END, 3, Pike.INDEX_FROM_END), "c"/"");
+
test_equal(`[..] ("abcdef"/"", 3, Pike.INDEX_FROM_END, 3, Pike.OPEN_BOUND), "cdef"/"");
+
test_equal(`[..] ("abcdef"/"", 1, Pike.OPEN_BOUND, 3, Pike.INDEX_FROM_BEG), "abcd"/"");
+
test_equal(`[..] ("abcdef"/"", 1, Pike.OPEN_BOUND, 3, Pike.INDEX_FROM_END), "abc"/"");
+
test_equal(`[..] ("abcdef"/"", 1, Pike.OPEN_BOUND, 3, Pike.OPEN_BOUND), "abcdef"/"");
+
+
define(test_new_style, [[
+
test_any_equal([[
+
object new_style = class {
+
array(int) `[..] (int... args) {return args;}
+
}();
+
return new_style $1;
+
]], $2)
+
]])
+
test_new_style([1..3], ({1, Pike.INDEX_FROM_BEG, 3, Pike.INDEX_FROM_BEG}))
+
test_new_style([1..<3], ({1, Pike.INDEX_FROM_BEG, 3, Pike.INDEX_FROM_END}))
+
test_new_style([1..], ({1, Pike.INDEX_FROM_BEG, 0, Pike.OPEN_BOUND}))
+
test_new_style([<1..3], ({1, Pike.INDEX_FROM_END, 3, Pike.INDEX_FROM_BEG}))
+
test_new_style([<1..<3], ({1, Pike.INDEX_FROM_END, 3, Pike.INDEX_FROM_END}))
+
test_new_style([<1..], ({1, Pike.INDEX_FROM_END, 0, Pike.OPEN_BOUND}))
+
test_new_style([..3], ({0, Pike.OPEN_BOUND, 3, Pike.INDEX_FROM_BEG}))
+
test_new_style([..<3], ({0, Pike.OPEN_BOUND, 3, Pike.INDEX_FROM_END}))
+
test_new_style([..], ({0, Pike.OPEN_BOUND, 0, Pike.OPEN_BOUND}))
+
undefine([[test_new_style]])
+
+
define(test_old_style, [[
+
test_any_equal([[
+
object old_style = class {
+
int _sizeof() {return 6;}
+
array(int) `[] (int... args) {return args;}
+
}();
+
return old_style $1;
+
]], $2)
+
]])
+
test_old_style([1..3], ({1, 3}))
+
test_old_style([1..<3], ({1, 2}))
+
test_old_style([1..], ({1, Int.NATIVE_MAX})) dnl Upper bound might become larger.
+
test_old_style([<1..3], ({4, 3}))
+
test_old_style([<1..<3], ({4, 2}))
+
test_old_style([<1..], ({4, Int.NATIVE_MAX})) dnl Upper bound might become larger.
+
test_old_style([..3], ({0, 3}))
+
test_old_style([..<3], ({0, 2}))
+
test_old_style([..], ({0, Int.NATIVE_MAX})) dnl Upper bound might become larger.
+
undefine([[test_old_style]])
+
// casting test_eq([[(int)1]],[[1]]) test_eq([[(int)-1]],[[-1]]) test_eq([[(int)1.0]],[[1]]) test_eq([[(int)-1.0]],[[-1]]) test_eq([[(int)"1"]],[[1]]) test_eq([[(int)"-1"]],[[-1]])
-
+
test_eq([[(int)"0x1"]],[[0]])
+
test_eq([[(int)"010"]],[[10]])
test_eq([[(float)"1"]],[[1.0]]) test_eq([[(float)"-1"]],[[-1.0]]) test_eq([[(float)"1.0"]],[[1.0]]) test_eq([[(float)"-1.0"]],[[-1.0]]) test_eq([[(float)1.0]],[[1.0]]) test_eq([[(float)-1.0]],[[-1.0]]) test_eq([[(float)1]],[[1.0]]) test_eq([[(float)-1]],[[-1.0]]) test_eq([[(string)1]],[["1"]]) test_eq([[(string)-1]],[["-1"]])
-
+
test_eq([[(string)1.0]],[["1.0"]])
+
test_eq([[(string)-1.0]],[["-1.0"]])
+
// Note: 32-bit floats overflow at ~3.4e38.
+
test_true([[has_value ((string)1e38, ".") ||
+
has_value ((string)1e38, "e")]])
+
test_true([[has_value ((string)-1e38, ".") ||
+
has_value ((string)-1e38, "e")]])
+
test_true([[has_value ((string)1e-38, ".") ||
+
has_value ((string)1e-38, "e")]])
+
test_true([[has_value ((string)-1e-38, ".") ||
+
has_value ((string)-1e-38, "e")]])
+
cond([[Float.DIGITS_10 >= 15]], [[ // Usual size with 64 bit IEEE floats.
+
// Note: 1e100 overflows to infinity with 32 bit floats.
+
test_true([[has_value ((string)1e100, ".") ||
+
has_value ((string)1e100, "e")]])
+
test_true([[has_value ((string)-1e100, ".") ||
+
has_value ((string)-1e100, "e")]])
+
]])
+
// Note: 1e-100 underflows to 0.0 with 32 bit IEEE floats, but that's ok.
+
test_true([[has_value ((string)1e-100, ".") ||
+
has_value ((string)1e-100, "e")]])
+
test_true([[has_value ((string)-1e-100, ".") ||
+
has_value ((string)-1e-100, "e")]])
+
test_true([[has_value ((string)124354236143512312334562453624.1, ".") ||
+
has_value ((string)124354236143512312334562453624.1, "e")]])
+
test_eq([[(string) 0.8]], [["0.8"]])
+
cond([[Float.DIGITS_10 >= 6]], [[ // Usual size with 32 bit IEEE floats.
+
test_eq([[(string) 0.811113]], [["0.811113"]])
+
test_eq([[(string) 0.811114]], [["0.811114"]])
+
test_true([[Regexp ("^8\\.11113e\\+0*19$")->match ((string) 0.811113e20)]])
+
test_true([[Regexp ("^8\\.11114e\\+0*19$")->match ((string) 0.811114e20)]])
+
]])
+
cond([[Float.DIGITS_10 >= 15]], [[ // Usual size with 64 bit IEEE floats.
+
test_eq([[(string) 0.811111111111113]], [["0.811111111111113"]])
+
test_eq([[(string) 0.811111111111114]], [["0.811111111111114"]])
+
test_true([[Regexp ("^8\\.11111111111113e\\+0*19$")->match ((string) 0.811111111111113e20)]])
+
test_true([[Regexp ("^8\\.11111111111114e\\+0*19$")->match ((string) 0.811111111111114e20)]])
+
]])
+
test_do(return (string)1e308)
+
test_do(return (string)1e200)
+
test_do(return (string)1e-200)
+
test_do(return (string)1e-307)
+
test_any([[
+
array foo=({ 1 });
+
return (string)sizeof(foo);
+
]], [["1"]])
+
test_any([[
+
array foo=({ -1 });
+
return (string)-sizeof(foo);
+
]], [["-1"]])
test_equal([[(array)(["1":1])]],[[ ({ ({"1", 1}) }) ]]) test_equal([[(array(int)) ({"1","4711",2.0,4})]],[[({1,4711,2,4})]]) test_equal([[(array(array))({({})})]],[[({({})})]]) test_equal([[ (array(array(int))) ({ ({"1","4711",2.0,4}) }) ]],[[ ({ ({1,4711,2,4}) }) ]]) test_equal([[ (array(array(array(int)))) ({ ({ ({"1","4711",2.0,4}) }) }) ]],[[ ({ ({ ({1,4711,2,4}) }) }) ]]) test_equal([[ (array(array(array(array(int))))) ({ ({ ({ ({"1","4711",2.0,4}) }) }) }) ]],[[ ({ ({ ({ ({1,4711,2,4}) }) }) }) ]]) test_equal([[(array)"foo"]],[[ values("foo") ]]) test_equal([[(array)(<1,2,3>)]],[[ indices( (<1,2,3>) )]]) test_equal([[sort(column((array)([1:2,3:4]),0))]],[[ sort(indices(([1:2,3:4])) )]]) test_equal([[sort(column((array)([1:2,3:4]),1))]],[[ sort(values(([1:2,3:4])))]]) test_true([[(array(array))([]) ]]) test_true([[(array(array))([1:2]) ]]) test_true([[(array(array))([1:2,3:4]) ]]) test_true([[(array(array))([1:2,3:4,5:6]) ]]) test_equal( [[ (multiset) ({1})]], [[ (< 1 >) ]] )
-
+
test_equal( [[ (multiset(string)) ({1})]], [[ (< "1" >) ]] )
test_eval_error([[return (mapping)""]]) test_equal([[ (mapping)({({1,2}),({3,4})})]], [[([1:2,3:4]) ]]) test_equal([[ ({({1,2})})]], [[(array)([1:2]) ]]) test_equal([[ (mapping)({})]], [[ ([]) ]]) test_equal([[ ({}) ]], [[ (array)([]) ]]) test_eval_error([[ mapping m=(mapping)({ ({1,2,3}), ({4,5,6}) }); ]])
-
+
test_any([[
+
object x = class {
+
mixed cast (string t) {return t == "string" && "foo";}
+
}();
+
destruct (x);
+
return (string) x;
+
]], "0")
+
+
test_eq([[(string) ({0,1,2})]], "\0\1\2")
+
test_eq([[(string) ({'z', 0xff, '.'})]], "z\xff.")
+
test_eq([[(string) ({'z', 0x100, '.'})]], "z\x100.")
+
test_eq([[(string) ({'z', 0xffff, '.'})]], "z\xffff.")
+
test_eq([[(string) ({'z', 0x10000, '.'})]], "z\x10000.")
+
test_eq([[(string) ({'z', -1, '.'})]], "z\xffffffff.")
+
test_eq([[(string) ({'z', 0x7fffffff, '.'})]], "z\x7fffffff.")
+
test_eval_error([[(string) ({0x80000000})]])
+
test_eq([[(string) ({'z', -0x80000000, '.'})]], "z\x80000000.")
+
test_eval_error([[(string) ({-0x80000001})]])
+
// testing @ test_equal(({1,2,3}),lambda(mixed ... x) { return x; }(@a())) test_equal("foo"/"",lambda(mixed ... x) { return x; }(@a())) test_any([[array a=({1,2,3}); return lambda(mixed ... x) { return x; }(@a) !=a]],1)
-
+
test_any([[array z=({lambda(mixed x){return x;},17});return `()(@z);]],17)
// testing += test_any(int a=1; a+=10; return a,11)
-
+
test_any_equal(mapping m=([]); m->x+=([]); return m->x, ([]))
+
test_any_equal(mapping m=([]); m->x+=(<>); return m->x, (<>))
+
test_any_equal(mapping m=([]); m->x+=({}); return m->x, ({}))
+
test_any_equal([[
+
array a = ({});
+
catch {
+
a += Array.reduce(`+,({}));
+
};
+
return a;
+
]],({}))
+
// testing -= test_any(int a=1; a-=10; return a,-9) // testing &= test_any(int a=3; a&=10; return a,2) // testing |= test_any(int a=3; a|=10; return a,11)
-
+
test_any(int a = UNDEFINED; a|=1; return zero_type(a), 0)
+
test_any_equal(array a=({ "x" }); a|=({"x","y"}); return a, ({"x","y"}))
+
test_any_equal(array a=({ "x" }); a|=({"y"}); return a, ({"x","y"}))
+
test_any_equal(array a=({ "x" }); a|=({"x"}); return a, ({"x"}))
+
test_any_equal(array a=({ "x" }); a|=a; return a, ({"x"}))
+
test_any_equal(array a=({ "x" }); mapping m=(["a":a]); a|=({"x","y"}); return a, ({"x","y"}))
+
test_any_equal(array a=({ "x" }); mapping m=(["a":a]); a|=({"y"}); return a, ({"x","y"}))
+
test_any_equal(array a=({ "x" }); mapping m=(["a":a]); a|=({"x"}); return a, ({"x"}))
+
test_any_equal(array a=({ "x" }); mapping m=(["a":a]); a|=a; return a, ({"x"}))
// testing ^= test_any(int a=3; a^=10; return a,9) // testing <<= test_any(int a=3; a<<=2; return a,12) // testing <<= test_any(int a=12; a>>=2; return a,3) // testing *= test_any(int a=12; a*=2; return a,24) // testing /= test_any(int a=12; a/=2; return a,6)
pike.git/src/testsuite.in:4189:
test_any(int e;string t=""; for(e=2;e!=10;e++) t+=e; return t,"23456789") test_any(int e;string t=""; for(e=0;e>-10;e--) t+=e; return t,"0-1-2-3-4-5-6-7-8-9") // foreach test_any([[int e;string t=""; foreach(({7,6,3,8}),e) t+=e; return t]],"7638") test_any([[ /* FIXME: This test needs to be proofed against the optimizer. */ string s;if(1) foreach(({}),s); else foreach(({}),s); return 1 ]],1)
+
test_any([[
+
int ret;
+
foreach( ([1:2,3:5,7:11,13:17]) ; int a ; int b) ret+=a*b;
+
return ret;
+
]],315)
+
+
test_any([[
+
int ret;
+
foreach( ([1:2,3:5,7:11,13:17]) ; ; int b) ret+=b;
+
return ret;
+
]],35)
+
+
test_any([[
+
int ret;
+
foreach( ([1:2,3:5,7:11,13:17]) ; int a; ) ret+=a;
+
return ret;
+
]],24)
+
+
test_any([[
+
int ret;
+
foreach( (<1,3,7,13>) ; ; int b) ret+=b;
+
return ret;
+
]],4)
+
+
test_any([[
+
int ret;
+
foreach( (<1,3,7,13>) ; int a; ) ret+=a;
+
return ret;
+
]],24)
+
+
test_any([[
+
int ret;
+
foreach( (<1,3,7,13>) ; ; ) ret++;
+
return ret;
+
]],4)
+
+
+
test_any([[
+
int ret;
+
foreach( (<1,3,7,13>) ; int a; int b) ret+=a+b;
+
return ret;
+
]],24+4)
+
+
test_any([[
+
int ret;
+
foreach( ({2,5,11,17}) ; int a; ) ret+=a;
+
return ret;
+
]],6)
+
+
test_any([[
+
int ret;
+
foreach( ({2,5,11,17}) ; ; int b) ret+=b;
+
return ret;
+
]],35)
+
+
test_any([[
+
int ret;
+
foreach( ({2,5,11,17}) ; int a; int b) ret+=a*b;
+
return ret;
+
]],78)
+
+
test_any([[
+
int ret;
+
foreach( ({2,5,11,17}) ; ; ) ret++;
+
return ret;
+
]],4)
+
+
test_any([[
+
int ret;
+
foreach( "foobar" ; int a; int b) ret+=a*b;
+
return ret;
+
]],1585)
+
+
test_any([[
+
int ret;
+
foreach( "foobar" ; int a;) ret+=a;
+
return ret;
+
]],15)
+
+
test_any([[
+
int ret;
+
foreach( "foobar" ; ; int b) ret+=b;
+
return ret;
+
]],633)
+
+
test_any([[
+
mapping m=([1:2,3:5,7:11,13:17]);
+
foreach(m; int a; int b) if (m_delete(m,a) != b) return -1;
+
return sizeof(m);
+
]],0)
+
+
test_any([[
+
mapping m=([1:2,3:5,7:11,13:17]);
+
int ret;
+
foreach(m ; int a ; int b) { m_delete(m,a); ret+=a*b; }
+
return ret;
+
]],315)
+
+
test_eval_error([[
+
int i;
+
foreach (class{}(); mixed a; mixed b) i++;
+
return i;
+
]])
+
+
test_any([[
+
String.Iterator iter = String.Iterator ("foo");
+
foreach (iter; int idx;)
+
if (idx != iter->index()) return 1;
+
return 0;
+
]], 0)
+
+
test_any([[
+
mapping(object:int) x = ([]);
+
object o = class {}();
+
x[o] = 1;
+
destruct (o);
+
int i;
+
foreach (x;;) i++;
+
return i;
+
]], 0)
+
+
test_any([[
+
multiset(object) x = (<>);
+
object o = class {}();
+
x[o] = 1;
+
destruct (o);
+
int i;
+
foreach (x;;) i++;
+
return i;
+
]], 0)
+
+
test_any([[
+
// Check foreach iterator stepping behavior.
+
array a = indices (allocate (7));
+
Array.Iterator i = get_iterator (a);
+
foreach (i;; int v)
+
if (v > 3) break;
+
foreach (i;; int v)
+
if (v < 5) break;
+
foreach (i;; int v)
+
return v;
+
]], 4)
+
// do-while test_any(int e;string t=""; e=0; do{ t+=e; }while(++e<6); return t,"012345";) // while test_any(int e;string t=""; e=8; while(--e) t+=e; return t,"7654321";) test_any(int e;string t=""; e=8; while(e--) t+=e; return t,"76543210";) test_any(int e;string t=""; e=0; while(++e<6) t+=e; return t,"12345";) test_any(int e=1;string t=""; while(e<20){t+=e;e*=2;} return t,"124816";) // Switch
pike.git/src/testsuite.in:4290:
test_switch3($5,$2,$3,$4,$5,5) ]]) test_switch4(17,18,19,20,21) test_switch4("a","b","c","d","e") test_switch4("a",0,"c","d","e") test_switch4(1.0,2.0,3.0,4.0,5.0) test_switch4(this_object(),"",0,4.0,1) test_any(int e;string t=""; for(e=0;e<10;e++) switch(e) { default: t+=e; case 4..8: } return t,"01239")
-
test_any([[float e,q; q=0.0; for(e=0.1;e<10.0;e+=1.0) switch(e) { default: q+=e; case 4.0..8.0: } return q]],0.1+1.1+2.1+3.1+8.1+9.1)
+
-
+
// use sprintf here; the sums aren't totally equal for doubles (error~=1e-16)
+
test_any([[float e,q; q=0.0; for(e=0.1;e<10.0;e+=1.0) switch(e) { default: q+=e; case 4.0..8.0: } return sprintf("%.6f",q)]],[[sprintf("%.6f",0.1+1.1+2.1+3.1+8.1+9.1)]])
+
+
test_compile_error([[switch (1) {case 1: break; case 1: break;}]])
+
test_compile_error([[switch (1) {case 1: break; case 0..2: break;}]])
+
test_compile_error([[switch (1) {case 1..2: break; case 0..3: break;}]])
+
test_compile_error([[switch (1) {case 1..3: break; case 0..2: break;}]])
+
test_compile_error([[switch (1) {case 1..2: break; case 0..: break;}]])
+
test_compile_error([[switch (1) {case 1..2: break; case ..3: break;}]])
+
test_compile_error([[switch (1) {case 1..: break; case ..3: break;}]])
+
test_compile_error([[switch (1) {case ..: break;}]])
+
test_compile_error([[switch (1) {case "x"..: break;}]])
+
test_compile_error([[switch (1) {case .."y": break;}]])
+
test_compile_error([[switch (1) {case "x".."y": break;}]])
+
+
define(test_switch_ranges,[[
+
test_any_equal([[
+
int f (int i) {{$1;} return 0;};
+
array res = ({});
+
for (int i = -3; i <= 3; i++) res += ({f (i)});
+
return res;
+
]], $2)
+
]])
+
+
test_switch_ranges([[
+
switch (i) {case 1..2: return 2; case -2..-1: return 1;}
+
]], ({0, 1, 1, 0, 2, 2, 0}))
+
test_switch_ranges([[
+
switch (i) {case 1..2: return 2; case -2..0: return 1;}
+
]], ({0, 1, 1, 1, 2, 2, 0}))
+
test_switch_ranges([[
+
switch (i) {case 1..2: return 2; case -2..-1: return 1; case 0: return 3;}
+
]], ({0, 1, 1, 3, 2, 2, 0}))
+
test_switch_ranges([[
+
switch (i) {case 1..2: return 2; case ..-1: return 1; case 0: return 3;}
+
]], ({1, 1, 1, 3, 2, 2, 0}))
+
test_switch_ranges([[
+
switch (i) {case 1..: return 2; case -2..-1: return 1; case 0: return 3;}
+
]], ({0, 1, 1, 3, 2, 2, 2}))
+
test_switch_ranges([[
+
switch (i) {case 1..: return 2; case ..-1: return 1; case 0: return 3;}
+
]], ({1, 1, 1, 3, 2, 2, 2}))
+
// Breaks and continues with labels
-
+
test_compile_error([[break;]])
+
test_compile_error([[continue;]])
+
test_compile_error([[foo: break;]])
+
test_compile_error([[foo: continue;]])
+
test_compile_error([[break foo;]])
+
test_compile_error([[continue foo;]])
+
test_any([[foo: break foo; return 1;]], 1)
+
test_compile_error([[foo: continue foo;]])
test_compile_error([[int a; foo: if (a++) a++; else foo: a++;]]) test_compile_error([[int a; foo: foo: if (a++) a++; else a++;]]) test_compile([[int a; foo: if (a++) a++; foo: a++;]]) test_compile_error([[int a; do if (a++) break foo; while (0);]]) test_compile([[int a; do foo: if (a++) break foo; while (0);]]) test_compile([[int a; foo: do if (a++) break foo; while (0);]]) test_compile_error([[int a; do foo: if (a++) continue foo; while (0);]]) test_compile([[int a; foo: do if (a++) continue foo; while (0);]])
-
+
test_any([[
+
int i;
+
for (i = 1; i <= 4; i++)
+
foo: break;
+
return i;
+
]], 1);
+
test_any([[
+
int i;
+
for (int j = 1; j <= 4; j++) {
+
foo: continue;
+
i = j;
+
}
+
return i;
+
]], 0);
+
test_any([[
+
int i;
+
for (i = 1; i <= 4; i++)
+
foo: {
+
if (i > 5) break foo;
+
break;
+
}
+
return i;
+
]], 1);
test_any_equal([[ int a, b; foo: for (int i = 1; i <= 4; i++) { a = i; switch (1) { case 1: if (i >= 3) break foo; if (i >= 2) continue foo; }
pike.git/src/testsuite.in:4339:
test_any_equal([[ array res = ({}); foreach (({1, 2, 3}), int x) { res += ({-x}); foo: foreach (({1, 2, 3, 4}), int i) { res += ({i}); foreach (({1, 2}), int y) { if (i >= 3) break foo; if (i >= 2) continue foo;
+
y;
} res += ({i}); } } return res; ]], ({-1, 1, 1, 2, 3, -2, 1, 1, 2, 3, -3, 1, 1, 2, 3})); test_any_equal([[ int a, b; foo: for (int i = 1; i <= 4; i++) {
pike.git/src/testsuite.in:4375:
catch { catch { if (i >= 3) break; if (i >= 2) continue; }; }; b += i; } return ({a, b}); ]], ({4, 8}));
+
test_any([[
+
foo:
+
if (stringp (catch {int q=1; break foo;}) + 1) return 1;
+
else return 2;
+
return 3;
+
]], 3);
+
test_any([[
+
foo:
+
do {
+
if ((3*time() + 5) + stringp (catch {int q=1; break foo;})) return 1;
+
else return 2;
+
} while (0);
+
return 3;
+
]], 3);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (1,2,3, gauge {break foo;},4,5);
+
]]);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (@indices (all_constants()), gauge {break foo;});
+
]]);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (1,2,3, catch {int q=1; break foo;},4,5);
+
]]);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (@indices (all_constants()), catch {int q=1; break foo;});
+
]]);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (@({1,2,3,4,5}), catch {int q=1; break foo;});
+
]]);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (@indices (all_constants()), @allocate (511, 1), catch {int q=1; break foo;});
+
]]);
+
test_do([[
+
void gnu (mixed... args) {};
+
foo:
+
gnu (@allocate (511, 1), @indices (all_constants()), catch {int q=1; break foo;});
+
]]);
+
test_compile_error([[
+
foo: {
+
@indices (all_constants());
+
break foo;
+
}
+
]]);
+
test_do([[
+
// Note: This is valid <= 7.0 code.
+
foreach (({1,2,3}), int j)
+
do
+
if (17 + j + gauge {break;}) return 0;
+
while (0);
+
]]);
+
test_do([[
+
// Note: This is valid <= 7.0 code.
+
foreach (({1,2,3}), int j)
+
do
+
if (17 - j - gauge {break;}) return 0;
+
while (0);
+
]]);
+
test_do([[
+
int gnu (mixed... args) {};
+
gnu(@indices (all_constants()), gauge {
+
foreach (({1,2,3}), int j)
+
do
+
if (j && gnu(@indices (all_constants()),
+
17 + gauge {break;}))
+
return 0;
+
while (0);
+
});
+
]]);
+
test_do([[
+
int gnu (mixed... args) {};
+
foo:
+
gnu(@indices (all_constants()), gauge {
+
foreach (({1,2,3}), int j)
+
do
+
if (j && gnu(@indices (all_constants()),
+
17 + gauge {break foo;}))
+
return 0;
+
while (0);
+
});
+
]]);
cond([[all_constants()->_verify_internals]], [[ test_do(_verify_internals()) ]])
-
+
test_compile_any([[import Stdio.Readline; mapping x=([]);]]);
+
// testing preprocessor
-
test_eq([[cpp("#define FOO(X,Y) (X) (Y)\nFOO( (A),(B) )")]],"# 1 \"-\"\n\n( (A) ) ( (B) )")
-
test_eq([[cpp("#define F 'F'\nF")]],"# 1 \"-\"\n\n'F'")
-
test_eq([[cpp("#define MAX(X,Y) ((X)>(Y)?(X):(Y))\n#define MAX3(X,Y,Z) MAX(MAX(X,Y),Z)\nMAX3(1,2,3)")]],"# 1 \"-\"\n\n\n(( (( 1 )>( 2 )?( 1 ):( 2 )) )>( 3 )?( (( 1 )>( 2 )?( 1 ):( 2 )) ):( 3 ))")
+
test_eq([[cpp("#define FOO(X,Y) (X) (Y)\nFOO( (A),(B) )")]],"#
line
1 \"-\"\n\n( (A) ) ( (B) )")
+
test_eq([[cpp("#define
FOO(X)\nFOO BAR")]],"#line 1 \"-\"\n\nFOO BAR")
+
test_eq([[cpp("#define
F 'F'\nF")]],"#
line
1 \"-\"\n\n'F'")
+
test_eq([[cpp("#define MAX(X,Y) ((X)>(Y)?(X):(Y))\n#define MAX3(X,Y,Z) MAX(MAX(X,Y),Z)\nMAX3(1,2,3)")]],"#
line
1 \"-\"\n\n\n(( (( 1 )>( 2 )?( 1 ):( 2 )) )>( 3 )?( (( 1 )>( 2 )?( 1 ):( 2 )) ):( 3 ))")
test_eq([[cpp("foo\xfeff""bar \xfeff gazonk")]],[[cpp("foobar gazonk")]])
-
+
test_eq([[cpp("#define A(X) #X\n#define B(Y) A(Y)\nB(foo)")]],
+
"#line 1 \"-\"\n\n\n \"foo\" ")
+
test_eq([[cpp("#define FOO(X) X\nFOO(\"\\\n\")\n")]], "#line 1 \"-\"\n\n\n \"\" \n");
+
test_eq([[cpp("#define FOO(X) X\r\nFOO(\"\\\r\n\")\r\n")]], "#line 1 \"-\"\n\n\n \"\" \n" /* Note: Added extra space for \r. */);
+
test_equal([[compile_string("#define FOO(X) X\nstring s=FOO(\"\\\n\\\n\");\nmixed f() {return ({__LINE__, backtrace()[-1][1]});}\n")()->f()]], ({5, 5}));
+
test_equal([[compile_string("#define FOO(X) X\nstring s=FOO(#\"\n\n\");\nmixed f() {return ({__LINE__, backtrace()[-1][1]});}\n")()->f()]], ({5, 5}));
+
test_equal([[
+
compile_string("#define FOO BAR\n"
+
"#define TOSTR(X) #X\n"
+
"#define TOSTR2(X) TOSTR(X)\n"
+
"constant val = TOSTR2(FOO);\n")()->val;
+
]], "BAR")
+
test_equal([[
+
compile_string("#define FOO\n"
+
"#define TOSTR(X) #X\n"
+
"#define TOSTR2(X) TOSTR(X)\n"
+
"constant val = TOSTR2(FOO);\n")()->val;
+
]], "")
+
test_eq([[cpp("foo _Pragma(\"strict_types \\\\back \\\"str\\\"\") bar")]],
+
"#line 1 \"-\"\nfoo \n#pragma strict_types \\back \"str\"\n#line 1 \"-\"\n bar")
+
test_equal([[
+
compile_string(Charset.encoder("ebcdic-us")->
+
feed("#charset ebcdic-us\n"
+
"constant val = \"abc\";\n")->drain())()->val;
+
]], "abc")
+
test_eq([[cpp("\\\n")]], "#line 1 \"-\"\n\n")
+
test_eq([[cpp("#if 1\\\n-1\nfoo\n#endif\n")]], "#line 1 \"-\"\n\n\n\n\n")
+
test_any([[
+
Stdio.write_file("testsuite_test.h", "");
+
return compile_string(#"
+
#include \"\\
+
testsuite_test.h\"
+
int line = __LINE__;
+
")()->line;
+
]], 4)
+
test_do([[cpp(#"
+
#define FOO(X) X
+
FOO(// Pike 7.6 and earlier don't seem to like single
+
/* quotes (') in comments in macro arguments. */
+
arg)")]])
-
test_
any
(
int
e;
object
o
=
clone
(
Stdio.File
);
if
(
!o->open
("
conftest.h
"
,"wct"
))
return
-1;
e
=
o->write
("
return 17;\n
");
if
(
!o->close(
)
)
return
-1;
return
e,11)
+
// The following three tests are in triplicate to force testing in all shifts.
+
test_
do
(
[[
+
#define
FOO(X)
X
+
string
s
=
FOO
(
#"a
+
b
+
c"
);
+
]]);
+
test_do([[
+
#define
FOO
(
X) X
+
string s = FOO
(
#
"
a
+
b
+
c
")
;
+
]]
)
;
+
test_do([[
+
#define
FOO(X)
X
+
string
s
=
FOO
(
#
"
a
+
b
+
c
");
+
]]);
+
test_do([[
+
#define
FOO
(
X
)
X
+
string
s
=
FOO (#"
-
test_
compile_any
([[
import
Stdio.Readline;
mapping
x
=(
[]);]]);
+
");
+
]]);
+
test_
do
([[
+
#define
FOO(X)
X
+
string
s
=
FOO
(
#"
-
+
");
+
]]);
+
test_do([[
+
#define FOO(X) X
+
string s = FOO (#"
+
+
");
+
]]);
test_any([[
-
+
#define FOO(X) X
+
FOO ("\
+
\
+
");
+
return __LINE__;
+
]], 6);
+
test_any([[
+
#define FOO(X) X
+
FOO ("\
+
\
+
");
+
return __LINE__;
+
]], 6);
+
test_any([[
+
#define FOO(X) X
+
FOO ("\
+
\
+
");
+
return __LINE__;
+
]], 6);
+
+
test_any([[
+
#define ab\u0063
+
#ifdef \u0061\
+
bc
+
return 1;
+
#else
+
return 0;
+
#endif
+
]], 1)
+
+
test_any([[
+
#define \U00010330(\U00010331) #\U00010331
+
#define \U00010332(\U00010333) \U00010330 (\U00010333)
+
#define \U00010334 qth
+
return \U00010332 (\U00010334)
+
]], "qth")
+
test_any([[
+
#define \U00010330(\U00010331) #\U00010331
+
#define \U00010332(\U00010333) \U00010330 (\U00010333)
+
#define \U00010334 \u0220qt\u0222h
+
return \U00010332 (\U00010334)
+
]], "\x220qt\x222h")
+
test_any([[
+
#define \U00010330(\U00010331) #\U00010331
+
#define \U00010332(\U00010333) \U00010330 (\U00010333)
+
#define \U00010334 \U00010330qt\u0222h
+
return \U00010332 (\U00010334)
+
]], "\x10330qt\x222h")
+
test_program([[
+
typedef \u0069n\u0074 \u02222;
+
\u0222\u0032 my_\u0223 (\u02222 \u0220) {re\u0074urn \u0220+1\u0031;}
+
int a() {return m\u0079_\u0223 (17) == 28;}
+
]])
+
+
test_eq([[compile_string(#"
+
#define Y(y) #y
+
#define X(x) x(z)
+
string a() {return X(Y);}
+
")()->a()]], "z")
+
test_eq([[compile_string(#"
+
#define Y() \"z\"
+
#define X(x) x()
+
string a() {return X(Y);}
+
")()->a()]], "z")
+
test_compile([[
+
#define Y(y) y
+
#define X(x) x()
+
X(Y)
+
]])
+
test_compile_error([[
+
#define Y(y,z) y
+
#define X(x) x()
+
X(Y)
+
]])
+
test_compile_error([[
+
#define Y() y
+
#define X(x) x(z)
+
X(Y)
+
]])
+
test_true([[compile_string(#"
+
#define Y() z
+
#define X(x) x()
+
int z() {return 0;}
+
mixed a() {return functionp(X(Y));}
+
")()->a()]])
+
test_false([[compile_string(#"
+
#define Y z
+
#define X(x) x()
+
int z() {return 0;}
+
mixed a() {return functionp(X(Y));}
+
")()->a()]])
+
+
test_do([[
+
Stdio.write_file("testsuite_test.pmod", "syntax error");
+
object orig_master = master();
+
replace_master(object_program(orig_master)());
+
mixed err = catch {
+
compile_string(#"
+
#ifdef NONEXISTING_DEFINE
+
#error Not expected
+
#if constant (.testsuite_test)
+
#error Not expected either
+
#endif
+
#endif", "testsuite_test");
+
};
+
replace_master(orig_master);
+
if (err) throw (err);
+
]]);
+
+
test_do([[
+
Stdio.write_file("testsuite_test.pmod", "syntax error");
+
object orig_master = master();
+
replace_master(object_program(orig_master)());
+
mixed err = catch {
+
compile_string(#"
+
#if defined (NONEXISTING_DEFINE) && constant (.testsuite_test)
+
#error Not expected
+
#endif", "testsuite_test");
+
};
+
replace_master(orig_master);
+
if (err) throw (err);
+
]]);
+
+
test_any([[
+
class handler {mapping get_predefines() {return (["x": "1", "y": "", "z": 0]);}};
+
return cpp ("x y z p", "-", 0, handler());
+
]], "#line 1 \"-\"\n1 p");
+
test_eval_error([[
+
class handler {mixed get_predefines() {return (<"x">);}};
+
cpp ("x y z", "-", 0, handler());
+
]]);
+
test_eval_error([[
+
class handler {mapping get_predefines() {return ([0: 0]);}};
+
cpp ("x y z", "-", 0, handler());
+
]]);
+
test_eval_error([[
+
class handler {mapping get_predefines() {return (["": 1]);}};
+
cpp ("x y z", "-", 0, handler());
+
]]);
+
test_eval_error([[
+
class handler {mapping get_predefines() {return (["x": 1]);}};
+
cpp ("x y z", "-", 0, handler());
+
]]);
+
+
test_true( Stdio.write_file("conftest.h", "return 17;\n") )
+
+
test_any([[
#include "conftest.h" ]],17) dnltest_any([[ dnl#include <conftest.h> dnl]],17)
-
+
+
test_any([[
+
// bug 2440 (a)
+
#define FILENAME "conftest.h"
+
return #string FILENAME;
+
]], "return 17;\n")
+
+
test_any([[
+
// bug 2440 (b)
+
#define FILENAME "conftest.h"
+
#include FILENAME
+
]], 17)
+
+
test_any([[
+
// Double expansion
+
string FILENAME = "";
+
#define FILENAME "conftest.h" + FILENAME
+
return #string FILENAME;
+
]], "return 17;\n")
+
+
test_true( rm("conftest.h") )
+
test_true(intp(__LINE__)) test_true(stringp(__FILE__))
-
+
test_eq(dirname(__FILE__),__DIR__)
test_true(stringp(__DATE__)) test_true([[ sscanf(__DATE__, "%3s %d %d", string m, int d, int y) == 3 && search(({"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}), m) != -1 && intp(d) && d>0 && d<32 && intp(y) ]]) test_true(stringp(__TIME__)) test_true([[ sscanf(__TIME__, "%d:%d:%d", int h, int m, int s) == 3 && intp(h) && intp(m) && intp(s) && h>=0 && m>=0 && s>=0 && h<24 && m<60 && s<61 ]]) test_true(floatp(__VERSION__))
-
+
test_true(floatp(__REAL_VERSION__))
test_true(intp(__MAJOR__))
-
+
test_true(intp(__REAL_MAJOR__))
test_true(intp(__MINOR__))
-
+
test_true(intp(__REAL_MINOR__))
test_true(intp(__BUILD__))
-
+
test_true(intp(__REAL_BUILD__))
+
test_eq(__PIKE__,1)
-
+
test_eq( compile_string("string a=#\"a\nb\";")()->a, "a\nb" )
+
test_eq( compile_string("string a=#\"a\r\nb\";")()->a, "a\nb" )
+
test_eq( compile_string("string a=#\"a\n\rb\";")()->a, "a\nb" )
+
// #define test_any([[ #define FOOa 1 return FOOa; ]],1) test_any([[ #define FOOa array
-
FOOa(int) b;
-
return
1
;
+
FOOa(int) b
= ({0})
;
+
return
sizeof(b)
;
]],1) test_any([[ #define FOOb 17 #undef FOOb #define FOOb 1 return FOOb; ]],1) test_compile_error([[ #define FOOc FOOc FOO FOO ]])
-
test_compile_error([[
-
#error FOOd
-
FOO
-
]])
-
+
test_any([[ #define FOOa(X) (X) return FOOa(2); ]],2) test_any([[ #define FOOa(X) \ (X) return FOOa(2); ]],2)
pike.git/src/testsuite.in:4499:
return FOOa(3); ]],"bargazonk") // /* */ test_any([[ /* return 99; * / /* */ return 1; ]],1)
+
test_any([[
+
/* return 99; // */
+
return 1;
+
]],1)
+
// // test_any([[ // return 99;
-
return 1;
+
return 1;
// return 47;
]],1)
-
+
// #!
+
test_any([[
+
#! int i=4;
+
int i=3;
+
#! i=5;
+
return i;
+
]],3)
+
// #if define(test_if_true,[[test_any([[ #if $1 return 1; #else return 0; #endif ]],1)]]) define(test_if_false,[[test_any([[ #if $1 return 1; #else return 0; #endif ]],0)]]) test_if_true(1) test_if_false(0)
-
+
test_if_true('n' == 110)
+
// #if == test_if_true(1==1) test_if_false(1==2) // #if != test_if_true(1!=2) test_if_false(1!=1) // #if ( ) test_if_true( (((1))==1) )
pike.git/src/testsuite.in:4679:
// #if x < define test_any([[ #define FOOi 1 #if 2 < FOOi return 0; #else return 1; #endif ]],1)
+
test_any([[
+
#if 0
+
#blahong
+
#endif
+
return 1;
+
]],1)
+
// #if efun // see test for add_constant() // #if /* */ test_any([[ #if 1 /* trying to be mean // * / */ /* /* */ return 1; /* */ #define foo # 1 "---" #undef foo
pike.git/src/testsuite.in:4739:
]],1) test_any([[ #if defined(FOOk) return 0; #else return 1; #endif ]],1)
+
// #if constant
+
test_any([[
+
#if constant(Foo.Bar)
+
return 0;
+
#else
+
return 1;
+
#endif
+
]],1)
+
+
test_any([[
+
#if constant(Foo) && constant(Bar)
+
return 0;
+
#else
+
return 1;
+
#endif
+
]],1)
+
+
test_any([[
+
#if constant(String.Buffer)
+
return 1;
+
#else
+
return 0;
+
#endif
+
]],1)
+
+
test_any([[
+
#if constant(String.Bar)
+
return 0;
+
#else
+
return 1;
+
#endif
+
]],1)
+
+
test_any([[
+
#if constant(String) && constant(String.Bar)
+
return 0;
+
#else
+
return 1;
+
#endif
+
]],1)
+
+
test_compile_error([[
+
#if constant()
+
constant foo=1;
+
#endif
+
]])
+
// #ifdef test_any([[ #ifdef FOOl return 0; #else return 1; #endif ]],1) test_any([[
pike.git/src/testsuite.in:4889:
return 1; #elseif 1 return 0; #else return 0; #endif ]],1) // #pragma // FIXME: add tests for real pragmas
-
test_
any
([[
+
test_
compile_warning
([[
#pragma whatever return 1;
-
]]
,1
)
+
]])
-
+
test_compile_warning([[
+
class A {
+
nomask int x;
+
}
+
]])
+
+
test_do([[
+
#pragma no_deprecation_warnings
+
class A {
+
nomask int x;
+
}
+
]])
+
+
test_compile_warning([[
+
#pragma no_deprecation_warnings
+
#pragma deprecation_warnings
+
class A {
+
nomask int x;
+
}
+
]])
+
+
// #include
-
// FIXME add test for #include
+
test_compile_any([[ #pike 7.0 #include <simulate.h> ]]) // #error test_compile_error([[ #error Gurgel ]])
-
+
// #warning
+
test_compile_warning([[
+
#warning Gurgel
+
]])
+
+
// <<<<<<<
+
test_eval_error( cpp("<<<<<<<") )
+
test_compile_error([[
+
#if 0
+
<<<<<<<
+
#endif
+
]])
+
+
+
+
define(do_test_cpp_string,[[
+
test_eq([[ (({""}) + (string)indices("."*256)/"" + ({""})) * $1]],
+
[[ Stdio.write_file("testsuite.tmp",a()),compile_string("string s=#string \"testsuite.tmp\";")()->s ]])
+
]])
+
+
do_test_cpp_string([["0"]])
+
do_test_cpp_string([["1"]])
+
do_test_cpp_string([["2"]])
+
do_test_cpp_string([["3"]])
+
do_test_cpp_string([["4"]])
+
do_test_cpp_string([["5"]])
+
do_test_cpp_string([["6"]])
+
do_test_cpp_string([["7"]])
+
do_test_cpp_string([["8"]])
+
do_test_cpp_string([["9"]])
+
do_test_cpp_string([["a"]])
+
do_test_cpp_string([["A"]])
+
do_test_cpp_string([["\\"]])
+
do_test_cpp_string([["\\\\"]])
+
do_test_cpp_string([["\\\\\\"]])
+
do_test_cpp_string([["\""]])
+
+
// #undef inside an evaluation of the macro.
+
test_compile_error([[
+
#define LOCALE(X,Y) (Y)
+
#define DEFVAR(X, Y) ret[(X)]=my_defvar((X),(Y),vars)
+
+
DEFVAR("cm_wa",
+
Sitebuilder.SBConnect()->
+
ChooseWorkareaVariable(LOCALE(0, "Work area") + LOCALE(0, "Work area"),
+
LOCALE(0, "the"));
+
+
DEFVAR("cr_startpage",
+
Variable.URLList(LOCALE(0, "Crawling behaviour") + LOCALE(0, "Start pages"), ""));
+
+
#undef DEFVAR
+
+
constant cif_defines = #"
+
<input align='&_.img-align;' type='image' name='&_.name;' value='&_.contents;' src='&var.url;' border='0' />
+
</define>";
+
]])
+
// foop define(do_test_foop,[[ test_eq($1 (17), !($2)) test_eq($1 (1.7), !($2-1)) test_eq($1 ("17"), !($2-2)) test_eq($1 (this_object()), !($2-3)) test_eq($1 (a), !($2-4)) // a is the test function test_eq($1 (({})), !($2-5)) test_eq($1 (([])), !($2-6)) test_eq($1 ((<>)), !($2-7)) test_eq($1 (object_program(this_object())), !($2-8))
-
+
test_eq($1 (typeof(1)), 0)
]]) do_test_foop(intp,0) do_test_foop(floatp,1) do_test_foop(stringp,2) do_test_foop(objectp,3) do_test_foop(functionp,4) do_test_foop(arrayp,5) do_test_foop(mappingp,6) do_test_foop(multisetp,7)
pike.git/src/testsuite.in:4948:
test_eq(foobar(),1) test_do(add_constant("foobar")) test_any([[ #if efun(foobar) return 1; #else return 0; #endif ]],0)
+
+
// #### Test everything in all_constants.
+
+
// - __automap__
+
// - __empty_program
+
// - __null_program
+
// - __parse_pike_type
+
// - __placeholder_object
+
// - _describe_program
+
// - _disable_threads
+
// - _do_call_outs
+
// - _exit
+
// - _leak
+
// - _memory_usage
+
// - _next
+
// - _prev
+
// - _refs
+
// - _static_modules
+
// - _typeof
+
+
// - _verify_internals
+
cond([[all_constants()->_verify_internals]],
+
[[
+
test_do(_verify_internals())
+
]])
+
+
// - `!
+
// - `!=
+
// - `%
+
// - `&
+
// - `()
+
// - `*
+
+
// - `+
+
test_eq(`+(1,1),2)
+
test_eq(`+(1,-2),-1)
+
test_eq(`+(-2,-2),-4)
+
test_eq(`+("hi","there"),"hithere")
+
+
test_eq(`+("hi\777","there"),"hi\777there")
+
test_eq(`+("hi","there\777"),"hithere\777")
+
+
test_eq(`+("hi\7777777","there"),"hi\7777777there")
+
test_eq(`+("hi","there\7777777"),"hithere\7777777")
+
+
test_eq(`+("human","number",666),"humannumber666")
+
test_eq(`+("human","number",666),"humannumber666")
+
test_eq(`+("human","number",666),"humannumber666")
+
test_eq(`+("human","number",666,111),"humannumber666111")
+
test_eq(`+("humannumber",`+(666+111)),"humannumber777")
+
test_eq(`+("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y"),"abcdefghijklmnopqrstuvxy")
+
test_eq(`+(1.0+1.0),2.0)
+
test_eq(`+(1.0,-1.0),0.0)
+
test_eq(`+(-1.0,-1.0),-2.0)
+
test_equal(`+(({1,2,3}),({4,5,6})),({1,2,3,4,5,6}))
+
test_equal(`+((<1,2,3,4>),(<4,5,6>)),(<1,2,3,4,4,5,6>))
+
test_equal(`+(([0:1,3:6]),([5:2,3:6])),([0:1,3:6,3:6,5:2]))
+
+
test_equal(17+class{mixed ``+(mixed n){return (<n>);}}(),(<17>))
+
test_equal(1700000000000000000000+class{mixed ``+(mixed n){return (<n>);}}(),(<1700000000000000000000>))
+
+
test_eval_error(Gmp.mpz(1700000000000000000000)+class{mixed ``+(mixed n){return (<n>);}}())
+
+
// - `-
+
// - `->
+
// - `->=
+
// - `/
+
// - `<
+
// - `<<
+
// - `<=
+
// - `==
+
// - `>
+
// - `>=
+
// - `>>
+
// - `[]
+
// - `[]=
+
// - `^
+
// - `|
+
// - `~
+
+
// - abs
+
// - acos
+
// Tested in _math
+
+
// - add_constant
+
test_compile_error(int a=grunk(5);)
+
test_do(add_constant("grunk",abs))
+
test_do(int a=grunk(5);)
+
test_do(add_constant("grunk"))
+
test_compile_error(int a=grunk(5);)
+
+
// - add_include_path
+
// - add_module_path
+
// - add_program_path
+
// Tested in lib
+
// - aggregate
-
test_
true
(
arrayp(
aggregate()
))
-
test_eq
(
sizeof(aggregate(
))
,0)
+
test_
equal
(aggregate()
,
(
{}
))
test_equal(aggregate(1,2,3,4),({1,2,3,4}))
-
+
test_equal(aggregate(1,2)+aggregate(3,4),({1,2,3,4}))
+
test_equal(aggregate(@({1,2,3,4})),({1,2,3,4}))
+
test_equal(aggregate(@({7})*50),({7})*50)
// - aggregate_multiset
-
test_
true
(
multisetp
(aggregate_multiset()))
+
test_
equal
(
aggregate_multiset
(
), (<>))
+
test_equal(
aggregate_multiset(
1,1
)
, (<1,1>
))
+
test_equal(aggregate_multiset(1,2,"3"), (<1,2,"3">))
// - aggregate_mapping
-
test_
true
(
multisetp
(aggregate_
multiset
()))
+
test_
equal
(
aggregate_mapping
(
), ([]))
+
test_equal(
aggregate_
mapping
(
1,2,3,4
)
, ([1:2,3:4]
))
+
test_eval_error(aggregate_mapping(1,2,3))
-
+
// - alarm
+
// - all_constants test_true(mappingp(all_constants()))
-
test_true(all_constants()["all_constants"])
+
test_eq(all_constants()["all_constants"],all_constants)
-
+
// - all_threads
+
cond([[all_constants()->thread_create]],
+
[[
+
test_true(arrayp(all_threads()))
+
test_true(sizeof(all_threads()))
+
test_true(objectp(all_threads()[0]))
+
]])
+
// - allocate
-
test_
true
(
arrayp(
allocate(0)))
+
test_
equal
(allocate(0)
,({}
))
test_equal(allocate(2),({0,0})) test_false(allocate(2)==({0,0}))
-
+
test_equal(allocate(2,2),({2,2}))
test_true(allocate(65536,random))
-
+
// - array_sscanf
+
+
// - arrayp
+
// Tested in foop
+
+
// - asin
+
// - atan
+
// - atan2
+
// Tested in _math
+
+
// - atexit
+
// - backtrace test_true(arrayp(backtrace())) test_eq(backtrace()[-1][2],a)
-
+
// - basename
+
// Tested in lib
+
+
// - basetype
+
test_eq(basetype(0),"int")
+
test_eq(basetype(0.0),"float")
+
test_eq(basetype(""),"string")
+
test_eq(basetype(({})),"array")
+
test_eq(basetype(({1})),"array")
+
test_eq(basetype((<>)),"multiset")
+
test_eq(basetype(([])),"mapping")
+
test_eq(basetype(class {}),"program")
+
test_eq(basetype(class {}()),"object")
+
test_eq(basetype(abs),"function")
+
test_eq(basetype(lambda(){}),"function")
+
test_eq(basetype(typeof(0)),"type")
+
// - call_function test_eq(1,call_function(a)) test_eq(1,call_function(lambda(int a){ return a; },1)) test_eq(1,call_function(intp,1))
-
// -
String.capitalize
-
test
_
eq(String.capitalize("fubar"),"Fubar")
-
test
_
eq(String.capitalize("FooBar"),"FooBar")
-
test
_
eq(String.capitalize("-"),"-")
+
// -
call
_
out
+
// - call
_
out
_
info
-
// - String.
common
_
prefix
-
test_
eq
(String.
common
_
prefix
(({
"soliloquise"
}))
,
"soliloquise"
)
-
test_
eq
(String.
common
_
prefix
(({
"muzzle"
,
"muzzy"
})),
"muzz"
)
-
test_
eq
(
String.common
_
prefix
(({
"labyrinth"
,
"diatom"
}))
,
""
)
-
test_
eq
(
String.common_prefix
(({ "
abc
",
"abc",
"
abc
" }))
,
"
abc
")
-
test_
eq
(
String
.
common
_
prefix
((
{}
))
,
""
)
+
// -
callablep
+
test_true( callablep(time) )
+
test_true( callablep(
String.
capitalize) )
+
test
_
true( callablep(CommonLog.read) )
+
test_
true
(
callablep(ADT.Stack) )
+
test_true( callablep(
String.
Buffer) )
+
test
_
true
(
callablep
(
class
{
void
`()() {
}
}(
)
) )
+
test_
false
(
callablep(
String.
Buffer()) )
+
test
_
true
(
callablep
(
({}) ) )
+
test_true( callablep( (
{
0
,
0
})
)
)
+
test_false( callablep( ({ 0
,
1
}
)
) )
+
test_
true
(
callablep( ({ time }) ) )
+
test
_
true
(
callablep
(
(
{
time
,
0
})
) )
+
test_
false
(
callablep
(
({ "
a
",
time
}) ) )
+
test_false( callablep( ({
"" })
)
)
+
test_false( callablep(
""
)
)
+
test_
false
(
callablep( 3
.
14 ) )
+
test
_
false
(
callablep
(
(< time >
)
) )
+
test_false( callablep( 0 ) )
+
test_false( callablep( 7 ) )
-
// - clone
-
// clone is already tested a lot by this script
-
test_true(objectp(clone(compile_string("int foo() { return 17; }"))))
-
test_eq(clone(compile_string("int foo() { return 17; }"))->foo(),17)
+
-
+
// - cd
+
+
// - ceil
+
// Tested in _math
+
+
// - chmod
+
// - chown
+
// - chroot
+
// - cleargroups
+
+
// - new/clone
+
test_true([[
+
#pike 7.2
+
objectp(new(compile_string("int foo() { return 17; }"))) ]])
+
test_eq([[
+
#pike 7.2
+
new(compile_string("int foo() { return 17; }"))->foo() ]],17)
+
test_true([[
+
#pike 7.2
+
objectp(clone(compile_string("int foo() { return 17; }"))) ]])
+
test_eq([[
+
#pike 7.2
+
clone(compile_string("int foo() { return 17; }"))->foo() ]],17)
+
+
// - closelog
+
+
// - column
+
test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),0)]],[[({1,5,8})]])
+
test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),1)]],[[({2,6,9})]])
+
test_equal([[column(({({1,2,3}),({5,6,7}),({8,9,0})}),2)]],[[({3,7,0})]])
+
test_any_equal([[
+
array a = ({({(["foo": 17])})});
+
mixed res = column (a, "foo"); // Avoid constant optimization.
+
return res && a[0][0];
+
]], (["foo": 17]))
+
// - combine_path test_eq([[combine_path("/foo/bar/gazonk/","..")]],"/foo/bar")
-
+
test_eq([[combine_path("/foo/bar/gazonk","..")]],"/foo/bar")
+
test_eq([[combine_path("/foo/bar/", "gazonk")]],"/foo/bar/gazonk")
+
test_eq([[combine_path("/foo/bar", "gazonk")]],"/foo/bar/gazonk")
test_eq([[combine_path("/.../","sune")]],"/.../sune") test_eq([[combine_path("/",".")]],"/") test_eq([[combine_path("/","foo/.../sune")]],"/foo/.../sune") test_eq([[combine_path("/./foo/bar//gazonk/","../")]],"/foo/bar/") test_eq([[combine_path("/","/foo/./bar/gazonk/..")]],"/foo/bar") test_eq([[combine_path("/","/foo/bar/gazonk/../../")]],"/foo/") test_eq([[combine_path("/","/foo//bar/gazonk/../..")]],"/foo") test_eq([[combine_path("/","/foo/bar/./gazonk/../../..")]],"/") test_eq([[combine_path("/","/foo/../bar//./gazonk/../..")]],"/") test_eq([[combine_path("/","/foo/././/bar/gazonk/../../../..")]],"/") test_eq([[combine_path("/","..")]],"/") test_eq([[combine_path("./","..")]],"..") test_eq([[combine_path("./.","..")]],"..") test_eq([[combine_path("/","../../foo")]],"/foo") test_eq([[combine_path("./foobar/.","..")]],".") test_eq([[combine_path("/","foo","bar","gazonk")]],"/foo/bar/gazonk")
-
+
test_eq([[combine_path("/", "foo", "")]], "/foo/")
-
// - Stdio.append_path
-
test_eq([[
Stdio.append
_path("
..
/
foo/
",
"../
bar
")
]],
"
..
/foo/
bar
")
-
test_eq([[
Stdio.append
_path("
..
/
foo/
",
"../
bar", "
../
baz
")
]],
"
..
/
foo
/
bar/baz
")
-
test_eq([[
Stdio.append
_path("
..
/
foo/
",
"
..
/bar
", "..
/
baz", "
../
fie/
../
faz
")
]],
"
..
/
foo
/
bar/baz/faz
")
+
test_eq([[
combine
_path("/","
/foo/bar/ga\11111zonk/
../
../
")]],"/foo/")
+
test_eq([[
combine
_path("/","
/fo\1111/bar/ga\11111zonk/
../../")]],"/
fo\1111
/")
+
test_eq([[
combine
_path("/","/
fo\1111/
bar/
gazonk/
../../")]],"/
fo\1111
/")
-
+
test_eq([[combine_path("foo", "../bar")]],"bar")
+
test_eq([[combine_path("foo/", "../bar")]],"bar")
+
test_eq([[combine_path("foo/", "../bar/")]],"bar/")
+
test_eq([[combine_path("foo/.", "../bar")]],"bar")
+
test_eq([[combine_path("foo", "..")]],".")
+
test_eq([[combine_path("foo/", "..")]],".")
+
test_eq([[combine_path("foo/.", "..")]],".")
+
test_eq([[combine_path(".", "bar")]],"bar")
+
test_eq([[combine_path("./", "bar")]],"bar")
+
test_eq([[combine_path(".", "../bar")]],"../bar")
+
test_eq([[combine_path("./", "../bar")]],"../bar")
+
+
// - combine_path_nt
+
test_eq([[combine_path_nt("/","/fo\1111/bar/gazonk/../../")]],"/fo\1111/")
+
test_eq([[combine_path_nt("a:/","/fo\1111/bar/gazonk/../../")]],"a:/fo\1111/")
+
test_eq([[combine_path_nt("a:/", "/foo","bar")+combine_path_nt("/foo","bar")]],
+
"a:/foo/bar/foo/bar")
+
+
// - combine_path_unix
+
test_eq([[combine_path_unix("/","/fo\1111/bar/gazonk/../../")]],"/fo\1111/")
+
+
// - compile
// - compile_file
-
// FIXME: add tests for compile_file
+
// - compile_string // see test for clone()
-
cond([[all_constants()->thread_create]]
,
-
[[
+
cond
_begin
([[all_constants()->thread_create]]
)
+
test_any([[ string file = #" /*
-
* Attempt to
trigg
the lex.current_file == NULL bug.
+
* Attempt to
trig
the lex.current_file == NULL bug.
* * Henrik Grubbström 1999-07-01 */ string file = Stdio.File(__FILE__, \"r\")->read(); void thread_func() { int i;
pike.git/src/testsuite.in:5061:
a->wait(); return 0; } "; allocate(10, thread_create)(lambda() { int i; for(i = 0; i < 1000; i++) { compile_string(file);
+
// These watchdog calls shouldn't be necessary - the timeframe
+
// is at least 20 minutes between two calls, so doing these can
+
// extend the test time to up to 20000 minutes before the
+
// watchdog kicks in.. /mast
+
//if (!(i%10))
+
// __signal_watchdog();
+
if (!(i % 100))
+
log_status ("%s: %O at %d", ctime (time())[..<1], this_thread(), i);
} } )->wait(); return 0; ]], 0)
-
]])
+
-
+
cond_end // thread_create
+
// - copy_value test_eq(copy_value(1),1) test_eq(copy_value(""),"") test_eq(copy_value(1.0),1.0) test_eq(copy_value(this_object()),this_object()) test_eq(copy_value(a),a)
-
+
test_eq(copy_value(typeof(true)),typeof(true))
define(do_test_copy_value,[[ test_any([[mixed x=$1; return x==x]],1) test_any([[mixed x=$1; return copy_value(x)!=x]],1) test_any([[mixed x=$1; return equal(copy_value(x),x)]],1)]]) do_test_copy_value( ({1}) ) do_test_copy_value( ([]) ) do_test_copy_value( (<>) ) do_test_copy_value( (< ([]), ({1}) ,"" , 1.0 >) ) test_true(get_weak_flag(copy_value(set_weak_flag(({17}), 1)))) test_true(get_weak_flag(copy_value(set_weak_flag((<17>), 1)))) test_true(get_weak_flag(copy_value(set_weak_flag(([17:17]), 1)))) test_true(get_weak_flag(copy_value(set_weak_flag(([17:({17})]), 1))))
-
+
test_any([[
+
array x = ({0});
+
x[0] = x;
+
return equal (copy_value (x), x);
+
]], 1)
+
test_any([[
+
mapping x = ([]);
+
x[x] = x;
+
return equal (copy_value (x), x);
+
]], 1)
+
test_any([[
+
multiset x = (<>);
+
x[x] = 1;
+
return equal (copy_value (x), x);
+
]], 1)
+
test_any([[
+
array a=({0,0,0});
+
array b=copy_value(a); b[0]=17; b[1]=42; b[2]=128;
+
return equal( ({0,0,0}), a) && equal( ({17,42,128}), b);
+
]], 1)
+
test_any([[
+
// Bug 3693
+
array(mapping) a = ({([])})*2;
+
return a[0] == a[1];
+
]], 1)
+
test_any([[
+
mapping m = ([]);
+
multiset l = (<>);
+
m->foo = ({l});
+
m->bar = ({l});
+
mapping copy = copy_value (m);
+
return copy->foo != copy->bar && copy->foo[0] == copy->bar[0];
+
]], 1)
-
+
test_any([[
+
class X {int __hash() {return 17;}};
+
mixed c = copy_value (X());
+
return objectp (c) && object_program (c) == X;
+
]], 1)
+
+
// - cos
+
// Tested in _math
+
+
// - cpp
+
// - crypt test_true(stringp(crypt("hej"))) test_true(crypt("hej",crypt("hej")))
-
+
test_true(crypt("hej","Oz5i0K.16qkgA"))
+
test_true(crypt("hej","buf8/Z7taE6qs"))
+
test_true(crypt("123456789", crypt("123456780")))
test_false(crypt("hej","hej")) test_false(crypt("h","hej"))
-
+
test_false(crypt("hej","buf8/Z7taE6qst"))
+
test_false(crypt("hej","buf8/Z7taE6q"))
// - ctime
-
test_
true
(
stringp(
ctime(0)))
+
test_
eq
(ctime(0)
[-1],'\n'
)
+
test_do([[int t = -1; catch(ctime(t
)
);]])
-
+
// - decode_value
+
// - delay
+
// - describe_backtrace
+
// - describe_error
+
// - destruct
-
// FIXME put tests for destruct here.
+
test_do(add_constant("PROG",compile_string("int foo() { return 1; }")));
-
test_any([[object o=
clone(
PROG); destruct(o); return o]],0);
-
test_any([[object o=
clone(
PROG); destruct(o); return objectp(o)]],0);
-
test_any([[array(object) o=(
{clone
(
PROG
)}); destruct(o[0]); return o-({0}) ]],({}));
-
test_any([[mapping o=(["foo":
clone(
PROG)]); destruct(o["foo"]); return o["foo"]; ]],0);
-
dnl test_any([[object t; mapping o=([t=
clone(
PROG):"foo"]); destruct(t); return sizeof(o)]],0);
-
test_do([[object t; array(object) o=({}); o+=({t=
clone(
PROG)}); destruct(t); o=({});]]);
+
test_any([[object o=
PROG
(); destruct(o); return o]],0);
+
test_any([[object o=
PROG
(); destruct(o); return objectp(o)]],0);
+
test_any([[array(object) o=(
{PROG
()}); destruct(o[0]); return o-({0}) ]],({}));
+
test_any([[mapping o=(["foo":
PROG
()]); destruct(o["foo"]); return o["foo"]; ]],0);
+
dnl test_any([[object t; mapping o=([t=
PROG
():"foo"]); destruct(t); return sizeof(o)]],0);
+
test_do([[object t; array(object) o=({}); o+=({t=
PROG
()}); destruct(t); o=({});]]);
+
test_do(add_constant("PROG"))
-
// -
Array.diff
-
test_equal(Array.diff(({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }),
-
({ 6, 7, 8, 9, 3, 4, 5, 1, 2, 0 })),
-
({ ({ ({ 0, 1, 2, 3, 4, 5 }),
-
({ 6, 7, 8, 9 }), ({}) }),
-
({ ({}), ({ 6, 7, 8, 9 }),
-
({ 3, 4, 5, 1, 2, 0 }) }) }))
-
test_equal(Array.diff(({ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }),
-
({ 9, 7, 8, 4, 5, 6, 0, 1, 2, 3 })),
-
({ ({ ({}), ({ 0, 1, 2, 3 }),
-
({ 4, 5, 6, 7, 8, 9 }) }),
-
({ ({ 9, 7, 8, 4, 5, 6 }),
-
({ 0, 1, 2, 3 }), ({}) }) }))
-
test_equal(Array.diff("qadfgoksdfäojerjgöohjgdgkm"
/
"",
-
"xadfgokälojeorjgöoyjgdgkmzzz"
/
""),
-
({ ({ ({ "q" }), "adfgok"/"", "sdf"/"", ({ "ä" }), ({}),
-
"oje"/"", ({}), "rjgöo"/"", ({ "h" }), "jgdgkm"/"", ({}) }),
-
({ ({ "x" }), "adfgok"/"", ({}), ({ "ä" }), ({ "l" }),
-
"oje"/"", ({ "o" }), "rjgöo"/"", ({ "y" }), "jgdgkm"/"",
-
"zzz"/"" }) }))
-
test_equal(Array.diff("123.org"/"","http://123.org/"/""),
-
({ ({ ({}), "123.org"/"", ({}) }),
-
({ "http://"/"", "123.org"/"", ({ "/" }) }) }))
+
// -
dirname
+
//
Tested
in
lib
-
// -
Array.diff3 (note that the results would be different for a really optimal diff3)
-
test
_
equal(Array.diff3(({}),({"a","c"}),({"b","y"})),
-
({({({ })}),
-
({({"a","c"})}),
-
({({"b","y"})})}))
-
test_equal(Array.diff3(({"a"}),({"a","b"}),({"b"})),
-
({({({"a"}),({ })}),
-
({({"a"}),({"b"})}),
-
({({ }),({"b"})})}))
-
test_equal(Array.diff3(({"a"}),({"a","c"}),({"b"})),
-
({({({"a"}),({ })}),
-
({({"a"}),({"c"})}),
-
({({ }),({"b"})})}))
-
test_equal(Array.diff3(({"a","d"}),({"a","d"}),({"a","b"})),
-
({({({"a"}),({"d"})}),
-
({({"a"}),({"d"})}),
-
({({"a"}),({"b"})})}))
-
test_equal(Array.diff3(({"a","b"}),({"b"}),({"c","b"})),
-
({({({"a"}),({"b"})}),
-
({({ }),({"b"})}),
-
({({"c"}),({"b"})})}))
-
//
The
following is not optimal.
-
test
_
equal(Array.diff3(({"a","b"}),({"b"}),({"b","b"})),
-
({({({"a"}),({"b"}),({ })}),
-
({({ }),({"b"}),({ })}),
-
({({ }),({"b"}),({"b"})})}))
-
test
_
equal(Array.diff3(({"a","c","d"}),({"a","d","d"}),({"a","b"})),
-
({({({"a"}),({"c"}),({"d"}),({ })}),
-
({({"a"}),({ }),({"d"}),({"d"})}),
-
({({"a"}),({"b"}),({ }),({ })})}))
-
test_equal(Array.diff3(({"a","b","c"}),({"b","e","c"}),({"b","e","c"})),
-
({({({"a"}),({"b"}),({ }),({"c"})}),
-
({({ }),({"b"}),({"e"}),({"c"})}),
-
({({ }),({"b"}),({"e"}),({"c"})})}))
-
test_equal(Array.diff3(({"a","b","x"}),({"y","b","c","x"}),({"y","c","a"})),
-
({({({"a"}),({"b"}),({ }),({"x"})}),
-
({({"y"}),({"b"}),({"c"}),({"x"})}),
-
({({"y"}),({ }),({"c"}),({"a"})})}))
-
test_equal(Array.diff3(({"y","b","c","x"}),({"y","c","a"}),({"a","b","x"})),
-
({({({"y"}),({"b"}),({"c"}),({"x"})}),
-
({({"y"}),({ }),({"c"}),({"a"})}),
-
({({"a"}),({"b"}),({ }),({"x"})})}))
-
test_equal(Array.diff3(({"y","b","c","x"}),({"a","b","x"}),({"y","c","a"})),
-
({({({"y"}),({"b"}),({"c"}),({"x"})}),
-
({({"a"}),({"b"}),({ }),({"x"})}),
-
({({"y"}),({ }),({"c"}),({"a"})})}))
-
test_equal(Array.diff3(({"a","a","b","b"}),({"b","b","c","c"}),({"c","c","a","a"})),
-
({({({"a","a"}),({"b","b"}),({ }),({ })}),
-
({({ }),({"b","b"}),({"c","c"}),({ })}),
-
({({ }),({ }),({"c","c"}),({"a","a"})})}))
-
//
The
following is not optimal.
-
test_equal(Array.diff3(({"a","x","b","c"}),({"b","x","c"}),({"b","x","c"})),
-
({({({"a","x"}),({"b"}),({ }),({"c"})}),
-
({({ }),({"b"}),({"x"}),({"c"})}),
-
({({ }),({"b"}),({"x"}),({"c"})})}))
-
test_equal(Array.diff3(({"x","x","a","x"}),({"a","x","b","x"}),({"a","x","b","x"})),
-
({({({"x","x"}),({"a","x"}),({ })}),
-
({({ }),({"a","x"}),({"b","x"})}),
-
({({ }),({"a","x"}),({"b","x"})})}))
-
test_equal(Array.diff3(({"a","a","b"}),({"b","c"}),({"c","a","a"})),
-
({({({ }),({ }),({"a","a"}),({"b"})}),
-
({({"b"}),({"c"}),({ }),({ })}),
-
({({ }),({"c"}),({"a","a"}),({ })})}))
-
test_equal(Array.diff3(({"x","x","x","a"}),({"y","b"}),({"x","x","x","c"})),
-
({({({"x","x","x"}),({"a" })}),
-
({({ }),({"y","b"})}),
-
({({"x","x","x"}),({"c" })})}))
-
test_equal(Array.diff3(({"a","x","x","x","a"}),({"b","y","y","b"}),({"c","x","x","x","c"})),
-
({({({"a" }),({"x","x","x"}),({"a"})}),
-
({({"b","y","y","b"}),({ }),({ })}),
-
({({"c" }),({"x","x","x"}),({"c"})})}))
-
test_equal(Array.diff3(({"a","b","c","d"}),({"x","x","x","d"}),({"a","y","y","y"})),
-
({({({"a"}),({"b","c" }),({"d"})}),
-
({({ }),({"x","x","x"}),({"d"})}),
-
({({"a"}),({"y","y","y"}),({ })})}))
-
test_equal(Array.diff3(({"a","b","c","d"}),({"a","x","x","d"}),({"a","y","y","y"})),
-
({({({"a"}),({"b","c" }),({"d"})}),
-
({({"a"}),({"x","x" }),({"d"})}),
-
({({"a"}),({"y","y","y"}),({ })})}))
-
test_equal(Array.diff3(({"a","b","c","d"}),({"x","x","x","b"}),({"a","y","y","y"})),
-
({({({"a" }),({"b"}),({"c","d" })}),
-
({({"x","x","x"}),({"b"}),({ })}),
-
({({"a" }),({ }),({"y","y","y"})})}))
-
test_equal(Array.diff3(({"a","b","c","d"}),({"x","x","x","c"}),({"a","y","y","y"})),
-
({({({"a"}),({"b" }),({"c"}),({"d"})}),
-
({({ }),({"x","x","x"}),({"c"}),({ })}),
-
({({"a"}),({"y","y","y"}),({ }),({ })})}))
-
test_equal(Array.diff3(({"a","b","b","c","d"}),({"z","a","b","b","x"}),({"z","b","c","x"})),
-
({({({ }),({"a"}),({"b"}),({"b"}),({"c"}),({"d"})}),
-
({({"z"}),({"a"}),({"b"}),({"b"}),({ }),({"x"})}),
-
({({"z"}),({ }),({"b"}),({ }),({"c"}),({"x"})})}))
-
test_equal(Array.diff3(({"a","b","c","d"}),({"b","a","c","c"}),({"b","b","d","d","a"})),
-
({({({"a"}),({"b"}),({"c"}),({"d"}),({ }),({ }),({ })}),
-
({({ }),({"b"}),({ }),({ }),({ }),({"a"}),({"c","c"})}),
-
({({ }),({"b"}),({"b"}),({"d"}),({"d"}),({"a"}),({ })})}))
-
//
The
following is not optimal.
-
test_equal(Array.diff3(({"a"}),({"b","a"}),({"a","b","a"})),
-
({({({ }),({"a"}),({ })}),
-
({({"b"}),({"a"}),({ })}),
-
({({ }),({"a"}),({"b","a"})})}))
-
// The following is not optimal.
-
test_equal(Array.diff3(({"a","c"}),({"b","a","c"}),({"a","c","b","a","c"})),
-
({({({ }),({"a","c"}),({ })}),
-
({({"b"}),({"a","c"}),({ })}),
-
({({ }),({"a","c"}),({"b","a","c"})})}))
-
// The following is not optimal.
-
test_equal(Array.diff3(({"a","d"}),({"b","a","c"}),({"a","c","b","a","c"})),
-
({({({ }),({"a"}),({"d" }),({ })}),
-
({({"b"}),({"a"}),({ }),({"c"})}),
-
({({ }),({"a"}),({"c","b","a"}),({"c"})})}))
-
// The following is not optimal.
-
test_equal(Array.diff3(({"a","a"}),({"b","a","d","a"}),({"a","a","b","a","a"})),
-
({({({ }),({"a"}),({ }),({"a"}),({ })}),
-
({({"b"}),({"a"}),({"d"}),({"a"}),({ })}),
-
({({ }),({"a"}),({ }),({"a"}),({"b","a","a"})})}))
-
test_equal(Array.diff3(({"a"}),({"a","b"}),({"b","a"})),
-
({({({ }),({"a"}),({ })}),
-
({({ }),({"a"}),({"b"})}),
-
({({"b"}),({"a"}),({ })})}))
-
test_equal(Array.diff3(({"a","b"}),({"b","a"}),({"a"})),
-
({({({ }),({"a"}),({"b"})}),
-
({({"b"}),({"a"}),({ })}),
-
({({ }),({"a"}),({ })})}))
-
test_equal(Array.diff3(({"b","a"}),({"a"}),({"a","b"})),
-
({({({"b"}),({"a"}),({ })}),
-
({({ }),({"a"}),({ })}),
-
({({ }),({"a"}),({"b"})})}))
-
test_equal(Array.diff3(({"a","b"}),({"a"}),({"b","a"})),
-
({({({ }),({"a"}),({"b"})}),
-
({({ }),({"a"}),({ })}),
-
({({"b"}),({"a"}),({ })})}))
-
test_equal(Array.diff3(({"a","c"}),({"a","c","b","a"}),({"b","a","c"})),
-
({({({ }),({"a","c"}),({ })}),
-
({({ }),({"a","c"}),({"b","a"})}),
-
({({"b"}),({"a","c"}),({ })})}))
-
test_equal(Array.diff3(({"a","c","b","a"}),({"a","c"}),({"b","a","c"})),
-
({({({ }),({"a","c"}),({"b","a"})}),
-
({({ }),({"a","c"}),({ })}),
-
({({"b"}),({"a","c"}),({ })})}))
+
// -
encode
_
value
+
//
-
encode
_
value
_
canonic
+
//
-
endgrent
+
//
-
endpwent
-
+
// - enumerate
+
// Tested in lib
+
// - equal
-
// equal is already tested
by
this script
+
// equal is already tested
a
lot in
this script
-
+
test_any([[
+
class X (string s) {};
+
return equal (({X ("foo")}), ({X (0)}));
+
]], 0)
+
test_any([[
+
class X (string s) {};
+
return equal (({X (0)}), ({X ("foo")}));
+
]], 0)
+
test_any([[
+
class X (string s) {};
+
return equal (({X ("foo")}), ({X ("foo")}));
+
]], 1)
+
+
// - errno
+
+
// - error
+
// Tested in lib
+
+
// - exece
// - exit
-
// FIXME put test for exit here
+
-
// -
explode
-
test_equal(({"a","b","c",}), "anna bnna c"
/
"nna ")
-
test_equal(({"\3333","\3333","\3333",}), "\3333nna \3333nna \3333"
/
"nna
")
-
test_equal(({"\3333333","\3333333","\3333333",}),
"\3333333nna
\3333333nna \3333333"/"nna ")
-
test
_
equal(({"","",}),"hej"/"hej")
-
test_equal(({""}),""/"hej")
+
// -
exp
+
//
Tested
in
_
math
-
// -
fork()
-
//
FIXME:
add
tests
for
fork
+
// -
explode_path
+
//
-
file_stat
+
//
-
file_truncate
+
//
- filesystem_stat
-
cond([[all_constants()
-
>_verify_internals]],
-
[[
-
test_do(_verify_internals())
-
]])
+
//
-
filter
+
//
Tested
in lib/modules
-
+
// - find_call_out
+
+
// - floatp
+
// Tested in foop
+
+
// - floor
+
// Tested in _math
+
+
// - fork
+
// - function_name test_eq(function_name(a),"a") test_eq(function_name(function_name),0) // - function_object test_eq(function_object(a),this_object()) test_eq(function_name(function_object),0)
-
// -
get_
function
(actually in simulate.pike)
-
test
_
eq(a,
-
#pike 7.0
-
Simulate.get_function(this_object(),"a"))
-
test_eq(a,this_object()->a)
+
// - function_
program
-
+
// - functionp
+
// Tested in foop
+
+
// - gc
+
// gc is already tested above
+
+
// - get_all_groups
+
ifefun(get_all_groups,[[
+
test_true(arrayp(get_all_groups()))
+
test_any([[
+
foreach(get_all_groups(), array group)
+
foreach(group; int pos; array(string)|int|string value)
+
switch(pos) {
+
case 0: case 1:
+
if(!stringp(value)) return 0;
+
break;
+
case 2:
+
if(!intp(value)) return 0;
+
break;
+
case 3:
+
if(!arrayp(value)) return 0;
+
foreach(value, string user)
+
if(!stringp(user)) return 0;
+
break;
+
}
+
return 1;
+
]], 1)
+
]])
+
+
// - get_all_users
+
ifefun(get_all_users,[[
+
test_true(arrayp(get_all_users()))
+
test_any([[
+
foreach(get_all_users(), array user)
+
foreach(user; int pos; int|string value)
+
switch(pos) {
+
case 0: case 1: case 4: case 5: case 6:
+
if(!stringp(value)) return 0;
+
break;
+
case 2: case 3:
+
if(!intp(value)) return 0;
+
break;
+
}
+
return 1;
+
]], 1)
+
]])
+
+
// - get_dir
+
test_do(Stdio.recursive_rm("get_dir_test"))
+
test_do(mkdir("get_dir_test"))
+
test_equal(get_dir("get_dir_test"),({}))
+
test_do(Stdio.write_file("get_dir_test/x", "x"));
+
test_equal(get_dir("get_dir_test"),({"x"}))
+
test_do(Stdio.recursive_rm("get_dir_test"))
+
test_true(arrayp(get_dir()))
+
+
// - get_groups_for_user
+
// - get_weak_flag
+
+
// - getcwd
+
test_true(stringp(getcwd()))
+
test_true(sizeof(getcwd()))
+
test_do(Stdio.recursive_rm("getcwd_test"))
+
test_do(mkdir("getcwd_test"))
+
test_any([[
+
string a = getcwd();
+
cd("getcwd_test");
+
string b = getcwd();
+
cd("..");
+
#ifdef __NT__
+
return a==getcwd() && b==a+"\\getcwd_test";
+
#else
+
return a==getcwd() && b==a+"/getcwd_test";
+
#endif
+
]], 1)
+
test_do(Stdio.recursive_rm("getcwd_test"))
+
+
// - getegid
+
ifefun(getegid,[[
+
test_true(intp(getegid()))
+
test_true(getegid()==getegid())
+
]])
+
+
// - getenv
+
+
// - geteuid
+
ifefun(geteuid,[[
+
test_true(intp(geteuid()))
+
test_true(geteuid()==geteuid())
+
]])
+
+
// - getgid
+
ifefun(getgid,[[
+
test_true(intp(getgid()))
+
test_true(getgid()==getgid())
+
]])
+
+
// - getgrent
+
// - getgrgid
+
// - getgrnam
+
// - getgroups
+
// - gethostbyaddr
+
// - gethostbyname
+
+
// - gethostname
+
test_true(stringp(gethostname()))
+
test_true(sizeof(gethostname()))
+
+
// - gethrtime
+
// See time
+
+
// - gethrvtime
+
+
// - getpgrp
+
ifefun(getpgrp,[[
+
test_true(intp(getpgrp()))
+
test_true(getpgrp()==getpgrp())
+
]])
+
+
// - getpid
+
ifefun(getpid,[[
+
test_true(intp(getpid()))
+
test_true(getpid()==getpid())
+
]])
+
+
// - getppid
+
ifefun(getppid,[[
+
test_true(intp(getppid()))
+
test_true(getppid()==getppid())
+
]])
+
+
// - getpwent
+
// - getpwnam
+
// - getpwuid
+
+
// - getsid
+
ifefun(getsid,[[
+
test_true(intp(getsid()))
+
test_true(getsid()==getsid())
+
]])
+
+
// - getuid
+
ifefun(getuid,[[
+
test_true(intp(getuid()))
+
test_true(getuid()==getuid())
+
]])
+
+
// - glob
+
test_false(glob("","a"))
+
test_false(glob("a",""))
+
test_false(glob("?",""))
+
test_true(glob("*",""))
+
test_false(glob("foo","bar"))
+
test_true(glob("foo","foo"))
+
test_true(glob("f?o","foo"))
+
test_true(glob("f??","foo"))
+
test_true(glob("?o?","foo"))
+
test_true(glob("f*","foo"))
+
test_true(glob("*o","foo"))
+
test_true(glob("*<<<*","<<<"))
+
test_true(glob("*<<<*","<<<foo"))
+
test_false(glob("*f","foo"))
+
test_false(glob("o*","foo"))
+
test_false(glob("?f?","foo"))
+
test_equal([[glob("?f?",({"ff","ffff","off","fff",""}))]],[[({"off","fff"})]])
+
test_equal([[glob("foo*bar",({"foobar","foobargazonk","","foofoobar","fobar","fooar"}))]],[[({"foobar","foofoobar"})]])
+
test_eval_error([[
+
array a=({"a","b",3});
+
return glob("*", a);
+
]])
+
test_equal([[glob("foo", ({}))]], ({}))
+
+
// - gmtime
+
cond([[all_constants()->localtime && all_constants()->mktime]],[[
+
test_do([[int t = -1; catch(gmtime(t));]])
+
]])
+
+
// - hardlink
+
+
// - has_index
+
define(test_has_index,[[test_any([[mixed foo=$1; return has_index(foo,$2)==$3;]], 1)]])
+
test_has_index([[ ({}) ]],0,0)
+
test_has_index([[ ({}) ]],"foo",0)
+
test_has_index([[ ({ "a" }) ]],-1,0)
+
test_has_index([[ ({ "a" }) ]],"a",0)
+
test_has_index([[ ({ "a" }) ]],0,1)
+
test_has_index([[ ({ "a" }) ]],1,0)
+
test_has_index([[ ({ "a", "b" }) ]],1,1)
+
test_has_index([[ ([ "a":"A" ]) ]],4711,0)
+
test_has_index([[ ([ "a":"A" ]) ]],"a",1)
+
test_has_index([[ ([ "a":"A" ]) ]],"A",0)
+
test_has_index([[ ([ "a":"A", "b":"B", "c":"C" ]) ]],"b",1)
+
test_has_index([[ ([ "a":"A", "b":"B", "c":"C" ]) ]],"B",0)
+
test_has_index([[ (< "a" >) ]],4711,0)
+
test_has_index([[ (< "a" >) ]],"a",1)
+
test_has_index([[ (< "a" >) ]],"A",0)
+
test_has_index([[ (< "a", "b", "c" >) ]],"b",1)
+
test_has_index([[ (< "a", "b", "c" >) ]],"B",0)
+
test_has_index([[ class {}() ]],"foo",0)
+
test_has_index([[ (class{array _indices(){return({"a","b"});}})() ]],"b",1)
+
+
// - has_prefix
+
test_true(has_prefix("abc","a"))
+
test_false(has_prefix("abc","b"))
+
test_true(has_prefix("abc",""))
+
test_true(has_prefix("",""))
+
test_false(has_prefix("","abc"))
+
test_true(has_prefix("\666abc","\666a"))
+
+
// - has_suffix
+
test_true(has_suffix("cba","a"))
+
test_false(has_suffix("cba","b"))
+
test_true(has_suffix("abc",""))
+
test_true(has_suffix("",""))
+
test_false(has_suffix("","abc"))
+
test_true(has_suffix("cba\666","a\666"))
+
+
// - has_value
+
define(test_has_value,[[test_true([[mixed foo=$1; return has_value(foo,$2)==$3;]])]])
+
test_has_value([[ ({}) ]],0,0)
+
test_has_value([[ ({}) ]],"foo",0)
+
test_has_value([[ ({ "a" }) ]],-1,0)
+
test_has_value([[ ({ "a" }) ]],"a",1)
+
test_has_value([[ ({ "a" }) ]],0,0)
+
test_has_value([[ ({ "a", "b" }) ]],"b",1)
+
test_has_value([[ ([ "a":"A" ]) ]],4711,0)
+
test_has_value([[ ([ "a":"A" ]) ]],"a",0)
+
test_has_value([[ ([ "a":"A" ]) ]],"A",1)
+
test_has_value([[ ([ "a":"A", "b":"B", "c":"C" ]) ]],"B",1)
+
test_has_value([[ ([ "a":"A", "b":"B", "c":"C" ]) ]],"b",0)
+
test_has_value([[ class {}() ]],"foo",0)
+
test_has_value([[ (class{array _values(){return({"a","b"});}})() ]],"b",1)
+
// - hash
-
test_
true
(
intp(
hash("foo"))
)
-
test_
true
(
intp(
hash("foo",10))
)
-
test_
true
(hash("
foo
",
10
)
<10)
-
test_
true
(hash("bar",10)
<10
)
-
test_
true
(hash("
gazonk
",
10
)
<10)
-
test_eq(hash("
foobargazonk
"),hash("
foobargazonk
"))
-
test_
false
(hash(""))
+
test_
eq
(hash("foo")
,2091538203
)
+
test_
eq
(hash("foo",10)
,3
)
+
test_
eq
(hash("
bar
"
)
,
2091518428
)
+
test_
eq
(hash("bar",10)
,8
)
+
test_
eq
(hash("
b\666arqwerty1234
"
)
,
1829582221
)
+
test_eq(hash(""),
0)
+
test_eval_error( return
hash("
foo
"
,0
)
)
+
test_
eval_error
(
return
hash("
foo
"
,-1
)
)
-
// -
implode
-
test_
eq(
[[(
{})*
""
]]
,
"")
-
test_
eq
([[(
"foo"/"o"
)
*"o"
]],
"foo"
)
-
test_
eq
([[(
{"foo"
,
"bar"}
)
*"-"
]],
"foo-bar"
)
-
test_
eq
([[(
{"foo"
,
0
,
"bar"}
)
*"-"
]],"foo
-bar
")
-
test_
eq
([[
({1.0,
"foo",
0
,"bar",
this
_
object
(
),(
[
])})*
"
-
"]],
"foo-bar"
)
-
test_
eq
(
[[({
"
f
",
"o"
,
"o"}
)
*
""
]]
,"foo")
+
// -
hash_7_4
+
define(
test_
hash_7_4,
[[
+
ignore_warning
("
Calling a deprecated value.
",
[[
+
test_
any
([[
+
int i = hash_7_4
(
$1
)
;
+
return
]]
dnl
+
ifelse([[$3]]
,
,, [[((i==$2
)
||(i==$3))?$2:]])dnl
+
[[i;
+
]], $2)
+
]])
+
test_
any
([[
+
int i = 7.4::hash
(
$1);
+
return ]]dnl
+
ifelse([[$3]]
,
,, [[((i==$2
)
||(i==$3))?$2:
]]
)dnl
+
[[i;
+
]]
,
$2
)
+
test_
any
([[
+
#pike 7.4
+
int i = hash
(
$1);
+
return ]]dnl
+
ifelse([[$3]]
,,
, [[((i==$2
)
||(i==$3))?$2:
]]
)dnl
+
[[i;
+
]]
,
$2)
+
]])
+
test_hash_7_4(
"foo"
,2091538203
)
+
test_
hash_7_4
([["foo",
10]]
,
3)
+
test_hash_7_4(
"bar",
2091518428)
+
test
_
hash_7_4
([
[
"
bar
"
,10
]],
8
)
+
test_
hash_7_4
("
b\666arqwerty1234
",
2142487018
,
1858424874
)
+
test_hash_7_4(
"",
0)
+
test_eval_error( return 7.4::hash(
"foo"
,0
)
)
-
+
// - hash_7_0
+
define(test_hash_7_0, [[
+
ignore_warning("Calling a deprecated value.", [[
+
test_any([[
+
int i = hash_7_0($1);
+
return ]]dnl
+
ifelse([[$3]],,, [[((i==$2)||(i==$3))?$2:]])dnl
+
[[i;
+
]], $2)
+
]])
+
test_any([[
+
int i = 7.0::hash($1);
+
return ]]dnl
+
ifelse([[$3]],,, [[((i==$2)||(i==$3))?$2:]])dnl
+
[[i;
+
]], $2)
+
test_any([[
+
#pike 7.0
+
int i = hash($1);
+
return ]]dnl
+
ifelse([[$3]],,, [[((i==$2)||(i==$3))?$2:]])dnl
+
[[i;
+
]], $2)
+
]])
+
test_hash_7_0("foo",27734)
+
test_hash_7_0([["foo",10]],4)
+
test_hash_7_0("bar",26689)
+
test_hash_7_0([["bar",10]],9)
+
test_hash_7_0("b\666arqwerty1234", 2142487018, 1858424874)
+
test_hash_7_0("",0)
+
test_eval_error( return hash_7_0("foo",0) )
+
+
// - hash_value
+
define(test_hash_value, [[
+
test_true(intp(hash_value($1)))
+
dnl Make sure the value to hash has a chance at surviving the optimizer...
+
test_do(add_constant("test_value", $1))
+
test_eq(hash_value($1),hash_value($1))
+
test_do(add_constant("test_value"))
+
]])
+
test_hash_value(77)
+
test_hash_value(5.0)
+
test_hash_value("hello")
+
test_hash_value(({}))
+
dnl (<>) is mutable.
+
test_true(intp(hash_value((<>))))
+
dnl ([]) is mutable.
+
test_true(intp(hash_value(([]))))
+
test_hash_value(time)
+
test_hash_value(ADT.Stack)
+
dnl test_hash_value(String)
+
test_hash_value(typeof(true))
+
// - indices test_equal(indices("foo"),({0,1,2})) test_equal(indices(({'f','o','o'})),({0,1,2})) test_equal(Array.sort_array(indices(([7:3,8:9,99:12]))),({7,8,99})) test_equal(Array.sort_array(indices((<7,8,99>))),({7,8,99})) test_equal(mkmultiset(indices(class{constant a="a"; constant b="b";}())), (<"a","b">))
-
// -
Array.longest_ordered_sequence
-
test_equal(Array.longest_ordered_sequence("dfgaokäpojghadjjioijrgxcvb"
/
""),
-
({ 0, 1, 2, 10, 11, 16, 18, 19, 20, 22 }));
+
// -
initgroups
+
/
/
-
innetgrp
-
+
// - int2char
+
// - int2hex
+
// Tested in String
+
+
// - intp
+
// Tested in foop
+
+
// - is_absolute_path
+
// Tested in lib
+
+
// - kill
+
// - load_module
+
+
// - localtime
+
cond([[all_constants()->localtime]],[[
+
test_true(mappingp(localtime(0)))
+
test_do([[int t = -1; catch(localtime(t));]])
+
]])
+
cond([[all_constants()->localtime && all_constants()->mktime]],
+
[[
+
test_any([[int x=time(); return mktime(localtime(x)) == x;]], 1)
+
test_any([[int x=time(); for(int y=0;y<100;y++) if(mktime(localtime(x+y)) != x+y) return x+y; return 0;]], 0)
+
]])
+
+
+
// - log
+
// Tested in _math
+
// - lower_case test_equal(lower_case("foo"),"foo") test_equal(lower_case("Foo"),"foo") test_equal(lower_case("Foo1234-*~\n"),"foo1234-*~\n") test_equal(lower_case("foo\x3000"),"foo\x3000") test_equal(lower_case("Foo\x3000"),"foo\x3000") test_equal(lower_case("Foo1234-*~\n\x3000"),"foo1234-*~\n\x3000") test_equal(lower_case("foo\x13000"),"foo\x13000") test_equal(lower_case("Foo\x13000"),"foo\x13000") test_equal(lower_case("Foo1234-*~\n\x13000"),"foo1234-*~\n\x13000") test_equal(lower_case("Foo\x178"),"foo\xff") test_equal(lower_case("Foo\x39c"),"foo\x3bc") test_equal(lower_case((string) ({
-
+
// These characters correspond to the cases in case_info.h
+
// Please update this and the corresponding upper_case table
+
// when UnicodeData.txt is changed.
+
// Part 1: 0x0000 - 0x0FFF
0x0000, 0x0041, 0x005b, 0x0061, 0x007b, 0x00b5, 0x00b6, 0x00c0, 0x00d7, 0x00d8, 0x00df, 0x00e0, 0x00f7, 0x00f8, 0x00ff, 0x0100, 0x0130, 0x0131, 0x0132, 0x0138, 0x0139, 0x0149, 0x014a, 0x0178, 0x0179, 0x017f, 0x0180, 0x0181, 0x0182, 0x0186, 0x0187, 0x0189, 0x018b, 0x018d, 0x018e, 0x018f, 0x0190, 0x0191, 0x0193, 0x0194,
-
0x0195, 0x0196, 0x0197, 0x0198, 0x019a, 0x019c, 0x019d, 0x019e,
-
0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01aa, 0x01ac, 0x01ae,
-
0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01ba, 0x01bc, 0x01be,
-
0x01bf, 0x01c0, 0x01c4, 0x01c5, 0x01c7, 0x01c8, 0x01ca, 0x01cb,
-
0x01dd, 0x01de, 0x01f0, 0x01f1, 0x01f2, 0x01f6, 0x01f7, 0x01f8,
-
0x0250
,
0x0253
,
0x0254
,
0x0255
,
0x0256
,
0x0258
,
0x0259
,
0x025a,
-
0x025b
,
0x025c
,
0x0260
,
0x0261
,
0x0263
,
0x0264
,
0x0268
,
0x0269
,
-
0x026a
,
0x026f
,
0x0270
,
0x0272
,
0x0273
,
0x0275
,
0x0276
,
0x0280
,
-
0x0281
,
0x0283
,
0x0284
,
0x0288
,
0x0289
,
0x028a
,
0x028c
,
0x0292
,
-
0x0293
,
0x0345
,
0x0346
,
0x0386
,
0x0387
,
0x0388
,
0x038c
,
0x038e
,
-
0x0390
,
0x0391
,
0x03a0
,
0x03ac
,
0x03ad
,
0x03b0
,
0x03b1
,
0x03c0
,
-
0x03c2
,
0x03c3
,
0x03cc
,
0x03cd
,
0x03d0
,
0x03d1
,
0x03d2
,
0x03d5
,
-
0x03d6
,
0x03d7
,
0x03da
,
0x03f0
,
0x03f1
,
0x03f2
,
0x03f3
,
0x0400
,
-
0x0410
,
0x0420
,
0x0430
,
0x0440
,
0x0450
,
0x0460
,
0x0482
,
0x048c
,
-
0x04c0
,
0x04c1
,
0x04d0
,
0x0531
,
0x0559
,
0x0561
,
0x0587
,
0x1e00
,
-
0x1e96
,
0x1e9b
,
0x1ea0
,
0x1f00
,
0x1f08
,
0x1f10
,
0x1f18
,
0x1f20
,
-
0x1f28
,
0x1f30
,
0x1f38
,
0x1f40
,
0x1f48
,
0x1f50
,
0x1f51
,
0x1f52
,
-
0x1f53
,
0x1f54
,
0x1f55
,
0x1f56
,
0x1f57
,
0x1f59
,
0x1f60
,
0x1f68
,
-
0x1f70
,
0x1f72
,
0x1f76
,
0x1f78
,
0x1f7a
,
0x1f7c
,
0x1f80
,
0x1f88
,
-
0x1f90
,
0x1f98
,
0x1fa0
,
0x1fa8
,
0x1fb0
,
0x1fb2
,
0x1fb3
,
0x1fb4
,
-
0x1fb8
,
0x1fba
,
0x1fbc
,
0x1fbd
,
0x1fbe
,
0x1fbf,
0x1fc3, 0x1fc4,
-
0x1fc8, 0x1fcc, 0x1fcd, 0x1fd0, 0x1fd2, 0x1fd8, 0x1fda, 0x1fdd,
-
0x1fe0, 0x1fe2, 0x1fe5, 0x1fe6, 0x1fe8, 0x1fea, 0x1fec, 0x1fed,
-
0x1ff3, 0x1ff4, 0x1ff8, 0x1ffa, 0x1ffc, 0x1ffd, 0x2126, 0x2127,
-
0x212a, 0x212b, 0x212c, 0x2160, 0x2180, 0x24b6, 0x24d0, 0x24ea,
-
0xff21, 0xff3b, 0xff41, 0xff5b,
})),
(string) ({
+
0x0195, 0x0196, 0x0197, 0x0198, 0x019a,
0x019b,
0x019c, 0x019d,
+
0x019e, 0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01aa, 0x01ac,
+
0x01ae, 0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01ba, 0x01bc,
+
0x01be, 0x01bf, 0x01c0, 0x01c4, 0x01c5, 0x01c7, 0x01c8, 0x01ca,
+
0x01cb, 0x01dd, 0x01de, 0x01f0, 0x01f1, 0x01f2, 0x01f6, 0x01f7,
+
0x01f8,
0x0220
,
0x0221
,
0x0222
,
0x0234
,
0x023a
,
0x023b
,
0x023d
,
+
0x023e
,
0x023f
,
0x0241
,
0x0243
,
0x0244
,
0x0245
,
0x0246
,
0x0250
,
+
0x0251
,
0x0252
,
0x0253
,
0x0254
,
0x0255
,
0x0256
,
0x0258
,
0x0259
,
+
0x025a
,
0x025b
,
0x025c
,
0x0260
,
0x0261
,
0x0263
,
0x0264
,
0x0265
,
+
0x0266
,
0x0267
,
0x0268
,
0x0269
,
0x026a
,
0x026b
,
0x026c
,
0x026f
,
+
0x0270
,
0x0271
,
0x0272
,
0x0273
,
0x0275
,
0x0276
,
0x027d
,
0x027e
,
+
0x0280
,
0x0281
,
0x0283
,
0x0284
,
0x0288
,
0x0289
,
0x028a
,
0x028c
,
+
0x028d
,
0x0292
,
0x0293
,
0x0345
,
0x0346
,
0x0370
,
0x0374
,
0x0376
,
+
0x0378
,
0x037b
,
0x037e
,
0x0386
,
0x0387
,
0x0388
,
0x038b
,
0x038c
,
+
0x038d
,
0x038e
,
0x0390
,
0x0391
,
0x03a0
,
0x03a2
,
0x03a3
,
0x03ac
,
+
0x03ad
,
0x03b0
,
0x03b1
,
0x03c0
,
0x03c2
,
0x03c3
,
0x03cc
,
0x03cd
,
+
0x03cf
,
0x03d0
,
0x03d1
,
0x03d2
,
0x03d5
,
0x03d6
,
0x03d7
,
0x03d8
,
+
0x03f0
,
0x03f1
,
0x03f2
,
0x03f3
,
0x03f4
,
0x03f5
,
0x03f6
,
0x03f7
,
+
0x03f9
,
0x03fa
,
0x03fc
,
0x03fd
,
0x0400
,
0x0410
,
0x0420
,
0x0430
,
+
0x0440
,
0x0450
,
0x0460
,
0x0482
,
0x048a
,
0x04c0
,
0x04c1
,
0x04cf
,
+
0x04d0
,
0x0528
,
0x0531
,
0x0557
,
0x0561
,
0x0587
})),
+
(string) ({
0x0000, 0x0061, 0x005b, 0x0061, 0x007b, 0x00b5, 0x00b6, 0x00e0, 0x00d7, 0x00f8, 0x00df, 0x00e0, 0x00f7, 0x00f8, 0x00ff, 0x0101, 0x0069, 0x0131, 0x0133, 0x0138, 0x013a, 0x0149, 0x014b, 0x00ff, 0x017a, 0x017f, 0x0180, 0x0253, 0x0183, 0x0254, 0x0188, 0x0256, 0x018c, 0x018d, 0x01dd, 0x0259, 0x025b, 0x0192, 0x0260, 0x0263,
-
0x0195, 0x0269, 0x0268, 0x0199, 0x019a, 0x026f, 0x0272, 0x019e,
-
0x0275, 0x01a1, 0x0280, 0x01a8, 0x0283, 0x01aa, 0x01ad, 0x0288,
-
0x01b0, 0x028a, 0x01b4, 0x0292, 0x01b9, 0x01ba, 0x01bd, 0x01be,
-
0x01bf, 0x01c0, 0x01c6, 0x01c6, 0x01c9, 0x01c9, 0x01cc, 0x01cc,
-
0x01dd, 0x01df, 0x01f0, 0x01f3, 0x01f3, 0x0195, 0x01bf, 0x01f9,
-
0x0250, 0x0253, 0x0254, 0x0255, 0x0256, 0x0258, 0x0259, 0x025a,
-
0x025b, 0x025c, 0x0260, 0x0261, 0x0263, 0x0264, 0x0268, 0x0269,
-
0x026a, 0x026f, 0x0270, 0x0272, 0x0273, 0x0275, 0x0276,
0x0280
,
-
0x0281, 0x0283, 0x0284, 0x0288, 0x0289, 0x028a, 0x028c, 0x0292,
-
0x0293, 0x0345, 0x0346, 0x03ac, 0x0387, 0x03ad, 0x03cc, 0x03cd,
-
0x0390, 0x03b1, 0x03c0, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03c0,
-
0x03c2, 0x03c3, 0x03cc, 0x03cd, 0x03d0, 0x03d1, 0x03d2, 0x03d5,
-
0x03d6, 0x03d7,
0x03db
, 0x03f0, 0x03f1, 0x03f2, 0x03f3,
0x0450
,
-
0x0430, 0x0440, 0x0430, 0x0440, 0x0450, 0x0461, 0x0482,
0x048d
,
-
0x04c0
, 0x04c2, 0x04d1, 0x0561,
0x0559
, 0x0561, 0x0587,
0x1e01
,
-
0x1e96, 0x1e9b, 0x1ea1, 0x1f00, 0x1f00, 0x1f10, 0x1f10, 0x1f20,
-
0x1f20, 0x1f30, 0x1f30, 0x1f40, 0x1f40,
0x1f50
, 0x1f51, 0x1f52,
-
0x1f53, 0x1f54, 0x1f55, 0x1f56, 0x1f57, 0x1f51, 0x1f60, 0x1f60,
-
0x1f70, 0x1f72, 0x1f76, 0x1f78, 0x1f7a, 0x1f7c,
0x1f80
, 0x1f80,
-
0x1f90, 0x1f90, 0x1fa0, 0x1fa0, 0x1fb0, 0x1fb2, 0x1fb3, 0x1fb4,
-
0x1fb0, 0x1f70, 0x1fb3, 0x1fbd, 0x1fbe, 0x1fbf, 0x1fc3, 0x1fc4,
-
0x1f72, 0x1fc3, 0x1fcd, 0x1fd0, 0x1fd2, 0x1fd0, 0x1f76,
0x1fdd
,
-
0x1fe0, 0x1fe2, 0x1fe5, 0x1fe6, 0x1fe0, 0x1f7a, 0x1fe5, 0x1fed,
-
0x1ff3, 0x1ff4, 0x1f78, 0x1f7c, 0x1ff3, 0x1ffd, 0x03c9, 0x2127,
-
0x006b, 0x00e5, 0x212c, 0x2170, 0x2180, 0x24d0, 0x24d0, 0x24ea,
-
0xff41, 0xff3b, 0xff41, 0xff5b, }))
+
0x0195, 0x0269, 0x0268, 0x0199, 0x019a,
0x019b,
0x026f, 0x0272,
+
0x019e, 0x0275, 0x01a1, 0x0280, 0x01a8, 0x0283, 0x01aa, 0x01ad,
+
0x0288, 0x01b0, 0x028a, 0x01b4, 0x0292, 0x01b9, 0x01ba, 0x01bd,
+
0x01be, 0x01bf, 0x01c0, 0x01c6, 0x01c6, 0x01c9, 0x01c9, 0x01cc,
+
0x01cc, 0x01dd, 0x01df, 0x01f0, 0x01f3, 0x01f3, 0x0195, 0x01bf,
+
0x01f9,
0x019e, 0x0221, 0x0223, 0x0234, 0x2c65, 0x023c, 0x019a,
+
0x2c66, 0x023f, 0x0242, 0x0180, 0x0289, 0x028c, 0x0247,
0x0250,
+
0x0251, 0x0252,
0x0253, 0x0254, 0x0255, 0x0256, 0x0258, 0x0259,
+
0x025a, 0x025b, 0x025c, 0x0260, 0x0261, 0x0263, 0x0264,
0x0265,
+
0x0266, 0x0267,
0x0268, 0x0269, 0x026a,
0x026b, 0x026c,
0x026f,
+
0x0270,
0x0271,
0x0272, 0x0273, 0x0275, 0x0276,
0x027d, 0x027e,
+
0x0280, 0x0281, 0x0283, 0x0284, 0x0288, 0x0289, 0x028a, 0x028c,
+
0x028d,
0x0292, 0x0293, 0x0345, 0x0346,
0x0371, 0x0374, 0x0377,
+
0x0378, 0x037b, 0x037e,
0x03ac, 0x0387, 0x03ad,
0x038b,
0x03cc,
+
0x038d,
0x03cd, 0x0390, 0x03b1, 0x03c0,
0x03a2, 0x03c3,
0x03ac,
+
0x03ad, 0x03b0, 0x03b1, 0x03c0, 0x03c2, 0x03c3, 0x03cc, 0x03cd,
+
0x03d7,
0x03d0, 0x03d1, 0x03d2, 0x03d5, 0x03d6, 0x03d7,
0x03d9
,
+
0x03f0, 0x03f1, 0x03f2, 0x03f3,
0x03b8, 0x03f5, 0x03f6, 0x03f8,
+
0x03f2, 0x03fb, 0x03fc, 0x037b,
0x0450, 0x0430, 0x0440, 0x0430,
+
0x0440, 0x0450, 0x0461, 0x0482,
0x048b
,
0x04cf
, 0x04c2,
0x04cf,
+
0x04d1,
0x0528,
0x0561,
0x0557
, 0x0561, 0x0587
}))
+
test_equal(lower_case((string) ({
+
// These characters correspond to the cases in case_info.h
+
// Please update this and the corresponding upper_case table
+
// when UnicodeData.txt is changed.
+
// Part 2: 0x1000 -
+
0x10a0
,
0x10c6
,
0x10c7, 0x10c8, 0x10cd, 0x10ce, 0x1d79, 0x1d7a,
+
0x1d7d, 0x1d7e, 0x1e00,
0x1e96, 0x1e9b,
0x1e9c, 0x1e9e, 0x1e9f,
+
0x1ea0, 0x1f00, 0x1f08, 0x1f10, 0x1f16, 0x1f18, 0x1f1e, 0x1f20,
+
0x1f28, 0x1f30, 0x1f38, 0x1f40, 0x1f46, 0x1f48, 0x1f4e, 0x1f51,
+
0x1f52, 0x1f53, 0x1f54, 0x1f55, 0x1f56, 0x1f57, 0x1f58, 0x1f59,
+
0x1f5a, 0x1f5b, 0x1f5c, 0x1f5d, 0x1f5e, 0x1f5f, 0x1f60, 0x1f68,
+
0x1f70, 0x1f72, 0x1f76, 0x1f78, 0x1f7a, 0x1f7c, 0x1f7e, 0x1f80,
+
0x1f88, 0x1f90, 0x1f98, 0x1fa0, 0x1fa8, 0x1fb0, 0x1fb2, 0x1fb3,
+
0x1fb4, 0x1fb8, 0x1fba, 0x1fbc, 0x1fbd, 0x1fbe, 0x1fbf, 0x1fc3,
+
0x1fc4, 0x1fc8, 0x1fcc, 0x1fcd, 0x1fd0, 0x1fd2, 0x1fd8, 0x1fda,
+
0x1fdc, 0x1fe0, 0x1fe2, 0x1fe5, 0x1fe6, 0x1fe8, 0x1fea, 0x1fec,
+
0x1fed, 0x1ff3, 0x1ff4, 0x1ff8, 0x1ffa, 0x1ffc, 0x1ffd, 0x2126,
+
0x2127, 0x212a, 0x212b, 0x212c, 0x2132, 0x2133, 0x214e, 0x214f,
+
0x2160, 0x2180, 0x2183, 0x2185, 0x24b6, 0x24d0, 0x24ea, 0x2c00,
+
0x2c2f, 0x2c30, 0x2c5f, 0x2c60, 0x2c62, 0x2c63, 0x2c64, 0x2c65,
+
0x2c66, 0x2c67, 0x2c6d, 0x2c6e, 0x2c6f, 0x2c70, 0x2c71, 0x2c72,
+
0x2c74, 0x2c75, 0x2c77, 0x2c7e, 0x2c80, 0x2ce4, 0x2ceb, 0x2cef,
+
0x2cf2, 0x2cf4, 0x2d00, 0x2d26, 0x2d27, 0x2d28, 0x2d2d, 0x2d2e,
+
0xa640, 0xa66e, 0xa680, 0xa698, 0xa722, 0xa730, 0xa732, 0xa770,
+
0xa779, 0xa77d, 0xa77e, 0xa788, 0xa78b, 0xa78d, 0xa78e, 0xa790,
+
0xa794, 0xa7a0, 0xa7aa, 0xa7ab, 0xff21, 0xff3b, 0xff41, 0xff5b,
+
0x10400, 0x10428, 0x10450 })),
+
(string) ({
+
0x2d00, 0x10c6, 0x2d27, 0x10c8, 0x2d2d, 0x10ce, 0x1d79, 0x1d7a,
+
0x1d7d, 0x1d7e, 0x1e01, 0x1e96, 0x1e9b, 0x1e9c, 0x00df, 0x1e9f,
+
0x1ea1, 0x1f00, 0x1f00, 0x1f10,
0x1f16,
0x1f10,
0x1f1e,
0x1f20,
+
0x1f20, 0x1f30, 0x1f30, 0x1f40,
0x1f46,
0x1f40,
0x1f4e
, 0x1f51,
+
0x1f52, 0x1f53, 0x1f54, 0x1f55, 0x1f56, 0x1f57,
0x1f58,
0x1f51,
+
0x1f5a, 0x1f53, 0x1f5c, 0x1f55, 0x1f5e, 0x1f57,
0x1f60, 0x1f60,
+
0x1f70, 0x1f72, 0x1f76, 0x1f78, 0x1f7a, 0x1f7c,
0x1f7e,
0x1f80,
+
0x1f80, 0x1f90, 0x1f90, 0x1fa0, 0x1fa0, 0x1fb0, 0x1fb2, 0x1fb3,
+
0x1fb4, 0x1fb0, 0x1f70, 0x1fb3, 0x1fbd, 0x1fbe, 0x1fbf, 0x1fc3,
+
0x1fc4, 0x1f72, 0x1fc3, 0x1fcd, 0x1fd0, 0x1fd2, 0x1fd0, 0x1f76,
+
0x1fdc
, 0x1fe0, 0x1fe2, 0x1fe5, 0x1fe6, 0x1fe0, 0x1f7a, 0x1fe5,
+
0x1fed, 0x1ff3, 0x1ff4, 0x1f78, 0x1f7c, 0x1ff3, 0x1ffd, 0x03c9,
+
0x2127, 0x006b, 0x00e5, 0x212c,
0x214e, 0x2133, 0x214e, 0x214f,
+
0x2170, 0x2180,
0x2184, 0x2185,
0x24d0, 0x24d0, 0x24ea,
0x2c30,
+
0x2c2f, 0x2c30, 0x2c5f, 0x2c61, 0x026b, 0x1d7d, 0x027d, 0x2c65,
+
0x2c66, 0x2c68, 0x0251, 0x0271, 0x0250, 0x0252, 0x2c71, 0x2c73,
+
0x2c74, 0x2c76, 0x2c77, 0x023f, 0x2c81, 0x2ce4, 0x2cec, 0x2cef,
+
0x2cf3, 0x2cf4, 0x2d00, 0x2d26, 0x2d27, 0x2d28, 0x2d2d, 0x2d2e,
+
0xa641, 0xa66e, 0xa681, 0xa698, 0xa723, 0xa730, 0xa733, 0xa770,
+
0xa77a, 0x1d79, 0xa77f, 0xa788, 0xa78c, 0x0265, 0xa78e, 0xa791,
+
0xa794, 0xa7a1, 0x0266, 0xa7ab,
0xff41, 0xff3b, 0xff41, 0xff5b,
+
0x10428, 0x10428, 0x10450
}))
-
+
// - m_delete
+
// - map
-
+
// - mappingp
+
// Tested in foop
+
+
// - master
+
+
// - max
+
// - min
+
// Tested in _math
+
+
// - mkdir
+
+
// - mkmapping
+
test_equal(mkmapping(({}),({})), ([]))
+
test_equal(mkmapping(({0}),({0})), ([0:0]))
+
test_any_equal([[
+
array a=({"a"});
+
return mkmapping(a,a);
+
]], (["a":"a"]))
+
test_equal(mkmapping( ({({})}),({({})}) )[ ({}) ], ({}))
+
+
// - mkmultiset
+
test_equal(mkmultiset(({})), (<>))
+
test_equal(mkmultiset(({0})), (<0>))
+
test_equal(mkmultiset(({(<>)})), (<(<>)>))
+
+
// - mktime
+
cond([[all_constants()->mktime]],
+
[[
+
test_true([[mktime( ([
+
"sec":58,
+
"isdst":1,
+
"year":98,
+
"mon":3,
+
"mday":26,
+
"hour":1,
+
"min":51
+
]))]])
+
+
test_eq([[mktime(58,51,1,26,3,98,1,0)]],[[mktime( ([
+
"sec":58,
+
"isdst":1,
+
"year":98,
+
"mon":3,
+
"mday":26,
+
"hour":1,
+
"min":51,
+
"timezone":0,
+
]) ) ]])
+
+
test_any([[foreach(({1075550400,94691300,220921700,347152100,473382500,
+
599612900,725843300,852073700,978304100,1104534500,
+
1230764900,1356995300,1483225700,1609456100,1735686500,
+
1861916900,1988147300,2114377700
+
}),int t) {
+
int res = mktime (gmtime (t));
+
if(res!=t) return ({t, res});
+
}
+
return 0;]], 0)
+
+
test_eq(mktime (0, 0, 0, -200, -6, 101, 0, 0), 945043200);
+
test_eq(mktime (0, 0, 0, -1, 2, 107, 0, 0), 1172534400);
+
test_eq(mktime (0, 0, 0, 200, 1, 107, 0, 0), 1187481600);
+
test_eq(mktime (200, 200, 200, 200, 1, 107, 0, 0), 1188213800);
+
test_eq(mktime (-200, -200, -200, 200, 1, 107, 0, 0), 1186749400);
+
+
test_any( [[
+
// bug [2861] ------------------------------------------------------------
+
// http://community/crunch/show_bug.cgi?id=2861
+
return mktime(0,0,0,1,0,70,0,0);
+
]], 0)
+
+
test_any( [[
+
// bug [3270] ------------------------------------------------------------
+
// http://community/crunch/show_bug.cgi?id=3270
+
// Tue, 15 Oct 2002 09:38:32 GMT
+
return mktime(32, 38, 9, 15, 9, 102, 0, 0);
+
]], 1034674712)
+
]])
+
+
// - multisetp
+
// Tested in foop
+
+
// - mv
+
// - next_object
-
test_true(objectp(next_object()))
-
test_any(
int
e;
object o=next_object(); for(e=0;e<10000 && o;e++) o=next_object(o); return o,0)
+
test_true(objectp(next_object())
|| intp(next_object(
)
) && next_object())
+
test_any(
[[
+
object o=next_object();
+
for(
int
e=0;
e<10000 &&
(objectp(
o
) || intp(o) && o)
;
e++)
+
o=next_object(o);
+
return o
;
+
]]
,
0)
-
+
// - normalize_path
+
// Tested in lib
+
// - object_program test_true(programp(object_program(this_object())))
-
+
// - object_variablep
+
// - openlog
+
+
// - pow
+
// Tested in _math
+
+
// - programp
+
// Tested in foop
+
+
// - putenv
+
// Tested in lib
+
// - query_num_arg test_eq(lambda(int ... q) { return query_num_arg(); }(),0) test_eq(lambda(int ... q) { return query_num_arg(); }(1),1) test_eq(lambda(int ... q) { return query_num_arg(); }(1,1),2) test_eq(lambda(int ... q) { return query_num_arg(); }(1,1,1),3) test_eq(lambda(int ... q) { return query_num_arg(); }(1,1,1,1),4) // - random test_any([[int e,d;for(e=0;e<1000;e++){d=random(10); if(d<0 || d>=10) return 0;} return 1]],1)
-
+
test_eq([[ random( ({11,21,31,41}) ) % 10 ]], 1)
+
test_eq([[ random( ({11,21,31,41}) ) % 10 ]], 1)
+
test_eq([[ random( ({11,21,31,41}) ) % 10 ]], 1)
+
test_eq([[ random( ({11,21,31,41}) ) % 10 ]], 1)
+
test_eq([[ random( (<11,21,31,41>) ) % 10 ]], 1)
+
test_eq([[ random( (<11,21,31,41>) ) % 10 ]], 1)
+
test_eq([[ random( (<11,21,31,41>) ) % 10 ]], 1)
+
test_eq([[ random( (<11,21,31,41>) ) % 10 ]], 1)
+
test_eq([[ random( (<11,21,31,41>) ) % 10 ]], 1)
+
test_eq([[ random( (<11,21,31,41>) ) % 10 ]], 1)
+
test_eq([[ `-( @random( ([11:21,31:41]) )) ]], -10)
+
test_eq([[ `-( @random( ([11:21,31:41]) )) ]], -10)
+
test_eq([[ `-( @random( ([11:21,31:41]) )) ]], -10)
+
test_eq([[ `-( @random( ([11:21,31:41]) )) ]], -10)
+
test_eval_error([[ return random( ({}) ) ]])
+
test_eval_error([[ return random( (<>) ) ]])
+
test_eval_error([[ return random( ([]) ) ]])
+
test_eq([[ random( class() { int _random() { return 17; }}()) ]], 17)
-
// random_seed
+
//
-
random_seed
test_do(int p; foreach(({1,2,3,4,5}),p) random_seed(p)) test_eq([[random_seed(17),random(20000)]],[[random_seed(17),random(20000)]]) test_eq([[random_seed(18),random(20000)]],[[random_seed(18),random(20000)]]) test_eq([[random_seed(19),random(20000)]],[[random_seed(19),random(20000)]])
-
+
test_equal([[random_seed(4711),map(allocate(10,1000), random)]],
+
[[({598,11,331,991,383,553,997,53,272,381})]])
-
+
// - random_string
+
test_eq( sizeof(random_string(47)), 47 )
+
test_eq( random_string(0), "" )
+
test_eval_error( return random_string(-1); )
+
+
// - readlink
+
// - remove_call_out
+
+
// - remove_include_path
+
// - remove_module_path
+
// - remove_program_path
+
// Tested in lib
+
// - replace test_eq(replace("foo","f","\x9999"),"\x9999oo") test_eq(replace("foo",({"f"}),({"\x9999"})),"\x9999oo") test_eq([[replace("11013",({"1","100","108","13","1069","1067","106","10"}), ({"A","B","C","D","E","F","G","H"}))]],"AHD") test_eq([[replace("1264412124",({"126","124","12","122","1260"}), ({"13333","13335","883","13329","226709"}))]],"133334488313335") test_eq(replace("foobargazonk","o","-"),"f--bargaz-nk") test_eq(replace("foobargazonk",({"o","a"}),({"()","<>"})),"f()()b<>rg<>z()nk") test_eq(replace("f--barf--",({"f--","f--bar"}),({"f--bar","f--"})),"f--f--bar") test_eq(replace("f--barf--",({"f--bar","f--"}),({"f--","f--bar"})),"f--f--bar") test_eq(replace("test\ntest\n\ntest\ntest",({"\n","\n\n"}),({" ","<p>"})),"test test<p>test test") test_eq(replace("test\ntest\n\ntest\ntest",({"\n\n","\n"}),({"<p>"," "})),"test test<p>test test")
-
+
test_eq(replace("\xfffffff0", ({ "\xfffffff0" }), ({ "" })), "")
+
test_eq([[ replace("abcdefg", ([ "a":"x", "d":"y", "h":"z" ])) ]], "xbcyefg")
test_eq("123\000456""890"-"\0", "123\456""890") test_eq("123\456000""890"-"\0", "123\456000""890") test_any([[
-
+
array a=({ 1 });
+
replace(a,1,2);
+
return a[0];
+
]], 2)
+
+
test_any([[
+
mapping a=([ 1:1 ]);
+
replace(a,1,2);
+
return a[1];
+
]], 2)
+
+
test_any([[
function reference=lambda(string x, array(string) a, array(string) b) { string ret=""; for(int pos=0;pos<strlen(x);) { int best=-1; int bestlen=-1; for(int e=0;e<sizeof(a);e++) { if(strlen(a[e])>bestlen)
pike.git/src/testsuite.in:5491:
}; for(int e=0;e<10000;e++) { array(string) base=(array(string)) ( (({random})*(1+random(10)))(20) ); for(int d=0;d<random(random(40));d++) base+=({ base[ random(sizeof(base))] + random(10) }); base=Array.uniq(base);
-
string
*
to=(array(string))Array.map(base,hash);
+
array(
string
)
to=(array(string))Array.map(base,hash);
string text=""; for(int d=0;d<1+random(random(50));d++) { if(random(2)) text+=base[ random(sizeof(base))]; else text+=sprintf("%2d",random(100)); } string r1=replace(text,base,to); string r2=reference(text,base,to); if(r1 != r2) {
-
werror("
\nFailiure
:\n");
+
werror("
\nFailure
:\n");
werror("Text: %O\n",text); werror("From: %O\n",base); werror("To : %O\n",to); werror("Builtin: %O\n",r1); werror("Ref : %O\n",r2); return -1; } } return 1; ]],1)
pike.git/src/testsuite.in:5532:
test_eq(replace("f\777\777barf\777\777",({"f\777\777bar","f\777\777"}),({"f\777\777","f\777\777bar"})),"f\777\777f\777\777bar") test_eq(replace("f\7777777\7777777bargaz\7777777nk","\7777777","-"),"f--bargaz-nk") test_eq(replace("f\7777777\7777777bargaz\7777777nk",({"\7777777","a"}),({"()","<>"})),"f()()b<>rg<>z()nk") test_eq(replace("f\7777777\7777777barf\7777777\7777777",({"f\7777777\7777777","f\7777777\7777777bar"}),({"f\7777777\7777777bar","f\7777777\7777777"})),"f\7777777\7777777f\7777777\7777777bar") test_eq(replace("f\7777777\7777777barf\7777777\7777777",({"f\7777777\7777777bar","f\7777777\7777777"}),({"f\7777777\7777777","f\7777777\7777777bar"})),"f\7777777\7777777f\7777777\7777777bar") test_equal(replace(({1,2,3,4,5,1,2,3,4}),3,-1),({1,2,-1,4,5,1,2,-1,4})) test_equal(replace(([1:2,3:4,5:1,2:3]),3,-1),([1:2,3:4,5:1,2:-1]))
+
test_eval_error([[
+
mapping a = ([ "a":"b", 3:"c" ]);
+
return replace("bar", a);
+
]])
+
test_eval_error([[
+
mapping a = ([ "a":"b", "c":3 ]);
+
return replace("bar", a);
+
]])
+
test_eval_error([[
+
return replace("bar", ({"a"}), ({"b","c"}));
+
]])
+
+
// - replace_master
+
// - reverse test_eq(reverse("reverse"),"esrever") test_eq(reverse("r\777v\777rs\777"),"\777sr\777v\777r") test_eq(reverse("r\7777777v\7777777rs\7777777"),"\7777777sr\7777777v\7777777r") test_eq(reverse(""),"") test_eq(reverse("a"),"a") test_equal(reverse(({1,5,9})),({9,5,1})) test_equal(reverse(({})),({})) test_equal(reverse(({42})),({42})) test_equal(reverse(({42,4711})),({4711,42})) test_equal(reverse(0x12345678),0x1e6a2c48)
-
// -
rusage
-
test_true(arrayp(rusage()))
-
test_true(sizeof(rusage())>28)
+
// -
rm
-
// -
has_index
-
test_false([[
has_index([mixed]
({}),
0) ]])
-
test
_
false([[ has_index([mixed] ({}), "foo") ]])
-
test_false([[ has_index([mixed] ({ "a" }), -1) ]])
-
test_false([[ has_index([mixed] ({ "a" }), "a") ]])
-
test_true([[ has_index([mixed] ({ "a" }), 0) ]])
-
test_false([[ has_index([mixed] ({ "a" }), 1) ]])
-
test_true([[ has_index([mixed] ({ "a", "b" }), 1) ]])
-
test_false([[ has_index([mixed] ([ "a":"A" ]), 4711) ]])
-
test_true([[ has_index([mixed] ([ "a":"A" ]), "a") ]])
-
test_false([[ has_index([mixed] ([ "a":"A" ]), "A") ]])
-
test_true([[ has_index([mixed] ([ "a":"A", "b":"B", "c":"C" ]), "b") ]])
-
test_false([[ has_index([mixed] ([ "a":"A", "b":"B", "c":"C" ]), "B") ]])
-
test_false([[ has_index((class {})(), "foo") ]])
-
test_true([[has_index((class{array _indices(){return({"a","b"});}})(),"b")]])
+
// -
round
+
//
Tested
in
_
math
-
// -
has_value
-
test_
false
([[
has_value
(
[mixed]
(
{})
,
0) ]])
-
test_false([[ has_value([mixed] ({})
,
"foo"
)
]])
-
test_false
(
[[ has_value([mixed] ({ "a" })
,
-1
)
]]
)
-
test_true([[ has_value([mixed
]
({ "a" }), "a")
]
])
-
test_false(
[[
has_value
(
[mixed] ({ "a" })
,
0
)
]])
-
test_
true
([[
has_value
(
[mixed]
(
{ "a"
,
"b" })
,
"b"
)
]])
-
test_false
(
[[ has_value([mixed] ([ "a":"A" ])
,
4711
)
]]
)
-
test_true([[ has_value([mixed
]
([ "a":"A"
]
)
,
"A") ]])
-
test_false(
[[
has_value
(
[mixed] ([ "a":"A" ])
,
"a"
)
]])
-
test_
true
([[
has_value
(
[mixed]
(
[ "a":"A"
,
"b":"B"
,
"c":"C" ])
,
"B") ]])
-
test_false([[ has_value([mixed] ([ "a":"A"
,
"b":"B"
,
"c":"C" ])
,
"b"
)
]])
-
test_false
(
[[ has_value((class {})()
,
"foo"
)
]]
)
-
test_true(
[[
has_value
(
(class{array _values(){return({"a"
,
"b"});}})()
,
"b"
)]])
+
// -
rows
+
test_
equal
([[
rows
((
{1,2,3,4,5,6,7,8,9}
),(
{6
,
7,2}
))]],[[(
{7
,
8,3}
)]])
+
test_
equal
([[
rows
((
{1
,
2,3,4,5,6,7,8,9}
),(
{0
,
4,1}
))]],[[(
{1
,
5,2}
)]])
+
test_
equal
([[
rows
((
{1
,
2
,
3,4,5,6,7,8,9}
),(
{8
,
3
,
5}
))]],[[(
{9
,
4
,
6}
)]])
// - search test_eval_error(return search("foolbar","o",-10)) test_eval_error(return search("foolbar","o",2983742)) test_eq(search("foolbar","gazonk"),-1) test_eq(search("qowiueproqiuweproiwqueoplkjljlklksjjriwueproiuwerowieu","lkjljlklksjj"),24) test_eq(search("lkjljlklksjjriwueproiuwerlskjdvlaskjfowieu","lkjljlklksjj"),0) test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj","lkjljlklksjj"),24)
-
+
+
// Search cache is initialized with 10 slots.
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj1","lkjljlklksjj1"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj2","lkjljlklksjj2"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj3","lkjljlklksjj3"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj4","lkjljlklksjj4"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj5","lkjljlklksjj5"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj6","lkjljlklksjj6"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj7","lkjljlklksjj7"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj8","lkjljlklksjj8"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj9","lkjljlklksjj9"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj0","lkjljlklksjj0"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjjx","lkjljlklksjjx"),24)
+
test_eq(search("aaaaaaaaaaaaaaaaaaaaaaaalkjljlklksjj","lkjljlklksjj"),24)
+
test_eq(search("foobargazonk","oo"),1) test_eq(search("foobargazonk","o",3),9) test_eq(search("foobargazonk","o",9),9) test_eq(search("foobargazonk","o",10),-1) test_eq(search("foobargazonk","x",9),-1) test_eq(search(({56,8,2,6,2,7,3,56,7}),8),1) test_eq(search(({56,8,2,6,2,7,3,56,7}),56,0),0) test_eq(search(({56,8,2,6,2,7,3,56,7}),56,1),7) test_eq(search(({56,8,2,6,2,7,3,56,7}),56,7),7) test_eq(search(({56,8,2,6,2,7,3,56,7}),56,8),-1) test_eq(search(({"foo"}),"foo"),0) test_eq(search("fo-obar|gazonk"/"|","fo-obar"),0) test_eq(search("fo-obar|gazonk"/"|","gazonk"),1) test_eq(search(([1:2,3:4,5:6,7:8]),4),3)
-
test_true(zero_type(search(([1:2,3:4,5:6,7:8]),3)))
+
test_true(zero_type(search(([1:2,3:4,5:6,7:8]),
(int)
3)))
test_eq(search(([1:2,3:4,5:6,7:8]),8),7)
-
+
test_eq(search("foo",""),0)
test_any([[ mapping m=([]); m+=(["x":([])]); m->x->y++; m=([]); m+=(["x":([])]); return m->x->y; ]], 0) test_do([[
pike.git/src/testsuite.in:5647:
test_any_equal([[ mapping m = (["foo": "bar", "bar": "gnu", "gnu": "bar"]); array a = ({}); a += ({search (m, "bar")}); a += ({search (m, "bar", a[-1])}); a += ({search (m, "bar", a[-1])}); return sort (a); ]], sort(({0, "foo", "gnu"})))
+
// Some versions of Pike prior to 7.8 had unsigned characters.
+
// We regard this as an implementation bug, and thus no compat.
+
cond([[0]], [[
+
test_equal([[
+
#pike 7.6
+
sort(({"\Uffffffff","\0", "", "\177", "\377", "\U7fffffff"}));
+
]], ({ "", "\0", "\177", "\377", "\U7fffffff", "\Uffffffff" }))
+
]])
+
+
test_equal([[
+
sort(({"\Uffffffff","\0", "", "\177", "\377", "\U7fffffff"}));
+
]], ({ "", "\Uffffffff", "\0", "\177", "\377", "\U7fffffff" }))
+
// test large searches (find string, size, pattern) define(test_search,[[ test_eq(sprintf($1+"%'"+$3+"'*n",$2)[..strlen($1)-1],$1) test_eq(search(sprintf($1+"%'"+$3+"'*n",$2),$1),0) test_eq(search(sprintf("%'"+$3+"'*n" ,$2),$1),-1) test_eq(search(sprintf("%'"+$3+"'*n"+$1,$2),$1),$2) test_eq(search(sprintf("%'"+$3+"'*n"+$1+"%'"+$3+"'*n",$2,$2),$1),$2) ]]) define(test_search2,[[dnl
pike.git/src/testsuite.in:5684:
test_search3($1,($1[..strlen($1)-3])) test_search3($1,($1[1..])) ]]) dnl some m4's don't handle 8 bit characters... test_search4("SUNE") test_search4("kapit\344l>") test_search4("-------------------+") test_search4("\345-------------------") test_search4(sprintf("%'argel-bargel glop-glyf?'2000n"))
-
-
dnl these can be uncommented when sprintf handles wide strings
+
test_search4("\34567-------------------") test_search4("\345677777-------------------") test_search4("kapit\3333l>") test_search4("kapit\3333333l>")
-
+
// - rusage
+
test_true(
+
#pike 7.4
+
arrayp(rusage()))
+
test_true(
+
#pike 7.4
+
sizeof(rusage())>28)
-
// -
sprintf
-
test
_
eq(sprintf("%.1f",31415.9267),"31415.9")
-
test_eq(sprintf("%.0f",31415.9267),"31416")
-
test_eq(sprintf("%.
-
1f",31415.9267),"31420")
-
test
_
eq(sprintf("%.-2f",31415.9267),"31400")
-
test
_
eq(sprintf("%.-2f",-31415.9267),"-31400")
-
test_eq(sprintf("%.
-
10f",31415.9267),"0")
-
test_eq(sprintf("%20.
-
3f",
31415.92670),"
31000")
-
test_eq(sprintf("%t",
({"a"})),
"array")
-
test_any([[array(string)
a
= ({"a"}); return sprintf("%t", a);]], "array")
-
test_eq(sprintf("%t",
0),
"int")
-
test_any([[array(string)
a
= 0; return sprintf("%t", a);]], "int")
+
// -
set
_
priority
+
//
-
set
_
weak
_
flag
+
//
-
setegid
+
//
-
seteuid
+
//
-
setgid
+
//
-
setgrent
+
//
-
setgroups
+
//
-
setpgrp
+
//
-
setpwent
+
//
-
setresgid
+
//
-
setresuid
+
//
-
setsid
+
//
-
setuid
-
+
// - sgn
+
// Tested in _math
+
+
// - signal
+
// - signame
+
// - signum
+
+
// - sin
+
// Tested in _math
+
// - sizeof test_eq(sizeof("felbar"),6) test_eq(sizeof(({"fulbar","gazonk",7})),3) test_eq(sizeof(([8:3,6:6,7:0])),3) test_eq(sizeof((<8,7,6,5,4,7>)),6)
-
+
test_eq([[ sizeof( class { int _sizeof() { return 17; } }() ) ]], 17)
// - sleep test_do(sleep(1)) test_do(sleep(0.5)) test_any([[int x=time(); sleep(2); return x!=time()]],1) test_any([[int x=time(); sleep(2); return x!=time()]],1)
-
+
// - sort
+
test_equal(sort(({1,3,2,4})),({1,2,3,4}))
+
test_equal(sort(({4,3,2,1})),({1,2,3,4}))
+
test_equal([[lambda() {array(int) a=({1,2,3,4}); sort(({4,3,2,1}),a); return a; }()]],[[({4,3,2,1})]] )
+
test_equal([[lambda() {array(int) a=({1,2,3,4}), b=a+({}); sort(({4,3,2,1}),a,b); return b; }()]],[[({4,3,2,1})]] )
+
test_equal([[sort("a,A,å,Å,ä,*A,[A"/",")]],[["*A,A,[A,a,Å,ä,å"/","]])
+
test_equal([[sort(sprintf("%c",enumerate(256)[*]))]],
+
[[sprintf("%c",enumerate(256)[*])]])
+
test_equal([[sort(sprintf("%c",enumerate(1024)[*]))]],
+
[[sprintf("%c",enumerate(1024)[*])]])
+
test_equal(sort(({})),({}))
+
test_equal(sort(({1.0,2.0,4.0,3.0})),({1.0,2.0,3.0,4.0}))
+
test_any_equal([[
+
// sort() on one arg should be stable.
+
class C (int id) {int `< (mixed x) {return 0;}};
+
return sort (({C(2), C(6), C(1), C(4), C(3), C(5)}))->id;
+
]], ({2, 6, 1, 4, 3, 5}))
+
test_any_equal([[
+
// sort() on several args should be stable.
+
array a = ({2, 6, 1, 4, 3, 5});
+
sort (({1, 1, 1, 1, 1, 1}), a);
+
return a;
+
]], ({2, 6, 1, 4, 3, 5}))
+
test_any_equal([[
+
// sort() on several args should be stable.
+
array a = ({2, 6, 1, 4, 3, 5});
+
sort (({1, 2, 1, 2, 1, 2}), a);
+
return a;
+
]], ({2, 1, 3, 6, 4, 5}))
+
test_any([[
+
class foo {
+
int x=random(100);
+
int `<(object o) {return x < o->x;}
+
};
+
array(object) o=allocate(100,foo)();
+
sort(o);
+
for(int e=1;e<100;e++)
+
if(o[e-1]->x > o[e]->x)
+
return e;
+
return -1;
+
]],-1)
+
test_equal(sort (({(<2>), (<1>)})), ({(<1>), (<2>)}))
+
test_any_equal([[
+
function pike_fun = lambda() {};
+
function c_fun = sleep;
+
return ({equal (sort (({pike_fun, pike_fun})), ({pike_fun, pike_fun})),
+
equal (sort (({c_fun, c_fun})), ({c_fun, c_fun})),
+
equal (sort (({pike_fun, c_fun})), ({pike_fun, c_fun})),
+
equal (sort (({c_fun, pike_fun})), ({pike_fun, c_fun}))});
+
]], [[({1, 1, 1, 1})]])
+
+
dnl missing tests for objects, arrays, multisets and mappings
+
+
// - sprintf
+
// Tested in sprintf
+
+
// - sqrt
+
// Tested in _math
+
+
// - strerror
+
test_true(stringp(strerror(0)))
+
test_true(stringp(strerror(1)))
+
test_true(stringp(strerror(-1)))
+
// - string_to_unicode, unicode_to_string
-
+
test_eq(string_to_unicode(""), "")
test_eq(string_to_unicode("foo"), "\0f\0o\0o") test_eq(string_to_unicode("blä"), "\0b\0l\0ä") test_eq(string_to_unicode("\77077"), "\176\77") test_eq(string_to_unicode("\777077"), "\330\277\336\77")
-
// Enable when unicode
_to_
string
()
understands surrogates.
-
dnl
test_eq(unicode_to_string("
\330\277\336\77
"), "
\777077
")
-
// Disable when
unicode_to_string()
understands surrogates.
-
test_eq(unicode_to_string("\330\277\336\77"), "
\154277\157077
")
+
test
_
eq(string_
to_
unicode
(
"\777077foo\77077\777077blä\777077"
)
,
"\330\277\336\77\0f\0o\0o\176\77\330\277\336\77\0b\0l\0ä\330\277\336\77")
+
test_eq(unicode_to_string(""), "")
+
test_eq(
unicode_to_string(
"\330\277\336\77\0f\0o\0o\176\77\330\277\336\77\0b\0l\0ä\330\277\336\77"
)
,
"\777077foo\77077\777077blä\777077")
+
test_eq(unicode_to_string("\330\277\336\77"), "
\777077
")
test_eq(unicode_to_string("\176\77"), "\77077") test_eq(unicode_to_string("\0b\0l\0ä"), "blä") test_eq(unicode_to_string("\0f\0o\0o"), "foo")
-
+
test_eq(unicode_to_string("\xfe\xff\330\277\336\77\0f\0o\0o\176\77\330\277\336\77\0b\0l\0ä\330\277\336\77"), "\777077foo\77077\777077blä\777077")
+
test_eq(unicode_to_string("\xfe\xff\330\277\336\77"), "\777077")
+
test_eq(unicode_to_string("\xfe\xff\176\77"), "\77077")
+
test_eq(unicode_to_string("\xfe\xff\0b\0l\0ä"), "blä")
+
test_eq(unicode_to_string("\xfe\xff\0f\0o\0o"), "foo")
+
test_eq(unicode_to_string("\xff\xfe\277\330\77\336f\0o\0o\0\77\176\277\330\77\336b\0l\0ä\0\277\330\77\336"), "\777077foo\77077\777077blä\777077")
+
test_eq(unicode_to_string("\xff\xfe\277\330\77\336"), "\777077")
+
test_eq(unicode_to_string("\xff\xfe\77\176"), "\77077")
+
test_eq(unicode_to_string("\xff\xfe""b\0l\0ä\0"), "blä")
+
test_eq(unicode_to_string("\xff\xfe""f\0o\0o\0"), "foo")
test_eval_error(return string_to_unicode("\7077077"))
-
+
test_eval_error(return string_to_unicode("\xffff\x10000"))
+
test_eval_error(return unicode_to_string(" "))
// - string_to_utf8, utf8_to_string test_eq(string_to_utf8("foo"), "foo") test_eq(string_to_utf8("blä"), "bl\303\244") test_eq(string_to_utf8("\77077"), "\347\270\277")
-
test_eq(string_to_utf8("\7077077"), "\367\207\270\277")
-
test_eq(string_to_utf8("\77077077"), "\370\277\207\270\277")
-
test_eq(string_to_utf8("\7077077077"), "\374\270\277\207\270\277")
-
test_eq(string_to_utf8("\77077077077", 1), "\376\203\270\277\207\270\277")
-
test_eq(utf8_to_string("\376\203\270\277\207\270\277", 1), "\77077077077")
-
test_eq(utf8_to_string("\374\270\277\207\270\277"), "\7077077077")
-
test_eq(utf8_to_string("\370\277\207\270\277"), "\77077077")
-
test_eq(utf8_to_string("\367\207\270\277"), "\7077077")
+
test_eq(string_to_utf8("\7077077"
, 1
), "\367\207\270\277")
+
test_eq(string_to_utf8("\77077077"
, 1
), "\370\277\207\270\277")
+
test_eq(string_to_utf8("\7077077077"
, 1
), "\374\270\277\207\270\277")
+
+
// 077077077077 has 33 bits unsigned. The escape sequence parser used
+
// to silently truncate too long char values, but not anymore.
+
dnl
test_eq(string_to_utf8("\77077077077", 1), "\376\203\270\277\207\270\277")
+
dnl
test_eq(utf8_to_string("\376\203\270\277\207\270\277", 1), "\77077077077")
+
// The following uses the char that actually got tested.
+
test_eq(
string_to_
utf8
("\37077077077", 1), "\376\203\270\277\207\270\277")
+
test
_
eq(utf8_
to_string("
\376\203\270\277\207\270\277", 1), "\37077077077")
+
+
test_eq(utf8_to_string("
\374\270\277\207\270\277"
, 1
), "\7077077077")
+
test_eq(utf8_to_string("\370\277\207\270\277"
, 1
), "\77077077")
+
test_eq(utf8_to_string("\367\207\270\277"
, 1
), "\7077077")
test_eq(utf8_to_string("\347\270\277"), "\77077") test_eq(utf8_to_string("bl\303\244"), "blä") test_eq(utf8_to_string("foo"), "foo") test_eval_error(return string_to_utf8("\77077077077")) test_eval_error(return utf8_to_string("\376\203\270\277\207\270\277")) test_eval_error(return utf8_to_string("\277")); test_eval_error(return utf8_to_string("\377")); test_eval_error(return utf8_to_string("\376\203\270\277\207\270", 1)); test_eval_error(return utf8_to_string("\374\270\277\207\270"));
pike.git/src/testsuite.in:5765:
test_eval_error(return utf8_to_string("\367\207\270")); test_eval_error(return utf8_to_string("\347\270")); test_eval_error(return utf8_to_string("\303")); test_eval_error(return utf8_to_string("\376\203\270\277\207\270a")); test_eval_error(return utf8_to_string("\374\270\277\207\270a")); test_eval_error(return utf8_to_string("\370\277\207\270a")); test_eval_error(return utf8_to_string("\367\207\270a")); test_eval_error(return utf8_to_string("\347\270a")); test_eval_error(return utf8_to_string("\303a"));
-
//
-
sum
-
test_eq(
`+
(
1,1
),
2
)
-
test_eq(
`+
(1,
-2
),
-
1)
-
test_eq(
`+
(
-2,-2
),
-4
)
-
test_eq(
`+
("
hi
","
there
"),"
hithere
")
+
//
Invalid
ranges
+
test_eq(
string_to_utf8
(
"\ud7ff"
),
"\u00ed\u009f\u00bf"
)
+
test_
eval_error(return string_to_utf8 ("\ud800"))
+
test_
eq(
string_to_utf8
(
"\ud800",
1
)
,
"\u00ed\u00a0\u0080"
)
+
test_eq(string_to_utf8 ("\udfff"
,
1)
, "\u00ed\u00bf\u00bf")
+
test_
eval_error(return string_to_utf8 ("\udfff"))
+
test_
eq(
string_to_utf8
(
"\ue000"
),
"\u00ee\u0080\u0080"
)
+
test_eq(
string_to_utf8
("
\U0010ffff
"
)
,
"
\u00f4\u008f\u00bf\u00bf
")
+
test_eval_error(return string_to_utf8 ("\U00110000"))
+
test_eq(string_to_utf8 ("\U00110000"
,
1),
"
\u00f4\u0090\u0080\u0080
")
-
test_eq(
`+
("
hi\777
","
there
"),"
hi\777there
")
-
test_eq(
`+
("
hi
","
there\777
"),"
hithere\777
")
+
test_eq(
utf8_to_string
("
\u00ed\u009f\u00bf
"
)
,
"
\ud7ff
")
+
test_eval_error(return utf8_to_string ("\u00ed\u00a0\u0080"))
+
test_eq(utf8_to_string ("\u00ed\u00a0\u0080"
,
1),
"
\ud800
")
+
test_eq(
utf8_to_string
("
\u00ed\u00bf\u00bf
",
1),
"
\udfff
")
+
test_eval_error(return utf8_to_string ("\u00ed\u00bf\u00bf"))
+
test_eq(utf8_to_string ("\u00ee\u0080\u0080")
,
"
\ue000
")
+
test_eq(utf8_to_string ("\u00f4\u008f\u00bf\u00bf"), "\U0010ffff")
+
test_eval_error(return utf8_to_string ("\u00f4\u0090\u0080\u0080"))
+
test_eq(utf8_to_string ("\u00f4\u0090\u0080\u0080", 1), "\U00110000")
+
test_eval_error(return utf8_to_string ("\u00f8\u0088\u0080\u0080\u0080"))
+
test_eval_error(return utf8_to_string ("\u00fc\u0084\u0080\u0080\u0080\u0080"))
+
test_eval_error(return utf8_to_string ("\u00fe\u0082\u0080\u0080\u0080\u0080\u0080"))
+
test_eq(utf8_to_string ("\u00fe\u0083\u00bf\u00bf\u00bf\u00bf\u00bf", 1), "\Uffffffff")
+
test_eval_error(return utf8_to_string ("\u00fe\u0084\u0080\u0080\u0080\u0080\u0080", 1))
+
test_eval_error(return utf8_to_string ("\u00ff"))
+
test_eval_error(return utf8_to_string ("\u00ff", 1))
-
test_eq(
`+
("
hi\7777777
","
there
"),"
hi\7777777there
")
-
test_eq(
`+
("
hi
","
there\7777777
"),"
hithere\7777777
")
+
// Non-shortest forms
+
test_
eval_error(return utf8_to_string ("\u00c0\u0080"))
+
test_eval_error(return utf8_to_string ("\u00c1\u00bf"))
+
test_
eq(
utf8_to_string
("
\u00c2\u0080
"
)
,
"
\u0080
")
+
test_eval_error(return utf8_to_string ("\u00e0\u0080\u0080"))
+
test_eval_error(return utf8_to_string ("\u00e0\u009f\u00bf"))
+
test_eq(utf8_to_string ("\u00e0\u00a0\u0080")
,
"
\u0800
")
)
+
test_
eval_error(return utf8_to_string ("\u00f0\u0080\u0080\u0080"))
+
test_eval_error(return utf8_to_string ("\u00f0\u008f\u00bf\u00bf"))
+
test_
eq(
utf8_to_string
("
\u00f0\u0090\u0080\u0080
"
)
,
"
\U00010000
")
+
test_eval_error(return utf8_to_string ("\u00f8\u0080\u0080\u0080\u0080"
,
1))
+
test_eval_error(return utf8_to_string (
"
\u00f8\u0087\u00bf\u00bf\u00bf
"
, 1
)
)
+
test_eq(utf8_to_string ("\u00f8\u0088\u0080\u0080\u0080", 1), "\U00200000")
+
test_eval_error(return utf8_to_string ("\u00fc\u0080\u0080\u0080\u0080\u0080", 1))
+
test_eval_error(return utf8_to_string ("\u00fc\u0083\u00bf\u00bf\u00bf\u00bf", 1))
+
test_eq(utf8_to_string ("\u00fc\u0084\u0080\u0080\u0080\u0080", 1), "\U04000000")
+
test_eval_error(return utf8_to_string ("\u00fe\u0080\u0080\u0080\u0080\u0080\u0080", 1))
+
test_eval_error(return utf8_to_string ("\u00fe\u0081\u00bf\u00bf\u00bf\u00bf\u00bf", 1))
+
test_eq(utf8_to_string ("\u00fe\u0082\u0080\u0080\u0080\u0080\u0080", 1), "\U80000000")
-
test_eq(`+("human","number",666),"humannumber666")
-
test_eq(`+("human","number",666),"humannumber666")
-
test_eq(`+("human","number",666),"humannumber666")
-
test_eq(`+("human","number",666,111),"humannumber666111")
-
test_eq(`+("humannumber",`+(666+111)),"humannumber777")
-
test_eq(`+("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","x","y"),"abcdefghijklmnopqrstuvxy")
-
test_eq(`+(1.0+1.0),2.0)
-
test_eq(`+(1.0,
-
1.0),0.0)
-
test_eq(`+(-1.0,-1.0),-2.0)
-
test_equal(`+(({1,2,3}),({4,5,6})),({1,2,3,4,5,6}))
-
test_equal(`+((<1,2,3,4>),(<4,5,6>)),(<1,2,3,4,4,5,6>))
-
test_equal(`+(([0:1,3:6]),([5:2,3:6])),([0:1,3:6,3:6,5:2]))
+
//
-
stringp
+
// Tested in foop
-
test_
any
(
return((1+2+3)-(1+2-3))
,
6
)
+
// - strlen
+
test_
eq
(
strlen
,
sizeof
)
-
// - this_object
+
// -
symlink
+
// - syslog
+
+
// - tan
+
// Tested in _math
+
+
// -
this_object
and this
test_true(objectp(this_object()))
-
+
test_true(objectp(this))
+
test_true(objectp(global::this))
+
test_true(this_object() == this)
+
test_true([[typeof(this) == typeof(this_object())]])
+
test_true([[typeof(this) == typeof(global::this)]])
+
test_true([[typeof(this_program) == typeof(object_program(this_object()))]])
+
test_true([[typeof(this_program) == typeof(object_program(global::this))]])
-
//
-
throw
-
test
_
eq
(
20,catch
(
throw
(a())))
+
test_program_eq([[
+
string _sprintf() {return "g";}
+
class A {
+
string
_
sprintf
(
) {return "A";}
+
class B {
+
string _sprintf
(
) {return "B";}
+
mixed f
(
) {
+
return sprintf ("%O%O%O%O%O",
+
global::this, A::this, B::this, this_program::this, this);
+
}
+
}
+
}
+
string
a()
{return A(
)
->B(
)
->f(
)
;}
+
]], "gABBB")
-
// - catch compile-errors
-
test_
any
([[
master
()
->set
_
inhibit_compile_errors
(
lambda(
)
{})
;
mixed
res
=
catch{compile_
string("
dfasfqw123
"
)
;}
;master
()
->set
_
inhibit
_
compile
_
errors
(0);
return
arrayp
(
res
)
;
]],
1
)
+
test_
program_eq
([[
+
string _sprintf
()
{return "g";}
+
class A {
+
string
_
sprintf
()
{return "A"
;
}
+
class B {
+
string
_
sprintf
(
) {return
"
B
";}
+
mixed f
()
{
+
return sprintf ("%O%O%O%O",
+
this
_
object (2), this
_
object (1), this
_
object
(0)
, this_object())
;
+
}
+
}
+
}
+
string a
()
{return A()->B()->f()
;
}
+
]],
"gABB"
)
-
// catch
-
test_
false
([[class
X
{ string
test
(string
foo
) {
catch
{ return
lower
_
case
(
foo
); }
;
return
foo
;
}}
()->
test
(
0
);
]])
+
test_
program_eq
([[
+
string _sprintf() {return "g";}
+
class
A
{
+
string
_sprintf
(
) {return "A";}
+
class B {
+
string
_sprintf(
)
{return "B";}
+
mixed f()
{
+
return map (({2, 1, 0}), lambda (int l)
{
+
return
sprintf ("%O", this
_
object
(
l
)
)
;
+
}
)
*
""
;
+
}
+
}
+
}
+
string a
()
{return A()
->
B
()
->f()
;
}
+
]]
, "gAB"
)
-
+
test_program_eq([[
+
string _sprintf() {return "g";}
+
class A {
+
string _sprintf() {return "A";}
+
class B {
+
string _sprintf() {return "B";}
+
mixed f() {
+
return sprintf ("%O%O%O%O%O",
+
global::this, A::this, B::this, this_program::this, this);
+
}
+
}
+
constant this = 7;
+
}
+
string a() {return A()->B()->f();}
+
]], "g7BB7")
+
+
test_compile_error([[
+
this = 17;
+
]])
+
+
test_compile_error([[
+
class A {
+
class B {
+
void f() {A::this = 17;}
+
}
+
};
+
]])
+
+
test_any([[
+
class A {
+
class B {
+
A parent() {return A::this;}
+
}
+
};
+
A a = A();
+
A.B b = a->B();
+
destruct (a);
+
return zero_type (b->parent());
+
]], 2)
+
+
test_eval_error([[
+
class A {
+
class B {
+
class C {
+
A grandparent() {return A::this;}
+
}
+
}
+
};
+
A.B b = A()->B();
+
A.B.C c = b->C();
+
destruct (b);
+
b->grandparent();
+
]], 2)
+
+
test_program_eq([[
+
string _sprintf() {return "g";}
+
class A {
+
string _sprintf() {return "A";}
+
mixed f() {
+
return sprintf ("%O%O", global::this, A::this);
+
}
+
}
+
class B {
+
string _sprintf() {return "B";}
+
class C {
+
inherit A;
+
string _sprintf() {return "C";}
+
mixed f() {
+
return A::f() + sprintf ("%O%O%O%O",
+
global::this, B::this, this_program::this, this);
+
}
+
}
+
}
+
string a() {return B()->C()->f();}
+
]], "gCgBCC")
+
+
test_program_eq([[
+
string _sprintf() {return "g";}
+
class A {
+
string _sprintf() {return "A";}
+
mixed f() {
+
return sprintf ("%O%O%O%O",
+
global::this, A::this, this_program::this, this);
+
}
+
}
+
class B {
+
string _sprintf() {return "B";}
+
class C {
+
inherit A;
+
string _sprintf() {return "C";}
+
mixed f() {
+
return A::f() + "|" +
+
sprintf ("%O%O%O%O%O",
+
global::this, B::this, C::this, this_program::this, this);
+
}
+
}
+
}
+
string a() {return B()->C()->f();}
+
]], "gCCC|gBCCC")
+
+
test_program([[
+
class A {
+
class B {
+
mixed f() {
+
return typeof (A::this) != typeof (B::this);
+
}
+
}
+
}
+
int a() {return A()->B()->f();}
+
]])
+
+
test_program([[
+
class A {
+
class B {
+
mixed f() {
+
return typeof (this_object (1)) != typeof (this_object (0));
+
}
+
}
+
}
+
int a() {return A()->B()->f();}
+
]])
+
+
test_program([[
+
class A {
+
class B {
+
mixed f() {
+
return typeof (A::this_program) != typeof (B::this_program);
+
}
+
}
+
}
+
int a() {return A()->B()->f();}
+
]])
+
+
test_program_eq([[
+
object ao = compile_string(#"
+
string id() {return \"A\";}
+
class B {
+
string id() {return \"B\";}
+
string foo()
+
{
+
return this->id() + id() + local::id() + global::this->id() + global::id();
+
}
+
}")();
+
+
class Handler
+
{
+
mixed resolv (string id, void|string file, void|object handler)
+
{
+
if (id == "B") return ao->B;
+
return master()->resolv (id, file, handler);
+
}
+
}
+
+
string a()
+
{
+
object c = compile_string(#"
+
string id() {return \"C\";}
+
class D {
+
inherit B;
+
string id() {return \"D\";}
+
string foo()
+
{
+
return ::foo() + \"|\" +
+
this->id() + id() + B::id() + global::this->id() + global::id();
+
}
+
}", 0, Handler())();
+
+
return c->D()->foo();
+
}
+
]], "DDBAA|DDBCC")
+
+
test_program_eq([[
+
class X
+
{
+
object parent() {return global::this;}
+
}
+
+
class Handler
+
{
+
mixed resolv (string id, void|string file, void|object handler)
+
{
+
if (id == "X") return X;
+
return master()->resolv (id, file, handler);
+
}
+
}
+
+
object a()
+
{
+
object o = compile_string ("inherit X;", 0, Handler())();
+
return o->parent();
+
}
+
]], this_object())
+
+
+
// - this_thread
+
// - thread_create
+
// - thread_local
+
+
// - throw
+
test_eq(20,catch(throw(a())))
+
// - time test_true(time()) test_true(time(1)) test_true(intp(time())) test_true(intp(time(1))) test_true(floatp(time(2)))
-
+
// gethrtime() may gethrtime(), RDTSC or gettimeofday
+
// sleep uses a combination of select/poll and the above
+
// time() uses gettimeofday
+
test_any([[
+
float tts=2.0;
+
+
int t0=time();
+
float t1=time(t0);
+
int hrt1=gethrtime();
+
sleep(tts);
+
int hrt2=gethrtime();
+
float t2=time(t0);
+
+
float e=(hrt2-hrt1)*1e-6;
+
float f=t2-t1;
+
+
array r=({});
+
if (e<tts-0.1 || e>tts+0.1)
+
r+=({sprintf("hrtime %.6f, %+.6f",e,e-tts)});
+
+
if (f<tts-0.1 || f>tts+0.1)
+
r+=({sprintf("timeofday %.6f, %+.6f",f,f-tts)});
+
+
if (sizeof(r)) return r*" / ";
+
return "no error";
+
]],"no error")
+
// - trace test_do(trace(0)) test_eq(trace(0),0)
-
+
// - ualarm
+
+
// - umask
+
test_true(intp(System.umask()))
+
test_eq(System.umask(System.umask()),System.umask())
+
+
// - uname
+
test_true(mappingp(uname()))
+
+
// - unicode_to_string
+
// See string_to_unicode
+
// - upper_case test_equal(upper_case("fooq"),"FOOQ") test_equal(upper_case("FooR"),"FOOR") test_equal(upper_case("Foo1234-*~\n"),"FOO1234-*~\n") test_equal(upper_case("fooq\x3000"),"FOOQ\x3000") test_equal(upper_case("FooR\x3000"),"FOOR\x3000") test_equal(upper_case("Foo1234-*~\n\x3000"),"FOO1234-*~\n\x3000") test_equal(upper_case("fooq\x13000"),"FOOQ\x13000") test_equal(upper_case("FooR\x13000"),"FOOR\x13000") test_equal(upper_case("Foo1234-*~\n\x13000"),"FOO1234-*~\n\x13000") test_equal(upper_case("Foo\xff"),"FOO\x178") test_equal(upper_case("Foo\xb5"),"FOO\x39c") test_equal(upper_case((string) ({
-
+
// These characters correspond to the cases in case_info.h
+
// Please update this and the corresponding lower_case table
+
// when UnicodeData.txt is changed.
+
// Part 1: 0x0000 - 0x0FFF
0x0000, 0x0041, 0x005b, 0x0061, 0x007b, 0x00b5, 0x00b6, 0x00c0, 0x00d7, 0x00d8, 0x00df, 0x00e0, 0x00f7, 0x00f8, 0x00ff, 0x0100, 0x0130, 0x0131, 0x0132, 0x0138, 0x0139, 0x0149, 0x014a, 0x0178, 0x0179, 0x017f, 0x0180, 0x0181, 0x0182, 0x0186, 0x0187, 0x0189, 0x018b, 0x018d, 0x018e, 0x018f, 0x0190, 0x0191, 0x0193, 0x0194,
-
0x0195, 0x0196, 0x0197, 0x0198, 0x019a, 0x019c, 0x019d, 0x019e,
-
0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01aa, 0x01ac, 0x01ae,
-
0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01ba, 0x01bc, 0x01be,
-
0x01bf, 0x01c0, 0x01c4, 0x01c5, 0x01c7, 0x01c8, 0x01ca, 0x01cb,
-
0x01dd, 0x01de, 0x01f0, 0x01f1, 0x01f2, 0x01f6, 0x01f7, 0x01f8,
-
0x0250
,
0x0253
,
0x0254
,
0x0255
,
0x0256
,
0x0258
,
0x0259
,
0x025a,
-
0x025b
,
0x025c
,
0x0260
,
0x0261
,
0x0263
,
0x0264
,
0x0268
,
0x0269
,
-
0x026a
,
0x026f
,
0x0270
,
0x0272
,
0x0273
,
0x0275
,
0x0276
,
0x0280
,
-
0x0281
,
0x0283
,
0x0284
,
0x0288
,
0x0289
,
0x028a
,
0x028c
,
0x0292
,
-
0x0293
,
0x0345
,
0x0346
,
0x0386
,
0x0387
,
0x0388
,
0x038c
,
0x038e
,
-
0x0390
,
0x0391
,
0x03a0
,
0x03ac
,
0x03ad
,
0x03b0
,
0x03b1
,
0x03c0
,
-
0x03c2
,
0x03c3
,
0x03cc
,
0x03cd
,
0x03d0
,
0x03d1
,
0x03d2
,
0x03d5
,
-
0x03d6
,
0x03d7
,
0x03da
,
0x03f0
,
0x03f1
,
0x03f2
,
0x03f3
,
0x0400
,
-
0x0410
,
0x0420
,
0x0430
,
0x0440
,
0x0450
,
0x0460
,
0x0482
,
0x048c
,
-
0x04c0
,
0x04c1
,
0x04d0
,
0x0531
,
0x0559
,
0x0561
,
0x0587
,
0x1e00
,
-
0x1e96
,
0x1e9b
,
0x1ea0
,
0x1f00
,
0x1f08
,
0x1f10
,
0x1f18
,
0x1f20
,
-
0x1f28
,
0x1f30
,
0x1f38
,
0x1f40
,
0x1f48
,
0x1f50
,
0x1f51
,
0x1f52
,
-
0x1f53
,
0x1f54
,
0x1f55
,
0x1f56
,
0x1f57
,
0x1f59
,
0x1f60
,
0x1f68
,
-
0x1f70
,
0x1f72
,
0x1f76
,
0x1f78
,
0x1f7a
,
0x1f7c
,
0x1f80
,
0x1f88
,
-
0x1f90
,
0x1f98
,
0x1fa0
,
0x1fa8
,
0x1fb0
,
0x1fb2
,
0x1fb3
,
0x1fb4
,
-
0x1fb8
,
0x1fba
,
0x1fbc
,
0x1fbd
,
0x1fbe
,
0x1fbf,
0x1fc3, 0x1fc4,
-
0x1fc8, 0x1fcc, 0x1fcd, 0x1fd0, 0x1fd2, 0x1fd8, 0x1fda, 0x1fdd,
-
0x1fe0, 0x1fe2, 0x1fe5, 0x1fe6, 0x1fe8, 0x1fea, 0x1fec, 0x1fed,
-
0x1ff3, 0x1ff4, 0x1ff8, 0x1ffa, 0x1ffc, 0x1ffd, 0x2126, 0x2127,
-
0x212a, 0x212b, 0x212c, 0x2160, 0x2180, 0x24b6, 0x24d0, 0x24ea,
-
0xff21, 0xff3b, 0xff41, 0xff5b
})),
(string) ({
+
0x0195, 0x0196, 0x0197, 0x0198, 0x019a,
0x019b,
0x019c, 0x019d,
+
0x019e, 0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01aa, 0x01ac,
+
0x01ae, 0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01ba, 0x01bc,
+
0x01be, 0x01bf, 0x01c0, 0x01c4, 0x01c5, 0x01c7, 0x01c8, 0x01ca,
+
0x01cb, 0x01dd, 0x01de, 0x01f0, 0x01f1, 0x01f2, 0x01f6, 0x01f7,
+
0x01f8,
0x0220
,
0x0221
,
0x0222
,
0x0234
,
0x023a
,
0x023b
,
0x023d
,
+
0x023e
,
0x023f
,
0x0241
,
0x0243
,
0x0244
,
0x0245
,
0x0246
,
0x0250
,
+
0x0251
,
0x0252
,
0x0253
,
0x0254
,
0x0255
,
0x0256
,
0x0258
,
0x0259
,
+
0x025a
,
0x025b
,
0x025c
,
0x0260
,
0x0261
,
0x0263
,
0x0264
,
0x0265
,
+
0x0266
,
0x0267
,
0x0268
,
0x0269
,
0x026a
,
0x026b
,
0x026c
,
0x026f
,
+
0x0270
,
0x0271
,
0x0272
,
0x0273
,
0x0275
,
0x0276
,
0x027d
,
0x027e
,
+
0x0280
,
0x0281
,
0x0283
,
0x0284
,
0x0288
,
0x0289
,
0x028a
,
0x028c
,
+
0x028d
,
0x0292
,
0x0293
,
0x0345
,
0x0346
,
0x0370
,
0x0374
,
0x0376
,
+
0x0378
,
0x037b
,
0x037e
,
0x0386
,
0x0387
,
0x0388
,
0x038b
,
0x038c
,
+
0x038d
,
0x038e
,
0x0390
,
0x0391
,
0x03a0
,
0x03a2
,
0x03a3
,
0x03ac
,
+
0x03ad
,
0x03b0
,
0x03b1
,
0x03c0
,
0x03c2
,
0x03c3
,
0x03cc
,
0x03cd
,
+
0x03cf
,
0x03d0
,
0x03d1
,
0x03d2
,
0x03d5
,
0x03d6
,
0x03d7
,
0x03d8
,
+
0x03f0
,
0x03f1
,
0x03f2
,
0x03f3
,
0x03f4
,
0x03f5
,
0x03f6
,
0x03f7
,
+
0x03f9
,
0x03fa
,
0x03fc
,
0x03fd
,
0x0400
,
0x0410
,
0x0420
,
0x0430
,
+
0x0440
,
0x0450
,
0x0460
,
0x0482
,
0x048a
,
0x04c0
,
0x04c1
,
0x04cf
,
+
0x04d0
,
0x0528
,
0x0531
,
0x0557
,
0x0561
,
0x0587
})),
+
(string) ({
0x0000, 0x0041, 0x005b, 0x0041, 0x007b, 0x039c, 0x00b6, 0x00c0, 0x00d7, 0x00d8, 0x00df, 0x00c0, 0x00f7, 0x00d8, 0x0178, 0x0100, 0x0130, 0x0049, 0x0132, 0x0138, 0x0139, 0x0149, 0x014a, 0x0178,
-
0x0179, 0x0053,
0x0180
, 0x0181, 0x0182, 0x0186, 0x0187, 0x0189,
+
0x0179, 0x0053,
0x0243
, 0x0181, 0x0182, 0x0186, 0x0187, 0x0189,
0x018b, 0x018d, 0x018e, 0x018f, 0x0190, 0x0191, 0x0193, 0x0194,
-
0x01f6, 0x0196, 0x0197, 0x0198,
0x019a
, 0x019c, 0x019d,
0x019e
,
-
0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01aa, 0x01ac, 0x01ae,
-
0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01ba, 0x01bc, 0x01be,
-
0x01f7, 0x01c0, 0x01c4, 0x01c5, 0x01c7, 0x01c8, 0x01ca, 0x01cb,
-
0x018e, 0x01de, 0x01f0, 0x01f1, 0x01f2, 0x01f6, 0x01f7, 0x01f8,
-
0x0250
, 0x0181, 0x0186, 0x0255, 0x0189, 0x0258, 0x018f, 0x025a,
-
0x0190, 0x025c, 0x0193, 0x0261, 0x0194, 0x0264, 0x0197, 0x0196,
-
0x026a, 0x019c, 0x0270, 0x019d, 0x0273, 0x019f, 0x0276,
0x01a6
,
-
0x0281, 0x01a9, 0x0284, 0x01ae,
0x0289
, 0x01b1,
0x028c
, 0x01b7,
-
0x0293, 0x0399, 0x0346, 0x0386, 0x0387, 0x0388, 0x038c, 0x038e,
-
0x0390, 0x0391, 0x03a0, 0x0386, 0x0388, 0x03b0, 0x0391, 0x03a0,
-
0x03a3, 0x03a3, 0x038c, 0x038e, 0x0392, 0x0398, 0x03d2, 0x03a6,
-
0x03a0,
0x03d7
,
0x03da
, 0x039a, 0x03a1,
0x03a3
, 0x03f3,
0x0400
,
-
0x0410, 0x0420, 0x0410, 0x0420, 0x0400, 0x0460, 0x0482,
0x048c
,
-
0x04c0, 0x04c1, 0x04d0, 0x0531,
0x0559
, 0x0531, 0x0587, 0x1e00,
-
0x1e96, 0x1e60, 0x1ea0, 0x1f08, 0x1f08, 0x1f18, 0x1f18, 0x1f28,
-
0x1f28, 0x1f38, 0x1f38, 0x1f48, 0x1f48,
0x1f50
, 0x1f59, 0x1f52,
-
0x1f5b, 0x1f54, 0x1f5d, 0x1f56, 0x1f5f, 0x1f59, 0x1f68, 0x1f68,
-
0x1fba, 0x1fc8, 0x1fda, 0x1ff8, 0x1fea, 0x1ffa,
0x1f88
, 0x1f88,
-
0x1f98, 0x1f98, 0x1fa8, 0x1fa8, 0x1fb8, 0x1fb2, 0x1fbc, 0x1fb4,
-
0x1fb8, 0x1fba, 0x1fbc, 0x1fbd, 0x0399, 0x1fbf, 0x1fcc, 0x1fc4,
-
0x1fc8, 0x1fcc, 0x1fcd, 0x1fd8, 0x1fd2, 0x1fd8, 0x1fda,
0x1fdd
,
-
0x1fe8, 0x1fe2, 0x1fec, 0x1fe6, 0x1fe8, 0x1fea, 0x1fec, 0x1fed,
-
0x1ffc, 0x1ff4, 0x1ff8, 0x1ffa, 0x1ffc, 0x1ffd, 0x2126, 0x2127,
-
0x212a, 0x212b, 0x212c, 0x2160, 0x2180, 0x24b6, 0x24b6, 0x24ea,
-
0xff21, 0xff3b, 0xff21, 0xff5b }))
+
0x01f6, 0x0196, 0x0197, 0x0198,
0x023d
,
0x019b,
0x019c, 0x019d,
+
0x0220
, 0x019f, 0x01a0, 0x01a6, 0x01a7, 0x01a9, 0x01aa, 0x01ac,
+
0x01ae, 0x01af, 0x01b1, 0x01b3, 0x01b7, 0x01b8, 0x01ba, 0x01bc,
+
0x01be, 0x01f7, 0x01c0, 0x01c4, 0x01c5, 0x01c7, 0x01c8, 0x01ca,
+
0x01cb, 0x018e, 0x01de, 0x01f0, 0x01f1, 0x01f2, 0x01f6, 0x01f7,
+
0x01f8,
0x0220, 0x0221, 0x0222, 0x0234, 0x023a, 0x023b, 0x023d,
+
0x023e
,
0x2c7e, 0x0241, 0x0243, 0x0244, 0x0245, 0x0246, 0x2c6f,
+
0x2c6d, 0x2c70,
0x0181, 0x0186, 0x0255, 0x0189, 0x0258, 0x018f,
+
0x025a, 0x0190, 0x025c, 0x0193, 0x0261, 0x0194, 0x0264,
0xa78d,
+
0xa7aa, 0x0267,
0x0197, 0x0196, 0x026a,
0x2c62, 0x026c,
0x019c,
+
0x0270,
0x2c6e,
0x019d, 0x0273, 0x019f, 0x0276,
0x2c64, 0x027e,
+
0x01a6, 0x0281, 0x01a9, 0x0284, 0x01ae,
0x0244
, 0x01b1,
0x0245
,
+
0x028d,
0x01b7, 0x0293, 0x0399, 0x0346,
0x0370, 0x0374, 0x0376,
+
0x0378, 0x03fd, 0x037e,
0x0386, 0x0387, 0x0388,
0x038b,
0x038c,
+
0x038d,
0x038e, 0x0390, 0x0391, 0x03a0,
0x03a2, 0x03a3,
0x0386,
+
0x0388, 0x03b0, 0x0391, 0x03a0, 0x03a3, 0x03a3, 0x038c, 0x038e,
+
0x03cf,
0x0392, 0x0398, 0x03d2, 0x03a6, 0x03a0,
0x03cf
,
0x03d8
,
+
0x039a, 0x03a1,
0x03f9
, 0x03f3,
0x03f4, 0x0395, 0x03f6, 0x03f7,
+
0x03f9, 0x03fa, 0x03fc, 0x03fd,
0x0400, 0x0410, 0x0420, 0x0410,
+
0x0420, 0x0400, 0x0460, 0x0482,
0x048a
, 0x04c0, 0x04c1,
0x04c0,
+
0x04d0,
0x0528,
0x0531,
0x0557
, 0x0531, 0x0587
}))
+
test_equal(upper_case((string) ({
+
// These characters correspond to the cases in case_info.h
+
// Please update this and the corresponding lower_case table
+
// when UnicodeData.txt is changed.
+
// Part 2: 0x1000 -
+
0x10a0
,
0x10c6, 0x10c7, 0x10c8, 0x10cd, 0x10ce, 0x1d79, 0x1d7a,
+
0x1d7d, 0x1d7e,
0x1e00,
0x1e96, 0x1e9b, 0x1e9c, 0x1e9e, 0x1e9f,
+
0x1ea0, 0x1f00, 0x1f08, 0x1f10, 0x1f16, 0x1f18, 0x1f1e, 0x1f20,
+
0x1f28, 0x1f30, 0x1f38, 0x1f40, 0x1f46, 0x1f48, 0x1f4e, 0x1f51,
+
0x1f52, 0x1f53, 0x1f54, 0x1f55, 0x1f56, 0x1f57, 0x1f58, 0x1f59,
+
0x1f5a, 0x1f5b, 0x1f5c, 0x1f5d, 0x1f5e, 0x1f5f, 0x1f60, 0x1f68,
+
0x1f70, 0x1f72, 0x1f76, 0x1f78, 0x1f7a, 0x1f7c, 0x1f7e, 0x1f80,
+
0x1f88, 0x1f90, 0x1f98, 0x1fa0, 0x1fa8, 0x1fb0, 0x1fb2, 0x1fb3,
+
0x1fb4, 0x1fb8, 0x1fba, 0x1fbc, 0x1fbd, 0x1fbe, 0x1fbf, 0x1fc3,
+
0x1fc4, 0x1fc8, 0x1fcc, 0x1fcd, 0x1fd0, 0x1fd2, 0x1fd8, 0x1fda,
+
0x1fdc, 0x1fe0, 0x1fe2, 0x1fe5, 0x1fe6, 0x1fe8, 0x1fea, 0x1fec,
+
0x1fed, 0x1ff3, 0x1ff4, 0x1ff8, 0x1ffa, 0x1ffc, 0x1ffd, 0x2126,
+
0x2127, 0x212a, 0x212b, 0x212c, 0x2132, 0x2133, 0x214e, 0x214f,
+
0x2160, 0x2180, 0x2183, 0x2185, 0x24b6, 0x24d0, 0x24ea, 0x2c00,
+
0x2c2f, 0x2c30, 0x2c5f, 0x2c60, 0x2c62, 0x2c63, 0x2c64, 0x2c65,
+
0x2c66, 0x2c67, 0x2c6d, 0x2c6e, 0x2c6f, 0x2c70, 0x2c71, 0x2c72,
+
0x2c74, 0x2c75, 0x2c77, 0x2c7e, 0x2c80, 0x2ce4, 0x2ceb, 0x2cef,
+
0x2cf2, 0x2cf4, 0x2d00, 0x2d26, 0x2d27, 0x2d28, 0x2d2d, 0x2d2e,
+
0xa640, 0xa66e, 0xa680, 0xa698, 0xa722, 0xa730, 0xa732, 0xa770,
+
0xa779, 0xa77d, 0xa77e, 0xa788, 0xa78b, 0xa78d, 0xa78e, 0xa790,
+
0xa794, 0xa7a0, 0xa7aa, 0xa7ab, 0xff21, 0xff3b, 0xff41, 0xff5b,
+
0x10400, 0x10428, 0x10450 })),
+
(string) ({
+
0x10a0, 0x10c6, 0x10c7, 0x10c8, 0x10cd, 0x10ce, 0xa77d, 0x1d7a,
+
0x2c63, 0x1d7e, 0x1e00,
0x1e96, 0x1e60,
0x1e9c, 0x1e9e, 0x1e9f,
+
0x1ea0, 0x1f08, 0x1f08, 0x1f18,
0x1f16,
0x1f18,
0x1f1e,
0x1f28,
+
0x1f28, 0x1f38, 0x1f38, 0x1f48,
0x1f46,
0x1f48,
0x1f4e
, 0x1f59,
+
0x1f52, 0x1f5b, 0x1f54, 0x1f5d, 0x1f56, 0x1f5f,
0x1f58,
0x1f59,
+
0x1f5a, 0x1f5b, 0x1f5c, 0x1f5d, 0x1f5e, 0x1f5f,
0x1f68, 0x1f68,
+
0x1fba, 0x1fc8, 0x1fda, 0x1ff8, 0x1fea, 0x1ffa,
0x1f7e,
0x1f88,
+
0x1f88, 0x1f98, 0x1f98, 0x1fa8, 0x1fa8, 0x1fb8, 0x1fb2, 0x1fbc,
+
0x1fb4, 0x1fb8, 0x1fba, 0x1fbc, 0x1fbd, 0x0399, 0x1fbf, 0x1fcc,
+
0x1fc4, 0x1fc8, 0x1fcc, 0x1fcd, 0x1fd8, 0x1fd2, 0x1fd8, 0x1fda,
+
0x1fdc
, 0x1fe8, 0x1fe2, 0x1fec, 0x1fe6, 0x1fe8, 0x1fea, 0x1fec,
+
0x1fed, 0x1ffc, 0x1ff4, 0x1ff8, 0x1ffa, 0x1ffc, 0x1ffd, 0x2126,
+
0x2127, 0x212a, 0x212b, 0x212c,
0x2132, 0x2133, 0x2132, 0x214f,
+
0x2160, 0x2180,
0x2183, 0x2185,
0x24b6, 0x24b6, 0x24ea,
0x2c00,
+
0x2c2f, 0x2c00, 0x2c5f, 0x2c60, 0x2c62, 0x2c63, 0x2c64, 0x023a,
+
0x023e, 0x2c67, 0x2c6d, 0x2c6e, 0x2c6f, 0x2c70, 0x2c71, 0x2c72,
+
0x2c74, 0x2c75, 0x2c77, 0x2c7e, 0x2c80, 0x2ce4, 0x2ceb, 0x2cef,
+
0x2cf2, 0x2cf4, 0x10a0, 0x2d26, 0x10c7, 0x2d28, 0x10cd, 0x2d2e,
+
0xa640, 0xa66e, 0xa680, 0xa698, 0xa722, 0xa730, 0xa732, 0xa770,
+
0xa779, 0xa77d, 0xa77e, 0xa788, 0xa78b, 0xa78d, 0xa78e, 0xa790,
+
0xa794, 0xa7a0, 0xa7aa, 0xa7ab,
0xff21, 0xff3b, 0xff21, 0xff5b
,
+
0x10400,
0x10400, 0x10450
}))
-
+
// - utf8_to_string
+
// See string_to_utf8
-
+
// - utime
+
// - values test_equal(values("foo"),({'f','o','o'})) test_equal(values(({'f','o','o'})),({'f','o','o'})) test_equal(Array.sort_array(values(([7:3,8:9,99:12]))),({3,9,12})) test_equal(values((<7,8,99>)),({1,1,1})) test_equal(mkmultiset(values(class{ constant a="a"; constant b="b";}())), (<"a","b">))
-
+
// - version
+
test_equal(version(), "Pike v"+__REAL_MAJOR__+"."+__REAL_MINOR__+" release "+__REAL_BUILD__)
+
+
// - werror
+
// - write
+
// - zero_type test_eq(zero_type(0),0) test_eq(zero_type(([])[7]),1)
-
+
test_eq(zero_type(([7: 0])[7]),0)
+
test_eq(zero_type(([7: UNDEFINED])[7]),0)
+
test_eq(zero_type(UNDEFINED), 1)
+
test_eq(zero_type (m_delete (([]), 1)), 1)
-
+
test_eq(zero_type (allocate (5, UNDEFINED)[2]), 1);
+
test_eq(zero_type (allocate (5, 0)[2]), 0);
+
test_eq(zero_type (allocate (5)[2]), 0);
+
test_true([[lambda (int|void a) { return zero_type(a); }()]]) test_true([[lambda () {mixed a; return zero_type(a = ([])[0]);}()]]) test_true([[lambda () {mapping a=([]); return zero_type(a[0] = ([])[0]);}()]]) test_true([[zero_type (lambda () {return ([])[0];}())]])
-
+
test_any([[
+
class A {
+
int j = 0;
+
in