d6b78d | 2004-05-02 | Martin Nilsson | |
START_MARKER
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | dnl - Concurrent
test_do([[
class AsyncResult {
mixed result = UNDEFINED;
int state;
void failure(mixed val)
{
if (state) error("Multiple results.\n");
state = -1;
result = val;
}
void success(mixed val)
{
if (state) error("Multiple results.\n");
state = 1;
result = val;
}
mixed get_result(int expected)
{
mixed res = (state == expected) && result;
state = 0;
result = UNDEFINED;
return res;
}
};
add_constant("AsyncResult", AsyncResult());
]])
define(init_promise, [[
test_do([[
Concurrent.Promise p = Concurrent.Promise();
add_constant("promise", p);
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | add_constant("future", p->future());
]])
]])
define(init_future, [[
test_do([[
future->on_success(AsyncResult.success);
future->on_failure(AsyncResult.failure);
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | ]])
]])
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | define(std_init_promise, [[
init_promise()
init_future()
]])
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | dnl expected_result_state, expected_result_value
define(exit_promise, [[
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | test_any_equal([[
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | while(Pike.DefaultBackend(0.0))
;
return AsyncResult->get_result($1);
]], $2)
]])
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - success()
std_init_promise()
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | test_do([[ promise->success(1); ]])
test_eval_error([[ promise->success(2); ]])
test_eval_error([[ promise->failure(3); ]])
test_do([[ promise->try_success(4); ]])
test_do([[ promise->try_success(5); ]])
exit_promise(1, 1)
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - failure()
std_init_promise()
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | test_do([[ promise->failure(6); ]])
test_eval_error([[ promise->success(7); ]])
test_eval_error([[ promise->failure(8); ]])
test_do([[ promise->try_success(9); ]])
test_do([[ promise->try_success(10); ]])
exit_promise(-1, 6)
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - try_success()
std_init_promise()
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | test_do([[ promise->try_success(11); ]])
test_eval_error([[ promise->success(12); ]])
test_eval_error([[ promise->failure(13); ]])
test_do([[ promise->try_success(14); ]])
test_do([[ promise->try_success(15); ]])
exit_promise(1, 11)
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - try_failure()
std_init_promise()
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | test_do([[ promise->try_failure(16); ]])
test_eval_error([[ promise->success(17); ]])
test_eval_error([[ promise->failure(18); ]])
test_do([[ promise->try_success(19); ]])
test_do([[ promise->try_success(20); ]])
exit_promise(-1, 16)
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - Late adding of callbacks.
init_promise()
test_do([[ promise->success(21); ]])
test_eval_error([[ promise->success(22); ]])
test_eval_error([[ promise->failure(23); ]])
test_do([[ promise->try_success(24); ]])
test_do([[ promise->try_success(25); ]])
exit_promise(0, 0)
init_future()
exit_promise(1, 21)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | | dnl - TODO: Future()->get().
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - map()
init_promise()
test_do([[ add_constant("future", future->map(`+, 100)); ]])
init_future()
test_do([[ promise->success(17); ]])
exit_promise(1, 117)
|
d9c418 | 2017-12-04 | Stephen R. van den Berg | | dnl - map_with()
init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("future", future->map_with(
lambda(int resp) {
p11->success(resp + 11);
return p11->future();
})); ]])
test_do([[ add_constant("future", future->recover_with(
lambda(int resp) {
p11->success(resp + 12);
return p11->future();
})); ]])
init_future()
test_do([[ promise->success(10); ]])
test_do([[ add_constant("p11"); ]])
exit_promise(1, 21)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - recover()
init_promise()
test_do([[ add_constant("future", future->recover(`+, 12)); ]])
init_future()
test_do([[ promise->failure(10); ]])
exit_promise(1, 22)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | | dnl - recover_with()
|
d9c418 | 2017-12-04 | Stephen R. van den Berg | | init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("future", future->map_with(
lambda(int resp) {
p11->success(resp + 11);
return p11->future();
})); ]])
test_do([[ add_constant("future", future->recover_with(
lambda(int resp) {
p11->success(resp + 12);
return p11->future();
})); ]])
init_future()
test_do([[ promise->failure(10); ]])
test_do([[ add_constant("p11"); ]])
exit_promise(1, 22)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | dnl - filter() - true
init_promise()
test_do([[ add_constant("future", future->filter(`&, 1)); ]])
init_future()
test_do([[ promise->success(11); ]])
exit_promise(1, 11)
dnl - filter() - false
init_promise()
test_do([[ add_constant("future", future->filter(`&, 1)); ]])
init_future()
test_do([[ promise->success(10); ]])
exit_promise(-1, UNDEFINED)
dnl - transform() - true
init_promise()
test_do([[ add_constant("future", future->transform(`+, `-, 100)); ]])
init_future()
test_do([[ promise->success(1); ]])
exit_promise(1, 101)
dnl - transform() - false
init_promise()
test_do([[ add_constant("future", future->transform(`+, `-, 100)); ]])
init_future()
test_do([[ promise->failure(1); ]])
exit_promise(1, -99)
dnl - transform() - exception
init_promise()
test_do([[ add_constant("future", future->transform(`+, throw)); ]])
init_future()
test_do([[ promise->failure(1); ]])
exit_promise(-1, 1)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | | dnl - transform_with()
dnl - zip()
|
30697c | 2017-12-04 | Stephen R. van den Berg | | init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ p12->success(12); ]])
test_do([[ promise->success(14); ]])
test_do([[ add_constant("future",
promise->future()->zip(p11, p12, p13)); ]])
init_future()
test_do([[ p13->success(13); ]])
test_do([[ p11->success(11); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, ({14, 11, 12, 13}))
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | dnl - Promise.depend() - true
init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
promise->depend(({p11->future(),p12->future()}))
->depend(({}))->depend(p13->future())
->depend(({p13->future(),p11->future(),p12->future()}))); ]])
test_do([[ promise->depend()->success(14); ]])
test_do([[ p13->success(13); ]])
|
584556 | 2017-11-26 | Stephen R. van den Berg | | test_do([[ promise->depend()->success(15); ]])
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | init_future()
test_do([[ p11->success(11); ]])
test_do([[ p12->success(12); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, ({11, 12, 13, 13, 11, 12, 14, 15}))
|
30697c | 2017-12-04 | Stephen R. van den Berg | | dnl - Promise.depend() no backend - true
init_promise()
test_do([[ Concurrent.use_backend(0); ]]);
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
promise->depend(({p11->future(),p12->future()}))
->depend(({}))->depend(p13->future())
->depend(({p13->future(),p11->future(),p12->future()}))); ]])
test_do([[ promise->depend()->success(14); ]])
test_do([[ p13->success(13); ]])
test_do([[ promise->depend()->success(15); ]])
init_future()
test_do([[ p11->success(11); ]])
test_do([[ p12->success(12); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, ({11, 12, 13, 13, 11, 12, 14, 15}))
test_do([[ Concurrent.use_backend(1); ]]);
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | dnl - Promise.depend() - false
init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
promise->depend(({p11->future(),p12->future()}))
->depend(({}))->depend(p13->future())
->depend(({p13->future(),p11->future(),p12->future()}))); ]])
test_do([[ promise->depend()->success(14); ]])
test_do([[ p11->success(11); ]])
|
584556 | 2017-11-26 | Stephen R. van den Berg | | test_do([[ promise->depend()->success(15); ]])
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | init_future()
test_do([[ p13->failure(13); ]])
test_do([[ p12->failure(12); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(-1, 13)
|
30697c | 2017-12-04 | Stephen R. van den Berg | | dnl - Promise.depend() no backend - false
init_promise()
test_do([[ Concurrent.use_backend(0); ]]);
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
promise->depend(({p11->future(),p12->future()}))
->depend(({}))->depend(p13->future())
->depend(({p13->future(),p11->future(),p12->future()}))); ]])
test_do([[ promise->depend()->success(14); ]])
test_do([[ p11->success(11); ]])
test_do([[ promise->depend()->success(15); ]])
init_future()
test_do([[ p13->failure(13); ]])
test_do([[ p12->failure(12); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(-1, 13)
test_do([[ Concurrent.use_backend(1); ]]);
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | dnl - Promise.fold() - true
init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
|
584556 | 2017-11-26 | Stephen R. van den Berg | | promise->depend(({p11->future(),p12->future()}))
->depend(({}))->depend(p13->future())
->depend(({p13->future(),p11->future(),p12->future()}))); ]])
test_do([[ promise->depend()->success(14); ]])
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | test_do([[ p13->success(13); ]])
|
584556 | 2017-11-26 | Stephen R. van den Berg | | test_do([[ promise->depend()->success(15); ]])
test_do([[ promise->fold(10,
lambda(int val, int acc) { return val+acc; }); ]])
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | init_future()
test_do([[ p11->success(11); ]])
test_do([[ p12->success(12); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, 10 + 11 + 12 + 13 + 13 + 11 + 12 + 14 + 15)
dnl - Promise.fold() - false
init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
|
584556 | 2017-11-26 | Stephen R. van den Berg | | promise->depend(({p11->future(),p12->future()}))
->depend(({}))->depend(p13->future())
->depend(({p13->future(),p11->future(),p12->future()}))); ]])
test_do([[ promise->depend()->success(14); ]])
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | test_do([[ p13->success(13); ]])
|
584556 | 2017-11-26 | Stephen R. van den Berg | | test_do([[ promise->depend()->success(15); ]])
test_do([[ promise->fold(10,
lambda(int val, int acc) { return val+acc; }); ]])
|
5ff9ea | 2017-11-24 | Stephen R. van den Berg | | init_future()
test_do([[ p11->failure(11); ]])
test_do([[ p12->failure(12); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(-1, 11)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | | dnl - Concurrent.first_completed()
|
30697c | 2017-12-04 | Stephen R. van den Berg | | init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
Concurrent.first_completed(({p11, promise, p12, p13})
->future())); ]])
init_future()
test_do([[ p12->success(12); ]])
test_do([[ p13->success(13); ]])
test_do([[ promise->success(14); ]])
test_do([[ p11->success(11); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, 12)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
dnl - Concurrent.results()
|
30697c | 2017-12-04 | Stephen R. van den Berg | | init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
Concurrent.results(({p11, promise, p12, p13})
->future())); ]])
init_future()
test_do([[ p12->success(12); ]])
test_do([[ p13->success(13); ]])
test_do([[ promise->success(14); ]])
test_do([[ p11->success(11); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, ({11, 14, 12, 13}))
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
|
2f2c4e | 2018-04-09 | Martin Karlgren | | dnl - Concurrent.results() - empty
init_promise()
test_do([[ add_constant("future", Concurrent.results(({}))); ]])
init_future()
exit_promise(1, ({}))
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | | dnl - Concurrent.traverse()
|
30697c | 2017-12-04 | Stephen R. van den Berg | | init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
Concurrent.traverse(({p11, promise, p12, p13})
->future(), lambda(int val) { return val+val;})); ]])
init_future()
test_do([[ p12->success(12); ]])
test_do([[ p13->success(13); ]])
test_do([[ promise->success(14); ]])
test_do([[ p11->success(11); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, ({11+11, 14+14, 12+12, 13+13}))
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
dnl - Concurrent.fold()
|
30697c | 2017-12-04 | Stephen R. van den Berg | | init_promise()
test_do([[ add_constant("p11", Concurrent.Promise()); ]])
test_do([[ add_constant("p12", Concurrent.Promise()); ]])
test_do([[ add_constant("p13", Concurrent.Promise()); ]])
test_do([[ add_constant("future",
Concurrent.fold(({p11, promise, p12, p13})
->future(), 10, lambda(int val, int acc) { return val+acc;})); ]])
init_future()
test_do([[ p12->success(12); ]])
test_do([[ p13->success(13); ]])
test_do([[ promise->success(14); ]])
test_do([[ p11->success(11); ]])
test_do([[ add_constant("p11"); ]])
test_do([[ add_constant("p12"); ]])
test_do([[ add_constant("p13"); ]])
exit_promise(1, 10+11+14+12+13)
|
4f4e0c | 2016-11-01 | Henrik Grubbström (Grubba) | |
|
40c482 | 2016-10-28 | Henrik Grubbström (Grubba) | | test_do([[ add_constant("future"); ]])
|
3eb995 | 2016-10-27 | Henrik Grubbström (Grubba) | | test_do([[ add_constant("promise"); ]])
test_do([[ add_constant("AsyncResult"); ]])
|
af2eab | 2013-10-28 | Per Hedbor | | dnl - NetUtils
test_equal( NetUtils.string_to_ip( "0.0.0.0" ), 0 );
test_equal( NetUtils.string_to_ip( "255.0.0.0" ), 0xff000000 );
test_equal( NetUtils.string_to_ip( "0.255.0.0" ), 0x00ff0000 );
test_equal( NetUtils.string_to_ip( "255.255.255.255" ), 0xffffffff );
test_equal( NetUtils.string_to_ip( "65535.255.255" ), -1 );
test_equal( NetUtils.string_to_ip( "20.255.255" ), -1 );
test_equal( NetUtils.string_to_ip( "20...10" ), -1 );
test_equal( NetUtils.string_to_ip( "4.3.2.300" ), -1 );
test_equal( NetUtils.string_to_ip( "::255.0.0.0" ), 0xff000000);
test_equal( NetUtils.string_to_ip( "1::255.0.0.0" ), 5192296858534827628530500607410176);
test_equal( NetUtils.string_to_ip("2001:4c28:a030:30:219:99ff:fe6d:2eb4"),
42542032843807851754427830279823240884);
test_equal( NetUtils.string_to_ip("10293::"),-1);
test_equal( NetUtils.string_to_ip("fel::"),-1);
test_equal( NetUtils.ip_to_string( -1 ), 0 );
test_equal( NetUtils.ip_to_string( 0 ), "0.0.0.0" );
test_equal( NetUtils.ip_to_string( 0xff000000 ), "255.0.0.0" );
test_equal( NetUtils.ip_to_string( 0x00ff0000 ), "0.255.0.0" );
test_equal( NetUtils.ip_to_string( 0xffffffff ), "255.255.255.255" );
test_equal( NetUtils.ip_to_string( 4294967296 ), "::1:0:0" );
test_equal(NetUtils.ip_to_string( 0xffffeeeeaaaa99998888777766665555 ),
"ffff:eeee:aaaa:9999:8888:7777:6666:5555");
|
352471 | 2015-05-26 | Martin Nilsson | | test_equal(NetUtils.ip_to_string( 0xffff0000000000000000000000005555 ),
|
af2eab | 2013-10-28 | Per Hedbor | | "ffff::5555");
test_equal(NetUtils.ip_to_string( 0x00010000000000000000000000000000 ),
"1::");
test_equal( NetUtils.string_to_ip("10293::"),-1);
test_equal( NetUtils.string_to_ip("fel::"),-1);
test_equal( NetUtils.cidr_to_netmask( "0.0.0.0/0" ), ({ 0,NetUtils.IPV6_FULL_MASK^0xffffffff }) );
test_equal( NetUtils.cidr_to_netmask( "255.0.0.0/0" ), ({ 0,NetUtils.IPV6_FULL_MASK^0xffffffff }) );
test_equal( NetUtils.cidr_to_netmask( "ff::/0" ), ({ 0,0 }) );
test_equal( NetUtils.cidr_to_netmask( "255.255.255.255/32" ),
({ 0xffffffff,NetUtils.IPV6_FULL_MASK }) );
|
352471 | 2015-05-26 | Martin Nilsson | | test_equal( NetUtils.cidr_to_netmask( "255.255.255.255/16" ),
|
af2eab | 2013-10-28 | Per Hedbor | | ({ 0xffff0000,NetUtils.IPV6_FULL_MASK^0xffff }) );
|
352471 | 2015-05-26 | Martin Nilsson | | test_equal( NetUtils.cidr_to_netmask( "255.255.255.255/0" ),
|
af2eab | 2013-10-28 | Per Hedbor | | ({ 0x00000000,NetUtils.IPV6_FULL_MASK^0xffffffff }) );
|
352471 | 2015-05-26 | Martin Nilsson | | test_equal( NetUtils.cidr_to_netmask( "::/0" ),
|
af2eab | 2013-10-28 | Per Hedbor | | ({ 0x00000000,0 }) );
|
352471 | 2015-05-26 | Martin Nilsson | | test_equal( NetUtils.cidr_to_netmask( "10.30.1.69/17" ),
|
af2eab | 2013-10-28 | Per Hedbor | | ({ 0x0a1e0000,NetUtils.IPV6_FULL_MASK^0x7fff }) );
test_equal( NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/64"),
({ 0x0001000200030004<<64,
0xffffffffffffffff<<64,
}) );
test_equal( NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/96"),
({ 0x000100020003000400050006<<32,
0xffffffffffffffffffffffff<<32,
}) );
test_equal( NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/32"), ({0x00010002<<96,0xffffffff<<96}) );
test_equal( NetUtils.cidr_to_netmask( "10.30/3" ), 0 );
test_equal( NetUtils.cidr_to_netmask( "255.255.255.255" ), 0 );
test_equal( NetUtils.cidr_to_netmask( "255" ), 0 );
// comma instead of first dot
test_equal( NetUtils.cidr_to_netmask( "255,255.255.255/32" ), 0 );
test_equal( NetUtils.cidr_to_netmask( "20...10/1" ), 0 );
test_equal( NetUtils.cidr_to_netmask( 0 ), 0 );
test_equal( NetUtils.cidr_to_netmask( "4.3.2.300/16" ), 0 );
test_equal( NetUtils.cidr_to_netmask( "4.3.2.1/38" ), 0 );
// binary IPs
test_equal( NetUtils.ip_in_block( 0xffffffff, 0xffffffff, 0xffffffff ), true );
test_equal( NetUtils.ip_in_block( 0xffff0000, 0xffff0000, 0xffff0102 ), true );
test_equal( NetUtils.ip_in_block( 0x00000000, 0x00000000, 0x01020304 ), true );
test_equal( NetUtils.ip_in_block( 0x0a1e0000, 0xffff8000, 0x0a1e0145 ), true );
test_equal( NetUtils.ip_in_block( 0xffffffff, 0xffffffff, 0x01020304 ), false );
test_equal( NetUtils.ip_in_block( 0xffff0000, 0xffff0000, 0x01020102 ), false );
// string IPs
test_equal( NetUtils.ip_in_block( 0xffffffff, 0xffffffff, "255.255.255.255" ), true );
test_equal( NetUtils.ip_in_block( 0xffff0000, 0xffff0000, "255.255.1.2" ), true );
test_equal( NetUtils.ip_in_block( 0x00000000, 0x00000000, "1.2.3.4" ), true );
test_equal( NetUtils.ip_in_block( 0x0a1e0000, 0xffff8000, "10.30.1.69" ), true );
test_equal( NetUtils.ip_in_block( 0xffffffff, 0xffffffff, "1.2.3.4" ), false );
test_equal( NetUtils.ip_in_block( 0xffff0000, 0xffff0000, "1.2.1.2" ), false );
test_equal( NetUtils.ip_in_block( 0x01020000, 0xffff0000, "1.1.1.2" ), false );
// error handling
test_eval_error( NetUtils.ip_in_block( 0x00000000, 0x00000000, "65535.255.255" ));
test_eval_error( NetUtils.ip_in_block( 0x00000000, 0x00000000, "20.255.255" ));
test_eval_error( NetUtils.ip_in_block( 0x00000000, 0x00000000, "20...10" ));
test_eval_error( NetUtils.ip_in_block( -1, 0x00000000, "255.255.255.255" ));
test_eval_error( NetUtils.ip_in_block( 0x00000000, -1, "255.255.255.255" ));
test_equal( NetUtils.ip_in_block( @NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/64"), "1:2:3:4:5:6:7:8"), true );
test_equal( NetUtils.ip_in_block( @NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/64"), "1:2:3:4::"), true );
test_equal( NetUtils.ip_in_block( @NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/64"), "1:2:3:4:ffff:123:0:0"), true );
test_equal( NetUtils.ip_in_block( @NetUtils.cidr_to_netmask( "1:2:3:4:5:6:7:8/64"), "1:2:3:9:ffff:123:0:0"), false )
test_equal( NetUtils.NetMask("1.2.3.4/24")->ip_in("1.2.3.1"), true );
test_equal( NetUtils.NetMask("1.2.3.4/24")->ip_in("1.2.2.1"), false );
test_equal( NetUtils.NetMask("1.2.3.4/32")->ip_in("1.2.3.4"), true );
test_equal( NetUtils.NetMask("1.2.3.4/32")->ip_in("1.2.3.3"), false );
test_equal( NetUtils.NetMask("1.2.3.4")->ip_in("1.2.3.4"), true );
test_equal( NetUtils.NetMask("1.2.3.4")->ip_in("1.2.3.3"), false );
test_eval_error( NetUtils.NetMask("1.2.3.4/38") );
test_eval_error( NetUtils.NetMask("1.2.3.foo") );
test_eval_error( NetUtils.NetMask("foo") );
test_eval_error(NetUtils.IpRangeLookup(0));
test_equal(NetUtils.IpRangeLookup( ([ ]) )->lookup("1.2.3.4"), 0);
test_eval_error(NetUtils.IpRangeLookup( ([
"good": ({ "1.2.3.4", "4.5.6.0/24" }),
"bad": ({ "foo" }),
]) ));
test_eval_error(NetUtils.IpRangeLookup( ([
"bad": ({ "4.3.2.300" }),
]) ));
test_eval_error(NetUtils.IpRangeLookup( ([
"bad": ({ "4.3.2.1/38" }),
]) ));
test_eval_error(NetUtils.IpRangeLookup( ([
"good": ({ "1.2.3.4", "4.5.6.0/24" }),
"ok": ({ "127.0.0.0/8" }),
"bad": ({ "192.168.1.0/24", "4.3.2.1/38" }),
]) ));
test_any([[
NetUtils.IpRangeLookup irl = NetUtils.IpRangeLookup( ([ "single": ({ "1.2.3.4" }) ]) );
if(irl->lookup("1.2.3.4")!= "single") return 0;
if(irl->lookup("4.3.2.1")!= 0) return 0;
return 1;
]],1)
test_any([[
NetUtils.IpRangeLookup irl = NetUtils.IpRangeLookup( ([
"info1": ({ "1.2.3.0/24" }),
"info2": ({ "88.192.0.0/10" }),
]) );
if(irl->lookup("1.2.3.4")!= "info1") return 0;
if(irl->lookup("88.201.123.44")!= "info2") return 0;
if(irl->lookup("222.123.45.6")!= 0) return 0;
return 1;
]],1);
test_any([[
NetUtils.IpRangeLookup irl = NetUtils.IpRangeLookup( ([
"info1": ({ "1.2.3.0/24", "88.192.0.0/10" }),
"info2": ({ "192.168.1.14", "192.168.1.23", "153.154.155.156" }),
"info3": ({ "127.0.0.0/8" }),
]) );
if(irl->lookup("1.2.3.4")!= "info1") return 0;
if(irl->lookup("88.201.123.44")!= "info1") return 0;
if(irl->lookup("192.168.1.23")!= "info2") return 0;
if(irl->lookup("192.168.1.55")!= 0) return 0;
if(irl->lookup("127.0.0.1")!= "info3") return 0;
return 1;
]],1)
test_any([[
NetUtils.IpRangeLookup irl = NetUtils.IpRangeLookup( ([
"info1": ({ "1.2.3.0/24", "127.0.0.1" }),
"info2": ({ "1.2.3.0/28", "127.0.0.0/16" }),
"info3": ({ "127.0.0.0/8" }),
]) );
if(irl->lookup("127.0.0.1")!= "info1") return 0;
if(irl->lookup("127.0.0.2")!= "info2") return 0;
if(irl->lookup("127.0.42.1")!= "info2") return 0;
if(irl->lookup("127.88.44.22")!= "info3") return 0;
if(irl->lookup("126.0.0.1")!= 0) return 0;
if(irl->lookup("1.2.3.127")!= "info1") return 0;
if(irl->lookup("1.2.3.15")!= "info2") return 0;
return 1;
]],1)
test_any([[
NetUtils.IpRangeLookup irl = NetUtils.IpRangeLookup
(([
"test2":({"::/0"}),
"test":({"0.0.0.0/0"}),
]));
if( irl->lookup("1.2.3.4")!= "test" ) return 0;
if( irl->lookup("1.2.3.4")!= "test" ) return 0;
if( irl->lookup("1::")!="test2" ) return 0;
if( irl->lookup("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")!= "test2" ) return 0;
return 1;
]],1)
|
b84bec | 2013-11-15 | Henrik Grubbström (Grubba) | | test_do([[
|
af2eab | 2013-10-28 | Per Hedbor | | array victims = ({
"127.0.0.1",
"::1",
"2001::feed",
"224.0.0.1",
"2002::beef",
"3001:10::",
"32.2.0.1",
});
array(string)
nothing=({}),
v6only = "localhostv6,localv6,globalv6,multicastv6,teredo,6to4,privatev6"/",",
v4only = "localhost,local,global,multicast,private"/",",
teredo = "localhostv6,localv6,teredo,globalv6,multicastv6,6to4,privatev6"/",",
v6to4 = "localhostv6,localv6,6to4,globalv6,multicastv6,teredo,privatev6"/",",
dual6to4 = "localhostv6,localhost,localv6,local,6to4,globalv6,global,multicastv6,"
"multicast,teredo,privatev6,private"/",",
dualdual = "localhostv6,localhost,localv6,local,teredo,6to4,globalv6,global,multicastv6,"
"multicast,privatev6,private"/",";
add_constant( "victims", victims );
add_constant( "nothing", nothing );
add_constant( "v6only", v6only );
add_constant( "v4only", v4only );
add_constant( "teredo", teredo );
add_constant( "v6to4", v6to4 );
add_constant( "dual6to4", dual6to4 );
add_constant( "dualdual", dualdual );
|
b84bec | 2013-11-15 | Henrik Grubbström (Grubba) | | ]]);
|
af2eab | 2013-10-28 | Per Hedbor | |
test_equal( NetUtils._connectable_network_types( false, false, false, false ), nothing );
test_equal( NetUtils._connectable_network_types( false, false, false, true ), nothing );
test_equal( NetUtils._connectable_network_types( false, false, true, false ), nothing );
test_equal( NetUtils._connectable_network_types( false, false, true, true ), nothing );
test_equal( NetUtils._connectable_network_types( true, false, false, false ),v6only );
test_equal( NetUtils._connectable_network_types( false, true, false, false ), v4only );
test_equal( NetUtils._connectable_network_types( false, true, true, false ), v4only );
test_equal( NetUtils._connectable_network_types( false, true, false, true ), v4only );
test_equal( NetUtils._connectable_network_types( false, true, true, true ), v4only );
test_equal( NetUtils._connectable_network_types( true, false, true, false ), teredo );
test_equal( NetUtils._connectable_network_types( true, false, false, true ), v6to4 );
test_equal( NetUtils._connectable_network_types( true, true, false, true ), dual6to4 );
test_equal( NetUtils._connectable_network_types( true, true, true, true ), dualdual );
test_equal( NetUtils._sort_addresses( victims, 0, false, nothing ), ({}) );
test_equal( NetUtils._sort_addresses( victims, 0, false, v6only ), ({
"::1",
"3001:10::",
"2001::feed",
"2002::beef",
}) );
test_equal( NetUtils._sort_addresses( victims, 0, false, v4only ), ({
"127.0.0.1",
"32.2.0.1",
"224.0.0.1",
}) );
test_equal( NetUtils._sort_addresses( victims, 0, false, teredo ), ({
"::1",
"2001::feed",
"3001:10::",
"2002::beef",
}) );
test_equal( NetUtils._sort_addresses( victims, 0, false, v6to4 ), ({
"::1",
"2002::beef",
"3001:10::",
"2001::feed",
}) );
test_equal( NetUtils._sort_addresses( victims, 0, false, dualdual ), ({
"::1",
"127.0.0.1",
"2001::feed",
"2002::beef",
"3001:10::",
"32.2.0.1",
"224.0.0.1",
}) );
|
b84bec | 2013-11-15 | Henrik Grubbström (Grubba) | | dnl network-addr, network-type, opt-separate-v6
define(test_network_type, [[
test_true([[(< $2 >)
[NetUtils.get_network_type($1, $3)]
]])
]])
dnl network-addr, network-type, opt-separate-v6
define(test_local_network_type, [[
// Test a network that might be a local network.
// The localhost variants are there just in case
// the local machine actually has the IP.
test_network_type([[$1]],
[[ NetUtils.LOCAL, NetUtils.LOCALV6,
|
b3a11c | 2013-11-16 | Henrik Grubbström (Grubba) | | NetUtils.LOCALHOST, NetUtils.LOCALHOSTV6, $2 ]],
|
b84bec | 2013-11-15 | Henrik Grubbström (Grubba) | | [[$3]])
]])
test_network_type("::1", NetUtils.LOCALHOST)
test_network_type("::1", NetUtils.LOCALHOSTV6, true)
test_network_type("127.0.0.1", NetUtils.LOCALHOST)
test_network_type("::ffff:127.0.0.1", NetUtils.LOCALHOST)
test_network_type("::ffff:127.0.0.1", NetUtils.LOCALHOST, true)
// NB: No machines will have these as local address,
// since the corresponding IPv4 addresses are reserved.
// (Correspond to 0.0.0.0 and 255.255.18.52).
test_network_type("2001::feed", NetUtils.TEREDO)
test_network_type("2001:0:ffff:1234::4321", NetUtils.TEREDO)
test_local_network_type("10.0.0.1", NetUtils.PRIVATE)
test_local_network_type("::FFFF:10.0.0.1", NetUtils.PRIVATE)
test_local_network_type("172.16.0.1", NetUtils.PRIVATE)
test_local_network_type("::FFFF:172.16.0.1", NetUtils.PRIVATE)
test_local_network_type("192.168.0.1", NetUtils.PRIVATE)
test_local_network_type("::FFFF:192.168.0.1", NetUtils.PRIVATE)
test_local_network_type("fc00::1", NetUtils.PRIVATE)
// NB: Multicast addresses are not valid as local addresses.
test_network_type("224.0.0.1", NetUtils.MULTICAST)
test_network_type("ff00:1:2:3::1", NetUtils.MULTICAST)
// NB: No machines will have these as local address,
// since the corresponding IPv4 addresses are reserved.
// (Correspond to 0.0.0.0 and 255.255.18.52).
test_network_type("2002::beef", NetUtils.V6TO4)
test_network_type("2002:ffff:1234::beef", NetUtils.V6TO4)
test_local_network_type("2001:1::feed", NetUtils.GLOBAL)
test_local_network_type("2001:ffff:1234::4321", NetUtils.GLOBAL)
test_local_network_type("2003::beef", NetUtils.GLOBAL)
test_local_network_type("3002:ffff::1234:beef", NetUtils.GLOBAL)
test_local_network_type("2001:1::feed", NetUtils.GLOBALV6, true)
test_local_network_type("2001:ffff:1234::4321", NetUtils.GLOBALV6, true)
|
af2eab | 2013-10-28 | Per Hedbor | |
// Could be mistaken for 2002::/16
|
b84bec | 2013-11-15 | Henrik Grubbström (Grubba) | | test_local_network_type("32.2.0.1", NetUtils.GLOBAL)
test_local_network_type("32.2.0.1", NetUtils.GLOBAL, true)
|
af2eab | 2013-10-28 | Per Hedbor | |
// Could be mistaken for 2001:0::/32
|
b84bec | 2013-11-15 | Henrik Grubbström (Grubba) | | test_local_network_type("32.1.0.0", NetUtils.GLOBAL)
test_local_network_type("32.1.0.0", NetUtils.GLOBAL, true)
|
af2eab | 2013-10-28 | Per Hedbor | |
test_do([[
add_constant("victims");
add_constant("nothing");
add_constant("v6only");
add_constant("v4only");
add_constant("teredo");
add_constant("v6to4");
add_constant("dual6to4");
add_constant("dualdual");
]])
test_any([[
class TestRemoteAddressObject(string local_ip, string remote_ip)
{
inherit NetUtils.RemoteAddressObject;
string query_address(int|void l)
{
if (l)
return local_ip;
return remote_ip;
}
};
string def_ip = "192.168.0.1";
string def_port = "1111";
string local_ip = "123.123.123.123";
string local_port = "1234";
string remote_ip = "234.234.234.234";
string remote_port = "5678";
add_constant("TestRemoteAddressObject",TestRemoteAddressObject);
add_constant("def_ip", def_ip );
add_constant("def_port", def_port );
add_constant("local_ip", local_ip );
add_constant("local_port", local_port );
add_constant("remote_ip", local_ip );
add_constant("remote_port", local_port );
return 1;
]],1);
test_equal(NetUtils.ip_of(0, false, def_ip), def_ip);
test_equal(NetUtils.ip_of(0, true, def_ip), def_ip);
test_equal(NetUtils.ip_of(remote_ip, false, def_ip), remote_ip);
test_equal(NetUtils.ip_of(local_ip, true, def_ip), local_ip);
test_equal(NetUtils.ip_of(remote_ip + " " + remote_port, false, def_ip), remote_ip);
test_equal(NetUtils.ip_of(local_ip + " " + local_port, true, def_ip), local_ip);
test_equal(NetUtils.ip_of(TestRemoteAddressObject(local_ip + " " + local_port, remote_ip + " " + remote_port), false, def_ip), remote_ip);
test_equal(NetUtils.ip_of(TestRemoteAddressObject(local_ip + " " + local_port, remote_ip + " " + remote_port), true, def_ip), local_ip);
test_equal(NetUtils.ip_of(TestRemoteAddressObject(local_ip, remote_ip), false, def_ip), remote_ip);
test_equal(NetUtils.ip_of(TestRemoteAddressObject(local_ip, remote_ip), true, def_ip), local_ip);
test_equal(NetUtils.port_of(0, false, def_port), def_port);
test_equal(NetUtils.port_of(0, true, def_port), def_port);
test_equal(NetUtils.port_of(remote_ip, false, def_port), def_port);
test_equal(NetUtils.port_of(local_ip, true, def_port), def_port);
test_equal(NetUtils.port_of(remote_ip + " " + remote_port, false, def_port), remote_port);
test_equal(NetUtils.port_of(local_ip + " " + local_port, true, def_port), local_port);
test_equal(NetUtils.port_of(TestRemoteAddressObject(local_ip + " " + local_port, remote_ip + " " + remote_port), false, def_port), remote_port);
test_equal(NetUtils.port_of(TestRemoteAddressObject(local_ip + " " + local_port, remote_ip + " " +remote_port), true, def_port), local_port);
test_equal(NetUtils.port_of(TestRemoteAddressObject(local_ip, remote_ip), false, def_port), def_port);
test_equal(NetUtils.port_of(TestRemoteAddressObject(local_ip, remote_ip), true, def_port), def_port);
test_equal(NetUtils.ip_and_port_of(0, false), 0);
test_equal(NetUtils.ip_and_port_of(0, true), 0);
test_equal(NetUtils.ip_and_port_of(remote_ip, false), ({ remote_ip, 0 }) );
test_equal(NetUtils.ip_and_port_of(local_ip, true), ({ local_ip, 0 }) );
test_equal(NetUtils.ip_and_port_of(remote_ip + " " + remote_port, false), ({ remote_ip, remote_port }) );
test_equal(NetUtils.ip_and_port_of(local_ip + " " + local_port, true), ({ local_ip, local_port }) );
test_equal(NetUtils.ip_and_port_of(TestRemoteAddressObject(local_ip + " " + local_port, remote_ip + " " + remote_port), false), ({ remote_ip, remote_port }) );
test_equal(NetUtils.ip_and_port_of(TestRemoteAddressObject(local_ip + " " + local_port, remote_ip + " " +remote_port), true), ({ local_ip, local_port }) );
test_equal(NetUtils.ip_and_port_of(TestRemoteAddressObject(local_ip, remote_ip), false), ({ remote_ip, 0 }) );
test_equal(NetUtils.ip_and_port_of(TestRemoteAddressObject(local_ip, remote_ip), true), ({ local_ip, 0 }) );
test_do([[
add_constant("TestRemoteAddressObject");
add_constant("def_ip" );
add_constant("def_port" );
add_constant("local_ip" );
add_constant("local_port" );
add_constant("remote_ip" );
add_constant("remote_port" );
]]);
|
5c20fa | 2008-05-01 | Martin Nilsson | | dnl - Arg
test_equal( Arg.parse("aa --hopp --haha=ho -bar=foo x y"/" "),
([ "hopp":1, "haha":"ho", "b":1, "a":1, "r":"foo", Arg.REST: ({"x","y"}) ]) )
test_equal( Arg.parse("aa -bar -x=6"/" "),
([ "b":1, "a":1, "r":1, "x":"6", Arg.REST: ({}) ]) )
test_equal( Arg.parse("aa --foo --bar"/" "),
([ "foo":1, "bar":1, Arg.REST: ({}) ]) )
test_equal( Arg.parse("aa --foo - --bar"/" "),
([ "foo":1, Arg.REST: ({ "-","--bar" }) ]) )
test_equal( Arg.parse("aa --foo x --bar"/" "),
([ "foo":1, Arg.REST: ({ "x","--bar" }) ]) )
|
685c7c | 2013-06-03 | Martin Nilsson | | test_equal( Arg.parse("aa -foo -o"/" "),
([ "f":1, "o":3, Arg.REST: ({}) ]) )
|
5c20fa | 2008-05-01 | Martin Nilsson | |
|
f33606 | 2008-05-03 | Martin Nilsson | | test_any([[
class Opt
{
inherit Arg.Options;
Opt verbose = NoOpt("-v")|NoOpt("--verbose")|Env("VERBOSE");
Opt name = HasOpt("-n")|HasOpt("--name")|Default("Donald");
Opt debug = MaybeOpt("-d")|MaybeOpt("--debug");
|
5abafb | 2016-07-10 | Martin Nilsson | | Opt i = Int(HasOpt("-i")|Default(42));
|
eb5a5f | 2017-01-27 | Martin Nilsson | | Opt m = Multiple(HasOpt("-m"));
|
f33606 | 2008-05-03 | Martin Nilsson | | };
add_constant("o",Opt);
return 1;
]], 1)
|
eb5a5f | 2017-01-27 | Martin Nilsson | | test_equal( sort(indices(o(({"x"})))) , sort(({ Arg.PATH, Arg.REST, Arg.APP, "debug", "help", "i", "m", "name", "verbose" })) )
|
5abafb | 2016-07-10 | Martin Nilsson | | test_equal( (mapping)o(({"x"}),([])) , ([ "name" : "Donald", "i":42, Arg.REST:({}) ]) )
|
f33606 | 2008-05-03 | Martin Nilsson | | test_equal( o(({"x"}),([]))->verbose , 0 )
test_equal( o(({"x"}),([]))->debug , 0 )
test_equal( o(({"x"}),([]))->name , "Donald" )
test_equal( o("x --name=foo"/" ",([]))->name , "foo" )
test_equal( o("x -n=foo"/" ",([]))->name , "foo" )
test_equal( o("x -n foo"/" ",([]))->name , "foo" )
|
5abafb | 2016-07-10 | Martin Nilsson | | test_equal( (mapping)o("x -dvn foo xor"/" ",([])), ([ "debug":1, "verbose":1, "name":"foo", "i":42, Arg.REST : ({ "xor" }) ]) )
|
f33606 | 2008-05-03 | Martin Nilsson | | test_equal( o(({"x"}),(["VERBOSE":"1"]))->verbose, "1" )
|
5abafb | 2016-07-10 | Martin Nilsson | | test_equal( (mapping)o("x --verbose=5"/" ",([])), ([ "name":"Donald", "i":42, Arg.REST : ({ "--verbose=5" }) ]) )
|
ad9bec | 2016-07-04 | Martin Nilsson | | test_equal( o("x -v florp"/" ")[Arg.REST], ({ "florp" }) )
|
685c7c | 2013-06-03 | Martin Nilsson | | test_equal( o("x -v -v"/" ",([]))->verbose , 2 )
|
5abafb | 2016-07-10 | Martin Nilsson | | test_equal( o("x"/" ")->i, 42 )
test_equal( o("x -i 7"/" ")->i, 7 )
|
35b78f | 2016-11-05 | Martin Nilsson | | test_equal( o("/a/b/c -v"/" ")[Arg.PATH], "/a/b/c" )
test_equal( o("/a/b/c -v"/" ")[Arg.APP], "c")
|
eb5a5f | 2017-01-27 | Martin Nilsson | | test_equal( o("x"/" ")->m, 0)
test_equal( o("x -m a"/" ")->m, ({ "a" }))
test_equal( o("x -m a -m b"/" ")->m, ({ "a", "b" }))
|
f33606 | 2008-05-03 | Martin Nilsson | |
test_do(add_constant("o"))
|
937007 | 2002-10-14 | Martin Nilsson | | dnl - Array
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
|
ee66ab | 2003-01-15 | Martin Nilsson | | 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"/"", ({ "/" }) }) }))
|
cccc64 | 2003-04-29 | Martin Nilsson | | dnl Array.diff_compare_table
|
ee66ab | 2003-01-15 | Martin Nilsson | | test_equal(Array.longest_ordered_sequence("dfgaokäpojghadjjioijrgxcvb"/""),
({ 0, 1, 2, 10, 11, 16, 18, 19, 20, 22 }));
|
d6b78d | 2004-05-02 | Martin Nilsson | | test_equal([[ Array.interleave_array( ({
([ 2:2, 6:3]), ([ 2:4, 5:5 ]), ([]), ([2:6,3:7,6:8]) })) ]],[[
({ 0, 2, -1, 6 }) ]])
|
937007 | 2002-10-14 | Martin Nilsson | | dnl Array.sort
|
e5a2cc | 2002-10-14 | Johan Sundström | | test_equal([[ Array.diff(enumerate(4),enumerate(4,1,2)) ]],
[[ ({ ({ ({0,1}), ({2,3}), ({ }) }),
({ ({ }), ({2,3}), ({4,5}) }) }) ]])
test_any_equal([[ array x, y;
[x, y] = Array.diff(enumerate(4),enumerate(4,1,2));
return x[1] == y[1]; ]], 1)
|
937007 | 2002-10-14 | Martin Nilsson | | test_equal(Array.everynth("0123456789"/""),
({ "0", "2", "4", "6", "8"}))
test_equal(Array.everynth("0123456789"/"",3),
({ "0", "3", "6", "9"}))
test_equal(Array.everynth("0123456789"/"",3,4),
({ "4", "7"}))
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.everynth(({})),({}))
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
test_equal(Array.splice(({7,8,99}),({"h","h",99})),
({7,"h",8,"h",99,99}))
test_equal(Array.splice(({7,8}),({"h","h",99})),
({7,"h",8,"h"}))
test_equal(Array.splice(({7,8,99}),({"h","h",99}),({"g",({"fg"}),97})),
({7,"h","g",8,"h",({"fg"}),99,99,97}))
test_equal(Array.splice(({7,"foo"})),
({7,"foo"}))
test_equal(Array.splice(),
({}))
test_equal(Array.splice(({})),
({}))
|
c514e1 | 2015-04-29 | Martin Nilsson | | test_equal(Array.transpose( ({ }) ), ({}))
|
3c87a1 | 2002-08-03 | Martin Nilsson | | test_equal(Array.transpose( ({ ({ 1,2,3}), ({4,5,6}) }) ),
({ ({1,4}), ({2,5}), ({3,6}) }))
test_equal([[Array.transpose(({catch{throw(({""}));},({1,2})[1..]}))]],
[[ ({ ({ "", 2 }) }) ]])
test_equal(Array.uniq( ({ 1,1,2,2,3,3,4,1,2,3,3,2,1,2,1 }) ),
({1,2,3,4}))
test_equal(Array.uniq( ({ "a",5,1.0,5,"b","a" }) ),
({"a",5,1.0,"b"}))
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.uniq( ({}) ), ({}))
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
test_equal(Array.filter( ({ 1,2,3,4,5,6, }), lambda(int i) { return 0; } ),
({}))
test_equal(Array.filter( ({ 1,2,3,4,5,6, }), lambda(int i) { return 1; } ),
({1,2,3,4,5,6}))
test_equal(Array.filter( ({ 1,2,3,4,5,6, }), lambda(int i) { return i%2; } ),
({1,3,5}))
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal([[ Array.filter( ({}), lambda(int i) { return 1; })]], ({}))
|
a3d0ee | 2014-08-28 | Martin Nilsson | | test_eq(filter("\0\1\2", `<, 2), "\0\1")
test_equal(filter((["a":1,"b":2]), `<, 2), (["a":1]))
test_equal(filter((<0,1,2>), `<, 2), (<0,1>))
test_any_equal(class A { constant a=1; constant b=2; }; return filter(A, `<, 2);, (["a":1]))
test_any_equal(class A { protected mixed cast(string t) { if(t=="mapping") return (["a":1,"b":2]);}}; return filter(A(), `<, 2);, (["a":1]))
test_any_equal(class A { protected mixed cast(string t) { if(t=="array") return ({1,2,3});}}; return filter(A(), `<, 2);, ({1}))
test_any_equal(class A { protected mixed cast(string t) { if(t=="multiset") return (<1,2,3>);}}; return filter(A(), `<, 2);, (<1>))
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
test_equal(Array.permute( ({ 1,2 }), 0 ),
({ 1,2 }))
test_equal(Array.permute( ({ 1,2 }), 1 ),
({ 2,1 }))
|
cccc64 | 2003-04-29 | Martin Nilsson | | test_equal(Array.permute( ({ 1,2 }), 2 ),
({ 1,2 }))
|
3c87a1 | 2002-08-03 | Martin Nilsson | | test_equal(Array.permute( ({ 1,2,3,4,5,6,7,8,9,10 }), 3628800),
({ 1,2,3,4,5,6,7,8,9,10 }))
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.permute( ({}), 1 ), ({}))
|
1a3dd9 | 2014-08-15 | Martin Nilsson | | test_eval_error(Array.permute( "12"/1, random(1)-2))
|
5f47fa | 2015-05-08 | Martin Nilsson | | test_any_equal([[
function f = Array.permute;
array a = ({ 1,2 });
return f(a, 1, 2);
]], ({ 2, 1}))
test_eval_error(Array.permute( ({1,2}), -(1+random(1))))
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.enumerate(0), ({}))
test_equal(Array.enumerate(1), ({ 0 }))
|
3c87a1 | 2002-08-03 | Martin Nilsson | | test_equal(Array.enumerate(5), ({ 0,1,2,3,4 }))
test_equal(Array.enumerate(5,2), ({ 0,2,4,6,8 }))
test_equal(Array.enumerate(5,2,7), ({ 7,9,11,13,15 }))
test_equal(Array.enumerate(5,2,7,`-), ({ 7,5,3,1,-1 }))
|
84604c | 2015-06-05 | Arne Goedeke | | test_equal(Array.enumerate(5,1,Int.NATIVE_MAX-1), ({ Int.NATIVE_MAX-1, Int.NATIVE_MAX, Int.NATIVE_MAX+1, Int.NATIVE_MAX+2, Int.NATIVE_MAX+3 }))
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
|
e5a2cc | 2002-10-14 | Johan Sundström | | test_eq([[ Array.reduce(`>>, ({})) ]], 0)
test_eq([[ Array.reduce(`==, ({}), 1) ]], 1)
test_eq([[ Array.reduce(`<<, ({1,2,3,4,5})) ]], 1<<14)
test_eq([[ Array.rreduce(`>>, ({})) ]], 0)
test_eq([[ Array.rreduce(`==, ({}), 1) ]], 1)
test_eq([[ Array.rreduce(`<<, ({4,3,2,1})) ]], 1125899906842624)
|
937007 | 2002-10-14 | Martin Nilsson | |
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.shuffle(({})), ({}))
test_equal(Array.shuffle(({1})), ({1}))
|
3c87a1 | 2002-08-03 | Martin Nilsson | | test_any([[
array b = Array.shuffle(Array.enumerate(1000));
// There is a chance in 1000! (aprox. 4E2568) that this fails of
// natural causes.
|
ec314b | 2014-12-06 | Arne Goedeke | | return !equal(b, Array.shuffle(Array.enumerate(1000)));
|
3c87a1 | 2002-08-03 | Martin Nilsson | | ]], 1);
test_true( equal(Array.enumerate(1000),sort(Array.shuffle(Array.enumerate(1000)))) )
|
937007 | 2002-10-14 | Martin Nilsson | | dnl Array.search_array
|
cccc64 | 2003-04-29 | Martin Nilsson | |
test_equal( Array.sum_arrays( `+, ({}) ), ({}) )
test_equal( Array.sum_arrays( `+, enumerate(5), enumerate(5)), ({0,2,4,6,8}) )
|
e5a2cc | 2002-10-14 | Johan Sundström | |
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.sort_array(({})), ({}))
|
e5a2cc | 2002-10-14 | Johan Sundström | | test_equal([[ Array.sort_array(enumerate(9), `<) ]], [[ enumerate(9,-1,8) ]])
|
937007 | 2002-10-14 | Martin Nilsson | | dnl Array.columns
dnl Array.transpose_old
|
ee66ab | 2003-01-15 | Martin Nilsson | |
dnl (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"})})}))
dnl 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"})})}))
dnl 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"}),({ })})}))
dnl The following is not optimal.
test_equal(Array.diff3(({"a"}),({"b","a"}),({"a","b","a"})),
({({({ }),({"a"}),({ })}),
({({"b"}),({"a"}),({ })}),
({({ }),({"a"}),({"b","a"})})}))
dnl 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"})})}))
dnl 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"})})}))
dnl 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"}),({ })})}))
|
bf779e | 2006-01-31 | Martin Stjernholm | | test_equal(Array.diff3(({1,2,3,4}),({1,6,7,2}),({1,3,4,2,6,7})),
({({({1}),({2}),({3,4}),({ }),({ }),({ })}),
({({1}),({ }),({ }),({ }),({6,7}),({2})}),
({({1}),({ }),({3,4}),({2}),({6,7}),({ })})}))
|
ee66ab | 2003-01-15 | Martin Nilsson | |
|
cccc64 | 2003-04-29 | Martin Nilsson | | define(test_sort,[[
test_eq(Array.$1($2,$3), -1)
test_eq(Array.$1($3,$2), 1)
]])
test_false(Array.dwim_sort_func("",""))
test_sort(dwim_sort_func,"1","a")
test_sort(dwim_sort_func,"1","1a")
test_sort(dwim_sort_func,"0a","1")
test_sort(dwim_sort_func,"1","2")
test_sort(dwim_sort_func,"2a","10")
|
20da98 | 2007-12-27 | Martin Nilsson | | test_sort(dwim_sort_func,"a1x","a02x")
|
ee66ab | 2003-01-15 | Martin Nilsson | | test_eq(Array.dwim_sort_func("1","1"), 0)
test_eq(Array.dwim_sort_func("1","01"), 0)
|
cccc64 | 2003-04-29 | Martin Nilsson | |
test_false(Array.lyskom_sort_func("",""))
test_sort(lyskom_sort_func,"a","b")
test_false(Array.lyskom_sort_func("a","a"))
test_false(Array.lyskom_sort_func("Foo (bar)","foo (really!)"))
|
ee66ab | 2003-01-15 | Martin Nilsson | |
|
cccc64 | 2003-04-29 | Martin Nilsson | | test_eq( Array.flatten( ({}) ), ({}) )
test_equal( Array.flatten( ({1,({2,({3,({4}),({}),5})}),({({}),({6})})})),
({1,2,3,4,5,6}) )
test_equal( Array.flatten( ({ 1,({2,3}),4,({2,3}),5 }) ), ({1,2,3,4,2,3,5}) )
test_any_equal([[
array a=({1,2,3});
a[1]=a;
return Array.flatten(a);
]], ({1,3}))
test_any_equal([[
array a=({1,({2,3}),({4,5}),({2,3})});
a[2][1]=a;
return Array.flatten(a);
]], ({1,2,3,4,2,3}))
|
e5a2cc | 2002-10-14 | Johan Sundström | |
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_eq(Array.sum(({})),0)
|
e5a2cc | 2002-10-14 | Johan Sundström | | test_eq(Array.sum((array(int))"157"), 157)
test_eq([[ Array.sum(enumerate(12345)) ]],
[[ Array.reduce(`+, enumerate(12345)) ]])
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_eq(Array.sum( "abcdefgh"/2.5 ), "abcdefgh")
test_equal([[ Array.sum( ({ ({ 1,2,3 }), ({ 4,5 }) }) )]],[[ ({ 1,2,3,4,5 }) ]])
|
e5a2cc | 2002-10-14 | Johan Sundström | |
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal(Array.uniq2(({})), ({}))
|
e5a2cc | 2002-10-14 | Johan Sundström | | test_equal([[ Array.uniq2("AAAAAAAAAAAHHHHAAA!!!!"/1)*"" ]], [[ "AHA!" ]])
|
937007 | 2002-10-14 | Martin Nilsson | |
test_equal([[ Array.arrayify( ({1,2,3}) ) ]],[[ ({1,2,3}) ]])
test_equal([[ Array.arrayify( 1 ) ]],[[ ({1}) ]])
test_equal([[ Array.arrayify( 0 ) ]],[[ ({0}) ]])
test_equal([[ Array.arrayify( UNDEFINED ) ]],[[ ({}) ]])
|
3c87a1 | 2002-08-03 | Martin Nilsson | |
|
937007 | 2002-10-14 | Martin Nilsson | | dnl Array.oid_sort_func
dnl Array.greedy_diff
|
e5a2cc | 2002-10-14 | Johan Sundström | |
|
f14a83 | 2002-10-16 | Martin Nilsson | | test_equal( Array.count(({})), ([]) )
|
e5a2cc | 2002-10-14 | Johan Sundström | | test_eq( Array.count((multiset)("All your Pike are belong to us!"/1), " "), 6 )
test_eq( Array.count("...and there was much rejoicing."/1, "."), 4 )
test_eq([[Array.count((["An":"eye", "for":4, "an":"eye"]), "eye")]], 2 )
test_equal([[ Array.count((["An":"eye", "for":4, "an":"eye"])) ]],
[[ ([ "eye":2, 4:1 ]) ]])
|
937007 | 2002-10-14 | Martin Nilsson | |
test_equal(Array.common_prefix(({ "soliloquise"/1 })), "soliloquise"/1)
test_equal(Array.common_prefix(({ "muzzle"/1, "muzzy"/1 })), "muzz"/1)
test_equal(Array.common_prefix(({ "labyrinth"/1, "diatom"/1 })), ({}))
test_equal(Array.common_prefix(({ "abc"/1, "abc"/1, "abc"/1 })), "abc"/1)
test_equal(Array.common_prefix(({})), ({}))
|
1093bf | 2016-03-10 | Martin Nilsson | | 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)
|
365b3c | 2016-03-10 | Martin Nilsson | | test_eq( sizeof(Array.Iterator(({1,2,3,4}))), 4 )
|
1093bf | 2016-03-10 | Martin Nilsson | |
|
70ca44 | 2016-03-12 | Martin Nilsson | | test_do(add_constant("random",Random.Deterministic(17)->random))
test_any_equal([[
string r = "";
for(int i; i<4; i++)
foreach(random(Array.Iterator("12345678"/1));; string v)
r += v;
return r;
]], "7883456785678")
test_do(add_constant("random",Random.System()->random))
|
e25444 | 2003-02-06 | Martin Nilsson | | dnl - Colors
define(test_rgb,[[
test_equal(Colors.$1($2),({$3}))
test_equal(Colors.$1(({$2})),({$3}))
]])
test_rgb(rgb_to_hsv,[[0,0,0]],[[0,0,0]])
test_rgb(rgb_to_hsv,[[255,255,255]],[[0,0,255]])
test_rgb(rgb_to_hsv,[[17,42,112]],[[159,216,112]])
test_rgb(hsv_to_rgb,[[0,0,0]],[[0,0,0]])
test_rgb(hsv_to_rgb,[[255,255,255]],[[255,0,0]])
test_rgb(hsv_to_rgb,[[17,42,112]],[[112,101,93]])
test_rgb(rgb_to_cmyk,[[0,0,0]],[[0,0,0,100]])
test_rgb(rgb_to_cmyk,[[255,255,255]],[[0,0,0,0]])
test_rgb(rgb_to_cmyk,[[17,41,112]],[[37,28,0,56]])
test_rgb(cmyk_to_rgb,[[0,0,0,0]],[[255,255,255]])
test_rgb(cmyk_to_rgb,[[100,100,100,100]],[[0,0,0]])
test_rgb(cmyk_to_rgb,[[17,42,100,2]],[[207,143,0]])
test_equal(Colors.parse_color(0),({0,0,0}))
test_equal(Colors.parse_color(""),({0,0,0}))
test_equal(Colors.parse_color("gazonk"),({0,0,0}))
test_equal(Colors.parse_color(0, ({1,2,3})),({1,2,3}))
test_equal(Colors.parse_color("", ({1,2,3})),({1,2,3}))
test_equal(Colors.parse_color("gazonk", ({1,2,3})),({1,2,3}))
test_equal(Colors.parse_color("red"),({255,0,0}))
test_equal(Colors.parse_color("red", ({1,2,3})),({255,0,0}))
test_equal(Colors.parse_color("RED"),({255,0,0}))
test_equal(Colors.parse_color("lightred"),({255,61,61}))
test_equal(Colors.parse_color("LIGHT RED"),({255,61,61}))
test_equal(Colors.parse_color("dimgray"),({105,105,105}))
test_equal(Colors.parse_color("#ff0000"),({255,0,0}))
test_equal(Colors.parse_color("ff0000"),({255,0,0}))
test_equal(Colors.parse_color("@0,255,255"),({255,0,0}))
test_equal(Colors.parse_color("%0,100,100,0"),({255,0,0}))
test_eq(Colors.color_name(0),"-")
test_eq(Colors.color_name( ({0,0}) ), "-")
test_eq(Colors.color_name( ({255,0,0}) ), "red")
test_eq(Colors.color_name( ({255,61,61}) ), "#ff3d3d")
test_eq(Colors.color_name( ({105,105,105}) ), "dimgrey")
|
937007 | 2002-10-14 | Martin Nilsson | |
|
26a195 | 2002-11-15 | Martin Nilsson | | dnl - Getopt
dnl setup
|
2cdaf9 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do(add_constant("original_POSIX_ME_HARDER", getenv("POSIX_ME_HARDER"));)
|
d7db96 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do(add_constant("original_foo", getenv("foo"));)
|
2cdaf9 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do(putenv("POSIX_ME_HARDER", 0);)
|
d7db96 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do(putenv("foo", "bar");)
|
2cdaf9 | 2004-07-14 | Henrik Grubbström (Grubba) | | // The following code is broken if the testsuite isn't run with -F,
// and messing around with internal structures in the master is not
// a good idea.
// /grubba 2004-07-14
//
|
a949ce | 2004-07-14 | Henrik Grubbström (Grubba) | | dnl test_do( add_constant("getopt_env", master()->environment); )
dnl test_do( master()->environment=([ "foo": ({ "foo", "bar" }) ]); )
dnl test_eq(function_object(getenv), master())
|
d7db96 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_equal(getenv("foo"), "bar")
test_equal(master()->getenv("foo"), "bar")
test_false(getenv("POSIX_ME_HARDER"))
test_false(master()->getenv("POSIX_ME_HARDER"))
|
26a195 | 2002-11-15 | Martin Nilsson | |
|
631757 | 2002-11-17 | Martin Nilsson | | test_eq( Getopt.find_option( ({}), "a" ), 0 )
|
26a195 | 2002-11-15 | Martin Nilsson | | test_eq( Getopt.find_option( "-a,-b"/",", "a" ), 0 )
test_eq( Getopt.find_option( "-a,--b"/",", "a" ), 0 )
test_eq( Getopt.find_option( "-a,-b"/",", "b" ), 1 )
test_eq( Getopt.find_option( "-a,-ab"/",", "b" ), 1 )
test_eq( Getopt.find_option( ",-a,-b"/",", "bc"/1 ), 1)
test_eq( Getopt.find_option( ",-,-a"/",", "a" ), 1)
test_eq( Getopt.find_option( ",--,-a"/",", "a" ), 0)
test_eq( Getopt.find_option( ",--a,-b"/",", "a"), 0)
test_eq( Getopt.find_option( ",--a,-b"/",", "b"), 1)
test_eq( Getopt.find_option( ",--a=b"/",", "x", "a"), "b")
test_eq( Getopt.find_option( ",--a=b"/",", "x", "a", 0, "y"), "b")
test_eq( Getopt.find_option( ",--a,-b"/",", "b", "a", 0, "y"), "-b")
|
631757 | 2002-11-17 | Martin Nilsson | | test_eq( Getopt.find_option( ",--a,-b"/",", "b", "a", 0, UNDEFINED), 1)
test_eval_error( Getopt.find_option( ",--a"/",", "x", "a", 0, "y", 1) )
|
26a195 | 2002-11-15 | Martin Nilsson | |
test_eq( Getopt.find_option( ",-ab"/",", "a"), 1)
test_eq( Getopt.find_option( ",-ab"/",", "b"), 1)
test_eq( Getopt.find_option( ",-ab"/",", "a", 0, 0, "y"), "b")
test_eq( Getopt.find_option( ",-a,-b"/",", "ab"/1, 0, 0, "y"), "-b")
|
631757 | 2002-11-17 | Martin Nilsson | | test_eval_error( Getopt.find_option( ",-a"/",", "a", 0, 0, "y", 1) )
|
26a195 | 2002-11-15 | Martin Nilsson | |
test_any_equal([[
array x = ({ "", "--a" });
Getopt.find_option( x, "x", "a" );
return x;
]],[[ ({ "", 0 }) ]])
test_any_equal([[
array x = ({ "", "--a" });
Getopt.find_option( x, "x", "b" );
return x;
]],[[ ({ "", "--a" }) ]])
test_any_equal([[
array x = ({ "", "--a", "hej" });
Getopt.find_option( x, "x", "a", 0, "b" );
return x;
]],[[ ({ "", 0, 0 }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
Getopt.find_option( x, "a" );
return x;
]],[[ ({ "", "-b" }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
Getopt.find_option( x, "b" );
return x;
]],[[ ({ "", "-a" }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
Getopt.find_option( x, "a", 0, 0, "y" );
return x;
]],[[ ({ "", 0 }) ]])
test_any_equal([[
array x = ({ "", "-", "-abc" });
Getopt.find_option( x, "b" );
return x;
]],[[ ({ "", "-", "-ac" }) ]])
test_any_equal([[
array x = ({ "", "-ab", "c" });
Getopt.find_option( x, "b", 0, 0, "y" );
return x;
]],[[ ({ "", "-a", 0 }) ]])
test_eq( Getopt.find_option(({}),({"a","b"}),({"c","d"}), 0, "e" ), "e")
test_eq( Getopt.find_option(({}),({"a","b"}),({"c","d"}), "foo", "e" ), "bar")
test_eq( Getopt.find_option(({}),({"a","b"}),({"c","d"}), "foo" ), "bar")
test_eq( Getopt.find_option(({}),({"a","b"}),({"c","d"}), ({"x","foo"}) ), "bar")
test_eq( Getopt.find_option(({}),({"a","b"}),({"c","d"}), "x", "e" ), "e")
|
631757 | 2002-11-17 | Martin Nilsson | | test_equal( Getopt.get_args( ({}) ), ({}) )
|
26a195 | 2002-11-15 | Martin Nilsson | | test_equal( Getopt.get_args(({ "x",0,0,1,"y",0,"z" })), "xyz"/1 )
test_eval_error( Getopt.get_args(({ "x", "-a" }), 0, 1) )
test_equal( Getopt.get_args(({ "-a", 0, "a"})), ({ "-a", "a" }) )
test_eval_error( Getopt.get_args(({ "x", "--a" }), 0, 1) )
test_equal( Getopt.get_args(({ "x", "--", "--a" })), ({ "x", "--a" }) )
test_equal( Getopt.get_args(({ "x", "-" })), ({ "x", "-" }) )
test_eval_error( Getop.get_args(({ "x", "a", "-b" }), 0, 1) )
test_equal( Getopt.get_args(({ "x", "a", "-b" }), 1, 1), ({ "x", "a", "-b" }))
test_equal( Getopt.get_args(({ "x", "ab", "-b" }), 1, 1), ({ "x", "ab", "-b" }))
|
48f249 | 2003-01-02 | Martin Nilsson | | test_eval_error( Getopt.get_args(({ "x", 0, "-b" }), 1, 1))
|
26a195 | 2002-11-15 | Martin Nilsson | | test_eval_error( Getopt.get_args(({ "x", "-a" }), 1, 1))
test_do( add_constant("opt", lambda(array x, array y, mixed ... z) {
return Getopt.find_all_options(x, ({ y }), @z); }); )
|
631757 | 2002-11-17 | Martin Nilsson | | test_equal( Getopt.find_all_options( ({}), ({}) ), ({}) )
|
26a195 | 2002-11-15 | Martin Nilsson | | test_equal( opt( "-a,-b"/",", ({ "a", Getopt.NO_ARG, "-a" }) ), ({}) )
test_equal( opt( "-a,--b"/",", ({ "a", Getopt.NO_ARG, "-b" }) ), ({}) )
test_equal( opt( "-a,-b"/",", ({ "b", Getopt.NO_ARG, "-b" }) ),
({ ({ "b", 1 }) }) )
test_equal( opt( "-a,-ab"/",", ({ "b", Getopt.NO_ARG, "-b" }) ),
({ ({ "b", 1 }) }) )
test_equal( opt( ",-,-a"/",", ({ "a", Getopt.NO_ARG, "-a" }) ),
({ ({ "a", 1 }) }) ) )
test_equal( opt( ",--,-a"/",", ({ "a", Getopt.NO_ARG, "-a" }) ), ({}) )
test_equal( opt( ",-b,-A"/",", ({ "a", Getopt.NO_ARG, "-a-A"/2 }) ),
({ ({ "a", 1 }) }) )
test_equal( Getopt.find_all_options( ",-a,-b"/",",
({ ({ "a", Getopt.NO_ARG, "-a" }), ({ "b", Getopt.NO_ARG, "-b" }) })),
({ ({ "a", 1 }), ({ "b", 1 }) }) )
test_equal( opt( "--a,--b"/",", ({ "a", Getopt.NO_ARG, "--a" }) ), ({}) )
test_equal( opt( "--a,--b"/",", ({ "b", Getopt.NO_ARG, "--b" }) ),
({ ({ "b", 1 }) }) )
test_equal( opt( "--a,--b=c"/",", ({ "b", Getopt.NO_ARG, "--b" }) ),
({ ({ "b", "c" }) }) )
test_equal( opt( ",-,--a"/",", ({ "a", Getopt.NO_ARG, "--a" }) ),
({ ({ "a", 1 }) }) ) )
test_equal( opt( ",--,--a"/",", ({ "a", Getopt.NO_ARG, "--a" }) ), ({}) )
test_equal( opt( ",--b,--A"/",", ({ "a", Getopt.NO_ARG, "--a--A"/3 }) ),
({ ({ "a", 1 }) }) )
test_equal( Getopt.find_all_options( ",--a,--b"/",",
({ ({ "a", Getopt.NO_ARG, "--a" }), ({ "b", Getopt.NO_ARG, "--b" }) })),
({ ({ "a", 1 }), ({ "b", 1 }) }) )
test_equal( opt( "-a,-b"/",", ({ "a", Getopt.MAY_HAVE_ARG, "-a" }) ), ({}) )
test_equal( opt( "-a,-b"/",", ({ "b", Getopt.MAY_HAVE_ARG, "-b" }) ),
({ ({ "b", 1 }) }) )
test_equal( opt( "-a,-b,c"/",", ({ "b", Getopt.MAY_HAVE_ARG, "-b" }) ),
({ ({ "b", 1 }) }) )
test_equal( opt( "-a,-bc"/",", ({ "b", Getopt.MAY_HAVE_ARG, "-b" }) ),
({ ({ "b", "c" }) }) )
test_equal( opt( "--a,--b"/",", ({ "a", Getopt.MAY_HAVE_ARG, "--a" }) ), ({}) )
test_equal( opt( "--a,--b,d"/",", ({ "b", Getopt.MAY_HAVE_ARG, "--b" }) ),
({ ({ "b", 1 }) }) )
test_equal( opt( "--a,--b=c,d"/",", ({ "b", Getopt.MAY_HAVE_ARG, "--b" }) ),
({ ({ "b", "c" }) }) )
test_equal( opt( "-a,-b"/",", ({ "a", Getopt.HAS_ARG, "-a" }) ), ({}) )
test_eval_error( opt( "-a,-b"/",", ({ "b", Getopt.HAS_ARG, "-b" }), 0, 1 ) )
test_equal( opt( "-a,-b,c"/",", ({ "b", Getopt.HAS_ARG, "-b" }) ),
({ ({ "b", "c" }) }) )
test_equal( opt( "-a,-bc,d"/",", ({ "b", Getopt.HAS_ARG, "-b" }) ),
({ ({ "b", "c" }) }) )
test_equal( opt( "--a,--b"/",", ({ "a", Getopt.HAS_ARG, "--a" }) ), ({}) )
test_eval_error( opt( "--a,--b"/",", ({ "b", Getopt.HAS_ARG, "--b" }), 0, 1 ) )
test_equal( opt( "--a,--b,d"/",", ({ "b", Getopt.HAS_ARG, "--b" }) ),
({ ({ "b", "d" }) }) )
test_equal( opt( "--a,--b=c,d"/",", ({ "b", Getopt.HAS_ARG, "--b" }) ),
({ ({ "b", "c" }) }) )
test_any_equal([[
array x = ({ "", "--a" });
opt( x, ({ "x", Getopt.NO_ARG, "--a" }) );
return x;
]],[[ ({ "", 0 }) ]])
test_any_equal([[
array x = ({ "", "--a" });
opt( x, ({ "x", Getopt.NO_ARG, "--b" }) );
return x;
]],[[ ({ "", "--a" }) ]])
test_any_equal([[
array x = ({ "", "--a", "hej" });
opt( x, ({ "x", Getopt.HAS_ARG, "--a" }) );
return x;
]],[[ ({ "", 0, 0 }) ]])
test_any_equal([[
array x = ({ "", "--a", "hej" });
opt( x, ({ "x", Getopt.MAY_HAVE_ARG, "--a" }) );
return x;
]],[[ ({ "", 0, "hej" }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
opt( x, ({ "x", Getopt.NO_ARG, "-a" }) );
return x;
]],[[ ({ "", "-b" }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
opt( x, ({ "x", Getopt.MAY_HAVE_ARG, "-a" }) );
return x;
]],[[ ({ "", 0 }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
opt( x, ({ "x", Getopt.NO_ARG, "-b" }) );
return x;
]],[[ ({ "", "-a" }) ]])
test_any_equal([[
array x = ({ "", "-ab" });
opt( x, ({ "x", Getopt.HAS_ARG, "-a" }) );
return x;
]],[[ ({ "", 0 }) ]])
test_any_equal([[
array x = ({ "", "-", "-abc" });
opt( x, ({ "x", Getopt.NO_ARG, "-b" }) );
return x;
]],[[ ({ "", "-", "-ac" }) ]])
test_any_equal([[
array x = ({ "", "-ab", "c" });
opt( x, ({ "x", Getopt.HAS_ARG, "-b" }) );
return x;
]],[[ ({ "", "-a", 0 }) ]])
test_any_equal([[
array x = ({ "", "-ab", "c", "--x", "x" });
Getopt.find_all_options( x, ({
({ "x", Getopt.HAS_ARG, "-b" }),
({ "y", Getopt.NO_ARG, "-a" }),
({ "z", Getopt.HAS_ARG, "--x" }) }) );
return x;
]],[[ ({ "", 0, 0, 0, 0 }) ]])
|
35c87a | 2003-02-26 | Martin Stjernholm | | test_any_equal([[
array x = ({"program", "-M", ".", "-e", "x"});
Getopt.find_all_options(
x, ({
({"M", Getopt.HAS_ARG, "-M", 0, 0}),
({"e", Getopt.HAS_ARG, "-e", 0, 0}),
}), 1);
return x;
]], ({"program", 0, 0, 0, 0}))
|
26a195 | 2002-11-15 | Martin Nilsson | |
test_equal( opt( ({}), ({ "a", Getopt.MAY_HAVE_ARG, "-a", 0, "e" }) ),
({ }) )
test_equal( opt( ({"","-a"}), ({ "a", Getopt.MAY_HAVE_ARG, "-a", 0, "e" }) ),
({ ({ "a", "e" }) }) )
test_equal( opt( ({"","--a"}), ({ "a", Getopt.MAY_HAVE_ARG, "--a", 0, "e" }) ),
({ ({ "a", "e" }) }) )
test_equal( opt( ({}), ({ "a", Getopt.HAS_ARG, "-a", "foo" }) ),
({ ({ "a", "bar" }) }) )
test_equal( opt( ({}), ({ "a", Getopt.HAS_ARG, "-a", ({ "x", "foo" }) }) ),
({ ({ "a", "bar" }) }) )
test_equal( Getopt.get_args(({ "x", "a", "-b" }), 1, 1), ({ "x", "a", "-b" }))
test_any_equal([[
array x = ({ "x", "a", "-b" });
opt(x, ({ "y", Getopt.HAS_ARG, "-b" }), 1 );
return x;
]],[[ ({ "x", "a", "-b" }) ]])
test_do( putenv("POSIX_ME_HARDER", "1"); )
|
d7db96 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_eq( getenv("POSIX_ME_HARDER"), "1")
|
26a195 | 2002-11-15 | Martin Nilsson | | test_eval_error( Getop.get_args(({ "x", "a", "-b" }), -1, 1) )
|
4661b5 | 2002-11-16 | Henrik Grubbström (Grubba) | | test_equal( Getopt.get_args(({ "x", "a", "-b" }), 0, 1), ({ "x", "a", "-b" }))
|
48f249 | 2003-01-02 | Martin Nilsson | | test_eval_error( Getopt.get_args(({ "x", 0, "-b" }), 0, 1))
|
854a76 | 2002-11-17 | Henrik Grubbström (Grubba) | | test_eval_error( opt( ({"x","a","-b"}), ({"y",Getopt.HAS_ARG,"-b"}), -1, 1 ))
|
26a195 | 2002-11-15 | Martin Nilsson | | test_any_equal([[
array x = ({ "x", "a", "-b" });
|
4661b5 | 2002-11-16 | Henrik Grubbström (Grubba) | | opt(x, ({ "y", Getopt.HAS_ARG, "-b" }), 0, 1 );
|
26a195 | 2002-11-15 | Martin Nilsson | | return x;
]],[[ ({ "x", "a", "-b" }) ]])
test_any_equal([[
array x = ({ "x", "a", "-b" });
|
afd927 | 2002-11-15 | Henrik Grubbström (Grubba) | | opt(x, ({ "y", Getopt.HAS_ARG, "-b" }), 1, 1);
|
26a195 | 2002-11-15 | Martin Nilsson | | return x;
]],[[ ({ "x", "a", "-b" }) ]])
dnl cleanup
|
2cdaf9 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do( putenv("POSIX_ME_HARDER", original_POSIX_ME_HARDER); )
|
9677b1 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do( putenv("foo", original_foo); )
|
2cdaf9 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do( add_constant("original_POSIX_ME_HARDER"); )
|
9677b1 | 2004-07-14 | Henrik Grubbström (Grubba) | | test_do( add_constant("original_foo"); )
|
26a195 | 2002-11-15 | Martin Nilsson | | test_do( add_constant("opt"); )
|
cccc64 | 2003-04-29 | Martin Nilsson | | dnl - Int
test_eq( Int.parity(0), 0 )
test_eq( Int.parity(1), 1 )
test_eq( Int.parity(2), 1 )
test_eq( Int.parity(3), 0 )
test_eq( Int.parity(4), 1 )
test_eq( Int.parity(6), 0 )
test_eq( Int.parity(7), 1 )
|
f1fbf8 | 2004-03-15 | Martin Nilsson | | test_eq( Int.swap_word(array_sscanf("\1\2", "%2c")[0]),
array_sscanf("\2\1", "%2c")[0])
test_eq( Int.swap_long(array_sscanf("\1\2\3\4", "%4c")[0]),
array_sscanf("\4\3\2\1", "%4c")[0])
|
937007 | 2002-10-14 | Martin Nilsson | | dnl - Mapping
dnl Mapping.delete
|
365b3c | 2016-03-10 | Martin Nilsson | |
test_eq( sizeof(Mapping.Iterator(([1:2,3:4]))), 2 )
|
937007 | 2002-10-14 | Martin Nilsson | |
|
4630c0 | 2009-11-10 | Henrik Grubbström (Grubba) | | test_do([[
// Test for [bug 5085].
|
8a307c | 2009-11-10 | Henrik Grubbström (Grubba) | | for (int i=0; i < 100; i++) {
|
4630c0 | 2009-11-10 | Henrik Grubbström (Grubba) | | // The following line trigged the bug 33% of the time.
|
d7fdf7 | 2016-03-09 | Martin Nilsson | | get_iterator(([1:1]))->_random(random_string, random);
|
4630c0 | 2009-11-10 | Henrik Grubbström (Grubba) | | }
]])
|
de9312 | 2009-11-09 | Martin Stjernholm | |
|
70ca44 | 2016-03-12 | Martin Nilsson | | test_do(add_constant("random",Random.Deterministic(17)->random))
test_any_equal([[
string r = "";
for(int i; i<5; i++)
|
c6d0d1 | 2016-03-14 | Martin Nilsson | | {
int n;
|
70ca44 | 2016-03-12 | Martin Nilsson | | foreach(random(Mapping.Iterator(([1:"1",2:"2",3:"3"])));; string v)
|
c6d0d1 | 2016-03-14 | Martin Nilsson | | n++;
r += n;
}
|
70ca44 | 2016-03-12 | Martin Nilsson | | return r;
|
b54d9e | 2016-03-15 | Martin Nilsson | | ]], "11312")
|
70ca44 | 2016-03-12 | Martin Nilsson | | test_do(add_constant("random",Random.System()->random))
|
937007 | 2002-10-14 | Martin Nilsson | | dnl - Multiset
|
365b3c | 2016-03-10 | Martin Nilsson | |
test_eq( sizeof(Multiset.Iterator((<1,2,3>))), 3 )
|
ee1317 | 2003-08-10 | Martin Nilsson | |
|
70ca44 | 2016-03-12 | Martin Nilsson | | test_do(add_constant("random",Random.Deterministic(17)->random))
test_any_equal([[
string r = "";
for(int i; i<5; i++)
|
c6d0d1 | 2016-03-14 | Martin Nilsson | | {
int n;
|
70ca44 | 2016-03-12 | Martin Nilsson | | foreach(random(Multiset.Iterator((<2,4,6,8,9>))); int v;)
|
c6d0d1 | 2016-03-14 | Martin Nilsson | | n++;
r += n;
}
|
70ca44 | 2016-03-12 | Martin Nilsson | | return r;
|
c6d0d1 | 2016-03-14 | Martin Nilsson | | ]], "31443")
|
70ca44 | 2016-03-12 | Martin Nilsson | | test_do(add_constant("random",Random.System()->random))
|
ee1317 | 2003-08-10 | Martin Nilsson | | dnl - Process
test_equal([[Process.split_quoted_string("test ")]],[[({"test"})]])
test_equal([[Process.split_quoted_string("'test'")]],[[({"test"})]])
test_equal([[Process.split_quoted_string("foo 'test' bar")]],[[({"foo","test","bar"})]])
|
aa1e5f | 2009-07-11 | Martin Stjernholm | | test_equal([[Process.split_quoted_string ("\\\"")]],
[[({"\""})]])
test_equal([[Process.split_quoted_string ("\\a")]],
[[({"a"})]])
test_equal([[Process.split_quoted_string ("\\ ")]],
[[({" "})]])
test_equal([[Process.split_quoted_string ("x\\")]],
[[({"x"})]])
test_equal([[Process.split_quoted_string ("\"\\\"foo bar\"")]],
[[({"\"foo bar"})]])
test_equal([[Process.split_quoted_string ("\"\"foo bar\"")]],
[[({"foo", "bar"})]])
|
64a10e | 2009-07-11 | Martin Stjernholm | | test_equal([[Process.split_quoted_string (" \t\n\r a \t\n\r b \t\n\r ")]],
[[({"a", "b"})]])
test_equal([[Process.split_quoted_string ("")]],
[[({})]])
test_equal([[Process.split_quoted_string ("\"\"")]],
[[({""})]])
test_equal([[Process.split_quoted_string ("''")]],
[[({""})]])
test_equal([[Process.split_quoted_string ("a '' \"\" b")]],
[[({"a", "", "", "b"})]])
test_equal([[Process.split_quoted_string ("\\")]],
[[({})]])
test_equal([[Process.split_quoted_string ("\\\\")]],
[[({"\\"})]])
test_equal([[Process.split_quoted_string ("\\\\", 1)]],
[[({"\\"})]])
test_equal([[Process.split_quoted_string ("\"")]],
[[({""})]])
test_equal([[Process.split_quoted_string ("'")]],
[[({""})]])
test_equal([[Process.split_quoted_string ("\"\\\"'\\x\"")]],
[[({"\"'\\x"})]])
test_equal([[Process.split_quoted_string ("'\"\\'\\x'")]],
[[({"\"\\x"})]])
test_equal([[Process.split_quoted_string ("\"a \t\n\rb\"")]],
[[({"a \t\n\rb"})]])
test_equal([[Process.split_quoted_string ("a\"b\"\'c\'")]],
[[({"abc"})]])
test_equal([[Process.split_quoted_string ("a\\ b")]],
[[({"a b"})]])
test_equal([[Process.split_quoted_string ("\\a\\b")]],
[[({"ab"})]])
test_equal([[Process.split_quoted_string ("\\a\\b", 1)]],
[[({"\\a\\b"})]])
test_equal([[Process.split_quoted_string ("\0")]],
[[({"\0"})]])
test_equal([[Process.split_quoted_string ("\0q\0p\0\0r\0")]],
[[({"\0q\0p\0\0r\0"})]])
test_equal([[Process.split_quoted_string ("\"\0\"")]],
[[({"\0"})]])
test_equal([[Process.split_quoted_string ("\"\0q\0p\0\0r\0\"")]],
[[({"\0q\0p\0\0r\0"})]])
test_equal([[Process.split_quoted_string ("'\0'")]],
[[({"\0"})]])
test_equal([[Process.split_quoted_string ("'\0q\0p\0\0r\0'")]],
[[({"\0q\0p\0\0r\0"})]])
test_equal([[Process.split_quoted_string ("\"\\\"")]],
[[({"\""})]])
test_equal([[Process.split_quoted_string ("\"\\")]],
[[({"\\"})]])
test_equal([[Process.split_quoted_string ("\"\\\0")]],
[[({"\\\0"})]])
test_equal([[Process.split_quoted_string ("\"a\\bc")]],
[[({"a\\bc"})]])
test_equal([[Process.split_quoted_string ("'a\\bc")]],
[[({"a\\bc"})]])
|
ee1317 | 2003-08-10 | Martin Nilsson | | test_equal([[Process.split_quoted_string("pike -m master.pike 'write(\"test\");'")]],[[({"pike","-m","master.pike","write(\"test\");"})]])
test_false([[
#ifdef __NT__
Process.system(RUNPIKE +" -e exit(0)")
#else /* !__NT__ */
Process.system(RUNPIKE +" -e 'exit(0)'")
#endif /* __NT__ */
]])
test_true([[
#ifdef __NT__
Process.system(RUNPIKE+" -e exit(1)")
#else /* !__NT__ */
Process.system(RUNPIKE+" -e 'exit(1)'")
#endif /* __NT__ */
]])
|
f1fde8 | 2011-03-05 | Martin Stjernholm | | test_any([[object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(2)"})); sleep(2); return p->wait()]],2)
|
ee1317 | 2003-08-10 | Martin Nilsson | | test_eq([[
#ifdef __NT__
Process.popen(RUNPIKE+" -e \"write(\\\"test\\\");\"")
#else /* !__NT__ */
Process.popen(RUNPIKE+" -e 'write(\"test\");'")
#endif /* __NT__ */
]],"test")
test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(5)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.Fd(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.Fd(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.Fd(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); o2=0; return p->wait()]],1)
test_any([[object o=Stdio.Fd(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(5)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.Fd(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.Fd(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.File(\"stdin\")->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.File(); object o2=o->pipe(); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.File(\"stdin\")->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_IPC); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o])); o2->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
test_any([[object o=Stdio.File(); object o2=o->pipe(Stdio.PROP_BIDIRECTIONAL); object p=Process.create_process(Process.split_quoted_string(RUNPIKE)+({"-e","exit(Stdio.stdin->read(1000)==\"hello\")"}),(["stdin":o2])); o->write("hello"); destruct(o); destruct(o2); return p->wait()]],1)
cond([[ file_stat("/bin/cat") && file_stat("/dev/null") && (cpp("__NT__")/"\n")[1]=="__NT__" ]],
[[
test_false(Process.create_process(({"/bin/cat","/dev/null"}))->wait());
test_false(Process.create_process(({"/bin/cat","/dev/null"}))->wait());
test_false(Process.create_process(({"/bin/cat","/dev/null"}))->wait());
|
352471 | 2015-05-26 | Martin Nilsson | |
|
ee1317 | 2003-08-10 | Martin Nilsson | | test_any([[
object o=Process.create_process(({"/bin/cat","/dev/null"}));
if(Process.create_process(({"/bin/cat","/dev/null"}))->wait()) return 99;
sleep(1);
return kill(o->pid(), 9);
]],0);
dnl Some OSs have a delay before PIDs are reused.
dnl Be nice, and let them reuse some.
test_do([[ sleep(2); ]]);
|
0903b6 | 2007-10-06 | Henrik Grubbström (Grubba) | | test_any([[
#ifdef DISABLE_SLOW_TESTS
return -1;
#endif
for(int x=0;x<10;x++) { for(int e=0;e<100;e++) if(Process.create_process(({"/bin/cat","/dev/null"}))->wait()) return e; __signal_watchdog(); } return -1;]],-1)
|
ee1317 | 2003-08-10 | Martin Nilsson | | ]])
cond([[ file_stat("/bin/cat") && file_stat("/dev/null") && all_constants()->thread_create && (cpp("__NT__")/"\n")[1]=="__NT__" ]],
[[
test_any([[
|
0903b6 | 2007-10-06 | Henrik Grubbström (Grubba) | | #ifdef DISABLE_SLOW_TESTS
return ({});
#endif
|
ee1317 | 2003-08-10 | Martin Nilsson | | return allocate(10, thread_create) (
lambda() {
for (int x=0; x<10; x++) {
for (int e=0; e<50; e++)
if (Process.create_process(({"/bin/cat","/dev/null"}))->wait())
return e;
__signal_watchdog();
}
return -1;
}
)->wait() - ({-1})]],({}))
]])
cond([[ file_stat("/bin/cat") && file_stat("/dev/null") && all_constants()->thread_create && (cpp("__NT__")/"\n")[1]=="__NT__" ]],
[[
test_do([[
|
0903b6 | 2007-10-06 | Henrik Grubbström (Grubba) | | #ifdef DISABLE_SLOW_TESTS
return 0;
#endif
|
ee1317 | 2003-08-10 | Martin Nilsson | | for(int q=0;q<100;q++)
{
array fnord=({});
Thread.Fifo fifo=Thread.Fifo();
for(int e=0;e<10;e++)
{
fnord+=({ thread_create(lambda() {
Process.create_process(({"/bin/cat","/dev/null"}));
fifo->read();
})
});
}
// for(int e=0;e<50;e++) Stdio.Port()->bind(0);
for(int e=0;e<10;e++) fifo->write(1);
fnord->wait();
__signal_watchdog();
}
]])
]])
cond([[ file_stat("/bin/sleep") && all_constants()->thread_create && (cpp("__NT__")/"\n")[1]=="__NT__" ]],
[[
test_any([[
class Fnord
{
int gnapp(int t)
{
|
0903b6 | 2007-10-06 | Henrik Grubbström (Grubba) | | #ifdef DISABLE_SLOW_TESTS
return -1;
#endif
|
ee1317 | 2003-08-10 | Martin Nilsson | | int e;
for(e=0;e<7;e++)
{
for(int d=0;d<150;d++)
{
object o=Process.create_process(({"/bin/sleep","99999"}));
kill( o->pid(), 9 );
o->wait();
__signal_watchdog();
}
|
452505 | 2015-05-23 | Henrik Grubbström (Grubba) | | if (gethostname() == "medaka")
werror("%s: %d:%d\n", __FILE__, t, e);
|
ee1317 | 2003-08-10 | Martin Nilsson | | }
return -1;
}
array start()
{
|
66a93f | 2015-07-31 | Henrik Grubbström (Grubba) | | if ((uname()->sysname == "Linux") &&
(< "3.15", "3.16", "3.17", "3.18">)[uname()->release[..3] ]) {
// This test trigers a kernel bug in Linux kernels 3.15 - 3.18
// introduced in commit b3ab03160dfaf8ab78d476b670de319f4c1a5685,
// and fixed in commit 3245d6acab981a2388ffb877c7ecc97e763c59d4.
return ({});
}
|
ee1317 | 2003-08-10 | Martin Nilsson | | array a=({});
for(int e=0;e<10;e++)
a+=({thread_create(gnapp,e)});
return a;
}
};
return Fnord()->start()->wait()-({ -1 });
]],[[ ({}) ]])
test_do([[
object proc = Process.create_process (({"/bin/sleep", "99999"}));
array threads = allocate (10, Thread.thread_create) (
lambda (object proc) {proc->wait();}, proc);
sleep (1);
proc->kill (9);
return threads->wait() - ({-1});
]], ({}))
]])
|
a42527 | 2004-04-21 | Martin Stjernholm | | cond([[all_constants()->thread_create]],
[[
test_any([[
int num_ok = 0;
Thread.Mutex m = Thread.Mutex();
Thread.MutexKey l = m->lock();
|
8c2e1d | 2004-05-01 | Martin Stjernholm | | void thread_fn()
|
a42527 | 2004-04-21 | Martin Stjernholm | | {
m->lock();
num_ok++;
};
array(Thread.Thread) t = (({Thread.thread_create}) * 5) (thread_fn);
sleep (0.5); // Make sure they are waiting for the lock.
destruct (m);
|
8c2e1d | 2004-05-01 | Martin Stjernholm | | l = 0;
sleep (0.5); // Wait for them to finish.
return num_ok;
]], 5)
|
a42527 | 2004-04-21 | Martin Stjernholm | | ]])
|
4bea98 | 2004-03-20 | Henrik Grubbström (Grubba) | | dnl - This test is disabled for now.
cond([[ 0 && __builtin->TraceProcess && (cpp("__NT__")/"\n")[1]=="__NT__" ]],
|
ee1317 | 2003-08-10 | Martin Nilsson | | [[
test_any([[
// Check that tracing works...
|
7c38af | 2003-10-16 | Henrik Grubbström (Grubba) | | // Spawn a /bin/dd that hangs on a read from a pipe connected to
|
72f767 | 2003-10-04 | Henrik Grubbström (Grubba) | | // this process, so that it will die of SIGPIPE if we die.
Stdio.File input_fd = Stdio.File();
|
ee1317 | 2003-08-10 | Martin Nilsson | | Process.TraceProcess proc =
|
87fbb0 | 2003-11-21 | Henrik Grubbström (Grubba) | | Process.TraceProcess(RUNPIKE_ARRAY + ({ "-e", "Stdio.stdin.read(1)" }), ([
|
05f38b | 2003-10-05 | Henrik Grubbström (Grubba) | | "stdin":input_fd->pipe(Stdio.PROP_IPC|Stdio.PROP_REVERSE),
|
72f767 | 2003-10-04 | Henrik Grubbström (Grubba) | | ]));
|
ee1317 | 2003-08-10 | Martin Nilsson | |
int initial_sleep = 5;
int count;
int state;
int code;
while (((code = proc->wait()) == -2) && (count++ < 20)) {
int sig = proc->last_signal();
switch(sig) {
case signum("TRAP"):
if (state) {
// NB: OSF/1 issues two SIGTRAPS before the program starts executing.
werror("Unexpected SIGTRAP in state %d.\n", state);
}
state = ((state <= 1) ? 1 : state);
proc->cont();
// Give it some time to settle down after initialization.
if (initial_sleep) {
sleep(initial_sleep);
initial_sleep=0;
}
// Check that we can block deadly signals.
proc->kill(signum("TERM"));
break;
case signum("TERM"):
if (state != 1) {
werror("Unexpected SIGTERM in state %d.\n", state);
}
state = ((state <= 2) ? 2 : state);
proc->cont(); // Ignore it...
// Check that we can make harmless signals deadly.
proc->kill(signum("CONT"));
break;
case signum("CONT"):
if (state != 2) {
werror("Unexpected SIGCONT in state %d.\n", state);
}
state = ((state <= 3) ? 3 : state);
proc->cont(signum("KILL")); // Make it a SIGKILL
sleep(5); // Give it some time to die and get reaped.
if (proc->kill(signum("KILL"))) {
return sprintf("Process didn't die of cont(%d).", signum("KILL"));
}
break;
default:
proc->kill(signum("KILL"));
return sprintf("Unexpected signal:%d in state %d.", sig, state);
}
}
if (code == -2) {
proc->kill(signum("KILL"));
return sprintf("Looping trace. (Looped %d times).", count-1);
}
if (code != -1) {
proc->kill(signum("KILL"));
return sprintf("Bad termination returncode from wait():%d (expected -1).",
code);
}
if (state != 3) {
return sprintf("Unexpected termination in state %d, signal %d.",
state, proc->last_signal());
}
int sig = proc->last_signal();
if (sig != signum("KILL")) {
proc->kill(signum("KILL"));
return sprintf("Unexpected termination signal:%d (expected %d).",
sig, signum("KILL"));
}
// Test ok.
return 0; ]], 0)
]])
test_do([[
string s;
for(s="foobar";strlen(s)<78;s+=s)
{
for(int e=0;e<strlen(s);e++)
{
s[e]++;
}
}
]])
|
d6b78d | 2004-05-02 | Martin Nilsson | |
|
1fbd78 | 2010-11-16 | Henrik Grubbström (Grubba) | | // Thread.Queue
test_do([[ add_constant("TestQueue", Thread.Queue()); ]])
test_any([[
int i;
for(i = 0; i < 10; i++) {
TestQueue->write(i);
}
return TestQueue->read();
]], 0)
test_eq([[ TestQueue->size() ]], 9)
test_equal([[ TestQueue->peek_array() ]], [[ ({ 1,2,3,4,5,6,7,8,9 }) ]])
test_eq([[ TestQueue->size() ]], 9)
test_equal([[ TestQueue->read_array() ]], [[ ({ 1,2,3,4,5,6,7,8,9 }) ]])
test_false([[ TestQueue->size() ]])
test_equal([[ TestQueue->peek_array() ]], [[ ({ }) ]])
test_equal([[ TestQueue->try_read_array() ]], [[ ({ }) ]])
test_false([[ TestQueue->size() ]])
test_true([[ zero_type(TestQueue->try_read()) ]])
test_do([[ add_constant("TestQueue"); ]])
|
a7201e | 2017-11-10 | Stephen R. van den Berg | | // Thread.ResourceCount
test_do([[ add_constant("TestResourceCount", Thread.ResourceCount()); ]])
test_any_equal([[
int i;
array a = allocate(10);
for(i = 0; i < 10; i++) {
a[i] = TestResourceCount->acquire();
}
for(i = 0; i < 10; i++) {
a[i] = 0;
a[i] = TestResourceCount->drained();
}
return a;
]], ({ 0,0,0,0,0,0,0,0,0,1 }))
test_do([[ add_constant("TestResourceCount"); ]])
|
e6a17f | 2016-04-27 | Martin Nilsson | | test_any([[
function a = lambda(string x) { return x+"a"; };
function b = lambda(string x) { return x+"b"; };
function q = Function.composite(a, b);
return map("123"/1, q)*"-";
]], "1ba-2ba-3ba")
|
d6b78d | 2004-05-02 | Martin Nilsson | | END_MARKER
|