1169d92004-05-02Martin Nilsson START_MARKER
4f9a0a2002-09-21Martin Stjernholm  // This triggered a bug only if run sufficiently early.
e70eb22015-11-30Martin Nilsson test_compile_any([[#pike 7.6]])
3daf982014-02-17Martin Nilsson test_compile_any([[#pike 7.8]])
b8ce9d2014-08-24Martin Nilsson test_compile_any([[#pike 8.0]])
63c1a62014-10-05Martin Nilsson test_compile_any([[#pike 8.1]])
2144ac2014-11-24Martin Nilsson test_compile_any([[#pike 8.2]])
ab01ea1999-09-21Fredrik Hübinette (Hubbe) 
3236822015-11-15Martin Nilsson ifefun(_verify_internals,
c0988f1998-04-17Fredrik Hübinette (Hubbe) [[ test_do(_verify_internals())
3b74641999-11-24Henrik Grubbström (Grubba) ]]); test_eq(1e1,10.0); test_eq(1E1,10.0); test_eq(1e+1,10.0); test_eq(1.1e1,11.0); test_eq(1e-1,0.1); test_eq('\x20',32); test_eq("\x20","\040"); test_eq("\d32","\x20"); test_eq('Å',"Å"[0]); test_eq('\7777',"\7777"[0]); test_eq('\77777777',"\77777777"[0]); test_eq("\x10000","\x10000"); test_eq(0x80000000-0x80000000, 0); test_eq(0xf0000000-0xf0000000, 0); test_eq(0x80000001-0x80000000, 1); test_eq(0x80000000-0x80000001,-1); test_eq(-2147483648*-1, -2147483648/-1);
3e50212014-08-18Martin Nilsson 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);
3b74641999-11-24Henrik Grubbström (Grubba) test_true([[1.0e-40]]);
a83f8c1998-03-20Fredrik Hübinette (Hubbe) test_eq([[#"foo
3b74641999-11-24Henrik Grubbström (Grubba) bar"]],[["foo\nbar"]]);
170d582015-08-23Martin Nilsson test_eq([[# "foo bar"]],[["foo\nbar"]]);
b62bf62000-03-30Fredrik Hübinette (Hubbe) test_eq([[#"foo\ bar"]],[["foobar"]]);
e9e53e2015-07-07Henrik Grubbström (Grubba) test_eq([[#(foo
606f272015-07-26Henrik Grubbström (Grubba) bar#) - "\r"]],[["foo\nbar"]]);
170d582015-08-23Martin Nilsson test_eq([[# (foo bar#) - "\r"]],[["foo\nbar"]]);
e9e53e2015-07-07Henrik Grubbström (Grubba) test_eq([[#(foo\
606f272015-07-26Henrik Grubbström (Grubba) bar#) - "\r"]],[["foo\\\nbar"]]);
e9e53e2015-07-07Henrik Grubbström (Grubba) test_eq([[#[foo
606f272015-07-26Henrik Grubbström (Grubba) bar#] - "\r"]],[["foo\nbar"]]);
170d582015-08-23Martin Nilsson test_eq([[# [foo bar#] - "\r"]],[["foo\nbar"]]);
e9e53e2015-07-07Henrik Grubbström (Grubba) test_eq([[#[foo\
606f272015-07-26Henrik Grubbström (Grubba) bar#] - "\r"]],[["foo\\\nbar"]]);
e9e53e2015-07-07Henrik Grubbström (Grubba) test_eq([[#{foo
606f272015-07-26Henrik Grubbström (Grubba) bar#} - "\r"]],[["foo\nbar"]]);
170d582015-08-23Martin Nilsson test_eq([[# {foo bar#} - "\r"]],[["foo\nbar"]]);
e9e53e2015-07-07Henrik Grubbström (Grubba) test_eq([[#{foo\
606f272015-07-26Henrik Grubbström (Grubba) bar#} - "\r"]],[["foo\\\nbar"]]);
3b74641999-11-24Henrik Grubbström (Grubba) test_true([[stringp(#string "Makefile")]]);
3488ef2000-04-17Henrik Grubbström (Grubba) test_any([[class Bar { array(int) foo = ({}); }; class Foo { inherit Bar; array(int) foo = ({1}); }; return sizeof(Foo()->foo);]],1);
87c9d21998-04-09Fredrik Hübinette (Hubbe) 
649dce2008-05-21Martin Stjernholm test_eq([["(" + 0x7fffffff + ")"]], "(2147483647)") test_eq([["(" + -0x80000000 + ")"]], "(-2147483648)")
3e50212014-08-18Martin Nilsson test_eq([["(" + 0x7fffffffffffffff + ")"]], "(9223372036854775807)") test_eq([["(" + -0x8000000000000000 + ")"]], "(-9223372036854775808)")
649dce2008-05-21Martin Stjernholm test_eq([["(" + Int.NATIVE_MAX + ")"]], [[sprintf ("(%d)", Int.NATIVE_MAX)]]) test_eq([["(" + Int.NATIVE_MIN + ")"]], [[sprintf ("(%d)", Int.NATIVE_MIN)]])
3362ea2012-07-06Martin Stjernholm 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)]])
649dce2008-05-21Martin Stjernholm 
137eab2014-08-19Martin Nilsson test_any_equal([[ array res = ({}); array ops = ({ `+, `-, `*, `/, `%, `<<, `>>, `&, `|, `^ }); array nums_a = ({ 0, 1, -1, 0xffffffff, 0xffffffffffffffff }); array nums_b = ({ 0, 1, -1 }); foreach(ops;; function op) foreach(nums_a;; int a) foreach(nums_b;; int b) { mixed err = catch { res += ({ op(a,b) }); }; if( err ) res += ({ "E" }); } return res; ]],[[ ({ // + 0, 1, -1, 1, 2, 0, -1, 0, -2, 0xffffffff, 0x100000000, 0xfffffffe, 0xffffffffffffffff, 0x10000000000000000, 0xfffffffffffffffe, // - 0, -1, 1, 1, 0, 2, -1, -2, 0, 0xffffffff, 0xfffffffe, 0x100000000, 0xffffffffffffffff, 0xfffffffffffffffe, 0x10000000000000000, // * 0, 0, 0, 0, 1, -1, 0, -1, 1, 0, 0xffffffff, -0xffffffff, 0, 0xffffffffffffffff, -0xffffffffffffffff, // / "E", 0, 0, "E", 1, -1, "E", -1, 1, "E", 0xffffffff, -0xffffffff, "E", 0xffffffffffffffff, -0xffffffffffffffff, // % "E", 0, 0, "E", 0, 0, "E", 0, 0, "E", 0, 0, "E", 0, 0, // << 0, 0, "E", 1, 2, "E", -1, -2, "E", 0xffffffff, 0x1fffffffe, "E", 0xffffffffffffffff, 0x1fffffffffffffffe, "E", // >> 0, 0, "E", 1, 0, "E", -1, -1, "E", 0xffffffff, 0x7fffffff, "E", 0xffffffffffffffff, 0x7fffffffffffffff, "E", // & 0, 0, 0, 0, 1, 1, 0, 1, -1, 0, 1, 0xffffffff, 0, 1, 0xffffffffffffffff, // | 0, 1, -1, 1, 1, -1, -1, -1, -1, 0xffffffff, 0xffffffff, -1, 0xffffffffffffffff, 0xffffffffffffffff, -1, // ^ 0, 1, -1, 1, 0, -2, -1, -2, 0, 0xffffffff, 0xfffffffe, -0x100000000, 0xffffffffffffffff, 0xfffffffffffffffe, -0x10000000000000000, }) ]])
2166c02008-05-06Henrik Grubbström (Grubba) # __func__ test_eq(__func__, "a") test_eq("b", __func__)
3b74641999-11-24Henrik Grubbström (Grubba) test_eq(8, 0b1000); test_eq(-8, -0b1000); test_eq(16, 0b10000); test_eq(-16, -0b10000);
5656451999-10-26Fredrik Noring 
9262082003-02-26Martin Stjernholm test_true(1e-100000000000000000000000000000000000000000000000000000000000<=1e-10000)
6f35772003-02-26Mirar (Pontus Hagland) 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)
9262082003-02-26Martin Stjernholm test_true(1e10000<=1e100000000000000000000000000000000000000000000000000000000000)
6f35772003-02-26Mirar (Pontus Hagland) 
0346dc2014-05-10Martin Nilsson test_compile_error('\3434523423423523423423423423') test_compile_error("\3434523423423523423423423423") test_compile_error("\d109827346981234561823743412654")
9a90b32014-10-22Per Hedbor test_compile_error('\d109827346981234561823743412654')
0346dc2014-05-10Martin Nilsson test_compile_error("\x109a27bc69e256c83deaa34c26b4")
9a90b32014-10-22Per Hedbor test_compile_error('\x109a27bc69e256c83deaa34c26b4')
b168bb2004-11-01Martin Stjernholm test_compile_error('\u17fo')
0346dc2014-05-10Martin Nilsson test_compile_error("\u17fo")
9a90b32014-10-22Per Hedbor  test_eq('012456789abcdefghijklmnopqrstuvwxyz'->digits(256), "012456789abcdefghijklmnopqrstuvwxyz") test_eq('\uu117f', 0x5c7531313766)
aee0b52004-11-16Martin Stjernholm test_eq("\uuuu17fo", "\\uuu17fo")
b168bb2004-11-01Martin Stjernholm test_eq('\u117f', 0x117f) test_eq("\u117foo", "\10577oo") test_eq("\u1117foo", "\10427foo") test_eq("\uuuu117foo", "\\uuu117foo") test_compile_error('\U117f')
0346dc2014-05-10Martin Nilsson test_compile_error("\U117f") test_compile_error("\UdEaDbEaT")
aee0b52004-11-16Martin Stjernholm test_eq("\UUdEaDbEaT", "\\UdEaDbEaT")
b168bb2004-11-01Martin Stjernholm test_eq('\UDeaDBeEF', -559038737) test_eq("\UDeaDBeEFFF", "\33653337357FF") test_eq("\UUDeaDBeEFFF", "\\UDeaDBeEFFF")
e80a292002-02-28Martin Stjernholm test_do([[
bcc7d62002-04-12Martin Nilsson  // bug 2677
e80a292002-02-28Martin Stjernholm  int x; if (time()) x = 1; else foo: break foo; ]])
14dd022002-06-11Henrik Grubbström (Grubba) 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)
805ea62002-02-26Martin Stjernholm test_any([[ int f (int i) {i = 0; return i;}; return f (1); ]],0)
fa78922001-07-28Fredrik Hübinette (Hubbe) test_any([[
c209412002-11-13Henrik Grubbström (Grubba)  // 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.
daf6492002-11-14Henrik Grubbström (Grubba)  // This test forces F_COND_RECUR to fail.
c209412002-11-13Henrik Grubbström (Grubba)  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))) ); } };
fa78922001-07-28Fredrik Hübinette (Hubbe) 
daf6492002-11-14Henrik Grubbström (Grubba)  class Y { inherit X; int Ack(int M, int N) { return ::Ack(M, N); } };
fa78922001-07-28Fredrik Hübinette (Hubbe) 
c209412002-11-13Henrik Grubbström (Grubba)  return Y()->Ack(2,2);
fa78922001-07-28Fredrik Hübinette (Hubbe) ]],7)
20043f2008-07-17Henrik Grubbström (Grubba) 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)
ce9bfb2002-12-20Henrik Grubbström (Grubba) 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)
4ce36d2003-01-29Marcus Comstedt 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)
f88fda2003-03-21Johan Sundström 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)
07b70d2014-10-27Martin Nilsson test_any([[ for(int i; i<10; i++) ; return 1; ]], 1)
9002ef2004-04-29Martin Nilsson test_any([[ // Another over-optimization test. string x(string i) { return i; }; return x("")+1+1; ]], "11")
df23b92009-11-20Henrik Grubbström (Grubba) test_any([[
5dffec2015-12-27Martin Nilsson  /* don't save parent */
df23b92009-11-20Henrik Grubbström (Grubba)  // 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)
2045362011-03-28Henrik Grubbström (Grubba) test_any([[
5dffec2015-12-27Martin Nilsson  /* don't save parent */
df23b92009-11-20Henrik Grubbström (Grubba)  // Check that parent pointers aren't added unnecessarily [bug 2672]. class I {}; class X {
2045362011-03-28Henrik Grubbström (Grubba)  // 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.
df23b92009-11-20Henrik Grubbström (Grubba)  inherit I; I i = I(); }; X x = ((program) X)(); // Error: Parent lost, cannot clone program. return 0; ]], 0)
2045362011-03-28Henrik Grubbström (Grubba) 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 {
e680902015-03-22Henrik Grubbström (Grubba)  final constant const_val = 1;
2045362011-03-28Henrik Grubbström (Grubba)  class Bar { int func() {
e680902015-03-22Henrik Grubbström (Grubba)  // parent-pointer not needed, since const_val is final. return const_val;
2045362011-03-28Henrik Grubbström (Grubba)  }; } }; return !Foo.Bar; ]], 0)
f538022003-02-25Marcus Comstedt test_compile_any([[
13670c2015-05-25Martin Nilsson  mixed foo()
f538022003-02-25Marcus Comstedt  { Stdio.File bar(int x, int y)
13670c2015-05-25Martin Nilsson  {
f538022003-02-25Marcus Comstedt  return 0;
1615822008-01-04Henrik Grubbström (Grubba)  }; return bar;
13670c2015-05-25Martin Nilsson  }
f538022003-02-25Marcus Comstedt ]])
7a84422003-10-10Martin Stjernholm 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; } ]])
c691162016-04-25Henrik Grubbström (Grubba) test_compile_any([[ mixed foo() { array a; array b = a->f("b")?->b; return b; } ]])
1273162014-07-02Arne Goedeke define(test_string_range,[[ test_any([[ string s = (string) ({ $1, $1 }); if (!arrayp(String.range(s))) return "huh?"; // dont optimize this, it forces string range check return search(s, $1); ]], 0) ]]) test_string_range(254); test_string_range(255); test_string_range((1<<16)-1); test_string_range((1<<16)+1); test_string_range((1<<29)-1); test_string_range((1<<29)+1); test_string_range((1<<31)-1); test_string_range(-(1<<31));
2fa1222006-03-01Henrik Grubbström (Grubba) dnl number of variables/scope, number of scopes, expect_compiler_error define(test_scopes,[[
887c592006-03-01Henrik Grubbström (Grubba)  test_any([[
50ab1c2010-07-12Martin Stjernholm  log_status("Testing scoped variables $1:$2%s...", $3?" expecting a compilation error":"");
887c592006-03-01Henrik Grubbström (Grubba)  string line = sprintf("#line %d %O\n", __LINE__, __FILE__);
2fa1222006-03-01Henrik Grubbström (Grubba)  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;
d553522007-06-18Martin Stjernholm  if ($3) master()->set_inhibit_compile_errors (1);
2fa1222006-03-01Henrik Grubbström (Grubba)  mixed err = catch { p = compile_string("int a() {\n" + line + (s * $2) + " return 0;\n" "}\n"); }; if ($3) {
d553522007-06-18Martin Stjernholm  master()->set_inhibit_compile_errors (0);
2fa1222006-03-01Henrik Grubbström (Grubba)  if (err) return 0; error("Expected a compilation error for $1 variables in $2 scope%s.\n", ($2>1)?"s":""); } if (err) throw(err);
887c592006-03-01Henrik Grubbström (Grubba)  return p()->a(); ]], 0) ]])
2fa1222006-03-01Henrik Grubbström (Grubba) test_scopes(255, 1, 0) test_scopes(256, 1, 1) test_scopes(16, 17, 0) test_scopes(17, 16, 0)
4ce36d2003-01-29Marcus Comstedt 
078c602006-03-02Henrik Grubbström (Grubba) test_any([[ // LysLysKOM 14180500 if (1) { string var = "Reinitialization error."; } sscanf("", "%d", int zero); return zero; ]], 0);
414ab92006-03-04Henrik Grubbström (Grubba) 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)
ae0ac12002-11-14Henrik Grubbström (Grubba) dnl FIXME: Add test that local and local:: in combination dnl with recursion works correctly.
3b74641999-11-24Henrik Grubbström (Grubba) test_eval_error([[mixed x; return mkmapping(x,x)]]);
97431e1999-03-19Fredrik Hübinette (Hubbe) 
3488ef2000-04-17Henrik Grubbström (Grubba) test_eval_error([[class Foo { void bar() {}
f960bd2015-07-31Martin Nilsson  void foo() {destruct(this);bar();}
3488ef2000-04-17Henrik Grubbström (Grubba) }; Foo()->foo(); ]])
7ddaa32000-08-22Martin Stjernholm test_do([[ void foo (int i) { multiset res = (<>); if (i) res = res; }; foo (1); ]])
5e44422001-02-25Fredrik Hübinette (Hubbe) test_any([[ array tmp=({}); tmp=({([])})+tmp; tmp->foo=7; tmp=({([])})+tmp; return sizeof(tmp[0]); ]], 0)
52032c2008-05-12Henrik Grubbström (Grubba) test_any([[ // Bug 4537. void fiddle(array(int) a) { a += ({ 2 }); }; array(int) a = ({ 1 }); fiddle(a); return sizeof(a); ]], 1)
5e44422001-02-25Fredrik Hübinette (Hubbe) 
774f9a2011-03-21Martin Stjernholm test_eval_error([[ // [Bug 5911] class X { string s; }; X()->s = (mixed) X(); ]])
b0dfbb2011-09-04Martin Nilsson 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)
6c98ca2011-09-05Henrik Grubbström (Grubba) 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")
6bf0fa2011-09-12Henrik Grubbström (Grubba) test_any([[ // bug 6065 class A(string s) {}; class B(string s) { inherit A; }; return B("foo")->s; ]], "foo")
49a00f2018-02-02Henrik Grubbström (Grubba) test_any_equal([[ class A{ constant sym = 1; } class B{ constant sym = 2; inherit A; } return indices(B); ]], ({ "sym" })) test_any_equal([[ class A{ constant sym = 1; } class B{ inherit A; constant sym = 2; } return indices(B); ]], ({ "sym" })) test_any_equal([[ class A{ constant sym = 1; } class B{ constant sym = 2; inherit A; } return values(B); ]], ({ 2 })) test_any_equal([[ class A{ constant sym = 1; } class B{ inherit A; constant sym = 2; } return values(B); ]], ({ 2 })) test_any_equal([[ class A{ constant sym = 1; } class B{ constant sym = 2; inherit A; } return indices(B()); ]], ({ "sym" })) test_any_equal([[ class A{ constant sym = 1; } class B{ inherit A; constant sym = 2; } return indices(B()); ]], ({ "sym" })) test_any_equal([[ class A{ constant sym = 1; } class B{ constant sym = 2; inherit A; } return values(B()); ]], ({ 2 })) test_any_equal([[ class A{ constant sym = 1; } class B{ inherit A; constant sym = 2; } return values(B()); ]], ({ 2 }))
fdd6a82008-10-13Mirar (Pontus Hagland) dnl bug in for loop optimization in combination with += test_any([[
13670c2015-05-25Martin Nilsson 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; } }
fdd6a82008-10-13Mirar (Pontus Hagland)  return sizeof(v); // if buggy, will be 6 and not 140 ]], 140); test_any([[
13670c2015-05-25Martin Nilsson 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; } }
fdd6a82008-10-13Mirar (Pontus Hagland)  return sizeof(v); // not buggy, will be 140 ]], 140);
3b74641999-11-24Henrik Grubbström (Grubba) 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);
2b2df21999-11-01Henrik Grubbström (Grubba)  test_any([[ int a=0xffffffff; return a/17 ]],
3b74641999-11-24Henrik Grubbström (Grubba)  [[ (0xffffffff == -1)?-1:0x0f0f0f0f ]]);
2b2df21999-11-01Henrik Grubbström (Grubba) test_any([[ int a=0xffffffff; return a%17 ]],
3b74641999-11-24Henrik Grubbström (Grubba)  [[ (0xffffffff == -1)?16:0 ]]);
2b2df21999-11-01Henrik Grubbström (Grubba) test_any([[ int a=0xffffffff; return a>>17 ]],
3b74641999-11-24Henrik Grubbström (Grubba)  [[ (0xffffffff == -1)?-1:0x7fff ]]);
f61d772013-12-12Henrik Grubbström (Grubba) dnl Check the derived return type of sprintf(). test_any([[return sprintf("%O", typeof(sprintf("%1H", "foo"))); ]],
a2f2422014-01-05Henrik Grubbström (Grubba)  "string(8bit)");
f61d772013-12-12Henrik Grubbström (Grubba) test_any([[return sprintf("%O", typeof(sprintf("foo"))); ]], "string(102..111)"); test_any([[return sprintf("%O", typeof(sprintf("foo%c", 17))); ]], "string(17..17 | 102..111)"); test_any([[return sprintf("%O", typeof(sprintf("%2c\n", 'a'))); ]],
a2f2422014-01-05Henrik Grubbström (Grubba)  "string(8bit)");
8b2dd42014-08-31Henrik Grubbström (Grubba) dnl Note the following tests the return type of int2char().
f61d772013-12-12Henrik Grubbström (Grubba) test_any([[return sprintf("%O", typeof(sprintf("%c", 1023))); ]], "string(1023..1023)"); test_any([[return sprintf("%O", typeof(sprintf("%c\n", 1023))); ]], "string(10..10 | 1023..1023)");
8b2dd42014-08-31Henrik Grubbström (Grubba) dnl The following is due to (string & sprintf_result) == sprintf_result.
f61d772013-12-12Henrik Grubbström (Grubba) test_any([[return sprintf("%O", typeof(sprintf("%c\n", Stdio))); ]],
8b2dd42014-08-31Henrik Grubbström (Grubba)  sprintf("%O", sprintf_result));
f61d772013-12-12Henrik Grubbström (Grubba) test_any([[return sprintf("%O", typeof(sprintf("%4[1]c", 17))); ]],
a2f2422014-01-05Henrik Grubbström (Grubba)  "string(8bit)");
f61d772013-12-12Henrik Grubbström (Grubba) test_any([[return sprintf("%O", typeof(sprintf("%[1]n", 17))); ]], "string(zero)");
b347262013-06-03Martin Nilsson test_any([[return sprintf("%O", typeof(aggregate("foo")));]], "array(string(102..111))");
4405922000-05-25Henrik Grubbström (Grubba) test_any([[int a; return sprintf("%O", typeof(aggregate(a)));]], "array(int)");
3b74641999-11-24Henrik Grubbström (Grubba) test_any([[int|string a;
4405922000-05-25Henrik Grubbström (Grubba)  string s = sprintf("%O", typeof(aggregate(a)));
3b30c92007-04-03Henrik Grubbström (Grubba)  return (< "array(string) | array(int)", "array(string | int)", "array(int | string)" >)[s];]], 1);
4405922000-05-25Henrik Grubbström (Grubba) test_any([[return sprintf("%O", typeof(aggregate()));]], "array(zero)");
1954be1999-12-10Henrik Grubbström (Grubba) test_any([[int i; return (< "int", "int | zero", "zero | int" >)
4405922000-05-25Henrik Grubbström (Grubba)  [sprintf("%O", typeof(max(i,0)))];]], 1)
3b74641999-11-24Henrik Grubbström (Grubba) 
4405922000-05-25Henrik Grubbström (Grubba) test_any([[array(string) a; return sprintf("%O", typeof(a[0])); ]], "string")
3b74641999-11-24Henrik Grubbström (Grubba)  test_any([[class foo { string a; }; object(foo) bar;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(bar->a));]], "string");
3b74641999-11-24Henrik Grubbström (Grubba)  test_any([[class foo { string a; }; array(object(foo)) bar;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(bar[0]->a));]], "string");
94b5241999-11-01Mirar (Pontus Hagland) 
4405922000-05-25Henrik Grubbström (Grubba) test_any([[function(:string)|function(int:int) f; return sprintf("%O", typeof(f())); ]],
f2e6a41999-11-24Henrik Grubbström (Grubba)  "string")
4405922000-05-25Henrik Grubbström (Grubba) test_any([[function(:string)|function(int:int) f; return sprintf("%O", typeof(f(1))); ]],
f2e6a41999-11-24Henrik Grubbström (Grubba)  "int")
dc19e71999-11-24Henrik Grubbström (Grubba) test_any([[function(:string)|function(mixed, mixed...:int) f;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(f())); ]],
dc19e71999-11-24Henrik Grubbström (Grubba)  "string") test_any([[function(:string)|function(mixed, mixed ...:int) f;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(f(1))); ]],
dc19e71999-11-24Henrik Grubbström (Grubba)  "int")
00091b1999-12-05Martin Stjernholm test_any([[mapping(object:string)|mapping(string:int) f;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(f[class{}()])); ]],
00091b1999-12-05Martin Stjernholm  "string") test_any([[mapping(object:string)|mapping(string:int) f;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(f[""])); ]],
00091b1999-12-05Martin Stjernholm  "int") test_any([[mapping(object:string)|mapping(string:int) f;
4405922000-05-25Henrik Grubbström (Grubba)  return sort((sprintf("%O", typeof(f[0])) - " ")/"|")*"|"; ]],
00091b1999-12-05Martin Stjernholm  "int|string")
4d7b181999-12-07Fredrik Hübinette (Hubbe) test_any([[class Foo { string `[](mixed y) {return "";} };
b6733a1999-12-05Henrik Grubbström (Grubba)  object(Foo) foo;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(foo[0])); ]],
b6733a1999-12-05Henrik Grubbström (Grubba)  "string")
f600911999-12-05Henrik Grubbström (Grubba) test_any([[class Foo { array(int) _indices() {return ({0});} };
b6733a1999-12-05Henrik Grubbström (Grubba)  object(Foo) foo;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(indices(foo))); ]],
f600911999-12-05Henrik Grubbström (Grubba)  "array(int)")
b6733a1999-12-05Henrik Grubbström (Grubba)  test_any([[class Foo { array(string) _values() {return ({""});} }; object(Foo) foo;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(values(foo))); ]],
b6733a1999-12-05Henrik Grubbström (Grubba)  "array(string)")
ffb7fe1999-12-08Henrik Grubbström (Grubba) test_any([[mapping(string:int) foo; array(string) bar;
4405922000-05-25Henrik Grubbström (Grubba)  return sprintf("%O", typeof(rows(foo, bar))); ]],
ffb7fe1999-12-08Henrik Grubbström (Grubba)  "array(int)")
c494422016-01-04Per Hedbor // basic auto tests. test_any([[ class Toplevel { class Foo { auto a = 10; auto b = typeof(a); }; string test() {
300d022016-11-05Martin Nilsson  return sprintf("a%Ob%O", typeof(Foo()->a),typeof(Foo()->b));
c494422016-01-04Per Hedbor  }; }; return Toplevel()->test(); ]], "aint(10..10)btype(int(10..10))"); test_any([[{ class Toplevel { class Foo { auto test(){ return 10;return 20;return 30; }; }; string test() {
300d022016-11-05Martin Nilsson  return sprintf("%O", typeof(Foo()->test));
c494422016-01-04Per Hedbor  } }; return Toplevel()->test()-" "; }]], "function(:int(10..10)|int(20..20)|int(30..30))");
85ff732001-07-03Martin Stjernholm test_any([[{ class Foo { mixed m;
537f1e2001-07-03Henrik Grubbström (Grubba)  };
85ff732001-07-03Martin Stjernholm  class Bar { inherit Foo; string m; Foo b;
537f1e2001-07-03Henrik Grubbström (Grubba)  mixed f() { return typeof(b->m); } };
f704a22001-07-03Henrik Grubbström (Grubba)  Foo c; Bar d;
537f1e2001-07-03Henrik Grubbström (Grubba)  return sprintf("%O$%O$%O$%O", Bar()->f(), typeof(c->m), typeof(d->m), typeof(d->b->m));
f704a22001-07-03Henrik Grubbström (Grubba) }]], "mixed$mixed$string$mixed")
85ff732001-07-03Martin Stjernholm 
32efc92003-03-07Henrik Grubbström (Grubba) // 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){
0b8d2f2013-06-17Martin Nilsson  return Charset.decoder("utf-8")->feed(s)->drain();
32efc92003-03-07Henrik Grubbström (Grubba)  })) ]], [[ "function(string : string)" ]])
9d3a7a2005-02-18Henrik Grubbström (Grubba) // Test implicit lambda. test_eq([[ `()(){ return 1; } ]], 1)
cc8b3b2017-11-02Henrik Grubbström (Grubba) test_equal([[ lambda(array a, function f) { return f(@a); } (({ 0, 1, 2, 3 })){ return __ARGS__; } ]], ({ 0, 1, 2, 3}))
d967202004-02-28Martin Stjernholm // Argument checking
bed4582012-07-12Henrik Grubbström (Grubba) // Test new_check_call.
c287ef2012-07-18Henrik Grubbström (Grubba) test_any([[
bed4582012-07-12Henrik Grubbström (Grubba)  constant foo = 5; // Test that it survives a F_ARG_LIST with CAR == CDR. return foo%foo; ]], 0)
d967202004-02-28Martin Stjernholm // 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"); ]])
ac1e892009-03-11Marcus Comstedt // Check that write() and error() with one argument are not // incorrectly subjected to sprintf() argument test_compile([[write("%\u2323");]]) test_compile([[error("%\u2323");]])
5bcd222001-02-21Mirar (Pontus Hagland) // type checks define(test_type_error, [[ test_compile_error([[ $1 x; x=$3; ]])
6b3f5c2002-04-11Martin Nilsson  test_compile_error_any([[ class ErrBa { $1 x() { return $3; } } ]]) test_compile_error_any([[ class ErrBa { $1 x() { $2 a=$3; return a; } } ]])
5bcd222001-02-21Mirar (Pontus Hagland) ]]) 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; })
f960bd2015-07-31Martin Nilsson test_type_error(int,program,this_program) test_type_error(int,object,this)
5bcd222001-02-21Mirar (Pontus Hagland)  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; })
f960bd2015-07-31Martin Nilsson test_type_error(float,program,this_program) test_type_error(float,object,this)
5bcd222001-02-21Mirar (Pontus Hagland)  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; })
f960bd2015-07-31Martin Nilsson test_type_error(array,program,this_program) test_type_error(array,object,this)
5bcd222001-02-21Mirar (Pontus Hagland)  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; })
f960bd2015-07-31Martin Nilsson test_type_error(mapping,program,this_program) test_type_error(mapping,object,this)
5bcd222001-02-21Mirar (Pontus Hagland)  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; })
f960bd2015-07-31Martin Nilsson test_type_error(multiset,program,this_program) test_type_error(multiset,object,this)
5bcd222001-02-21Mirar (Pontus Hagland)  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>))
b5ca842009-06-22Henrik Grubbström (Grubba) 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)))
b8efef2008-09-12Henrik Grubbström (Grubba) // Check that complex function types survive soft casting to function.
a4cf892008-09-12Henrik Grubbström (Grubba) ignore_warning("Soft cast of scope(0