summaryrefslogtreecommitdiff
path: root/test.pl
diff options
context:
space:
mode:
Diffstat (limited to 'test.pl')
-rwxr-xr-xtest.pl78
1 files changed, 78 insertions, 0 deletions
diff --git a/test.pl b/test.pl
new file mode 100755
index 0000000..870435c
--- /dev/null
+++ b/test.pl
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use AnyEvent;
+
+use_ok 'Tanja';
+
+
+# Simple matching tests.
+# (Doesn't test a whole lot, since the semantics aren't final yet anyway).
+ok Tanja::match([], []);
+ok Tanja::match([], [1, 2, 3]);
+ok Tanja::match([], [undef]);
+ok !Tanja::match([undef], []);
+ok Tanja::match([undef], [1]);
+ok Tanja::match([1], [1]);
+ok Tanja::match([1], [1, "b"]);
+ok Tanja::match([1], [undef, 3]);
+ok !Tanja::match([2], [1]);
+
+
+# Simple single-session test
+{
+ my $serv = Tanja::Server->new;
+ isa_ok $serv, 'Tanja::Server';
+ my $ses = $serv->session;
+ isa_ok $ses, 'Tanja::Session';
+ my $done = AnyEvent->condvar;
+ my $n = 0;
+ $ses->reg([], 0, sub {
+ my($t, $r) = @_;
+ is $r, undef;
+ is_deeply $t, [$n];
+ ok $n <= 5;
+ if(++$n == 5) {
+ $ses->close;
+ $done->send;
+ }
+ });
+ $ses->reg_once([undef], 0, sub {
+ my($t, $r) = @_;
+ is $r, undef;
+ is_deeply $t, [0];
+ });
+ $ses->send([$_]) for (0..10);
+ $done->recv;
+ is $n, 5;
+}
+
+
+# Simple double-session test
+{
+ my $serv = Tanja::Server->new;
+ my $a = $serv->session;
+ my $b = $serv->session;
+ my $done = AnyEvent->condvar;
+ $a->reg(["msg"], 0, sub {
+ my($t, $r) = @_;
+ is $r, undef;
+ is_deeply $t, ["msg", 'a'];
+ $a->send(["b"]);
+ });
+ $b->reg(["b"], 0, sub {
+ my($t, $r) = @_;
+ is $r, undef;
+ is_deeply $t, ["b"];
+ $done->send;
+ });
+ $b->send(["msg", 'a']);
+ $done->recv;
+}
+
+
+done_testing();
+
+# vim:noet:sw=4:ts=4