From 7744defa1f8a5f1b54d8eb78657bd2c8d73df29f Mon Sep 17 00:00:00 2001
From: David Phillips <david@yeah.nah.nz>
Date: Sat, 4 Apr 2020 00:21:47 +1300
Subject: WIP: Start writing some plugin tests

---
 Mock/CommandRegistry.pm | 15 ++++++++++++
 Mock/IRC.pm             | 62 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 Mock/CommandRegistry.pm
 create mode 100644 Mock/IRC.pm

(limited to 'Mock')

diff --git a/Mock/CommandRegistry.pm b/Mock/CommandRegistry.pm
new file mode 100644
index 0000000..166879d
--- /dev/null
+++ b/Mock/CommandRegistry.pm
@@ -0,0 +1,15 @@
+package Mock::CommandRegistry;
+
+use strict;
+use warnings;
+
+use fields qw/commands/;
+
+sub new {
+	my ($class) = @_;
+	bless {}, $class;
+}
+
+sub register {
+	...
+}
diff --git a/Mock/IRC.pm b/Mock/IRC.pm
new file mode 100644
index 0000000..5c62754
--- /dev/null
+++ b/Mock/IRC.pm
@@ -0,0 +1,62 @@
+package Mock::IRC;
+
+use strict;
+use warnings;
+use Switch;
+
+use fields qw/_joined_channels _nick_name/;
+
+sub new {
+	my Mock::IRC $self = shift;
+	unless ($self) {
+		$self = fields::new($self);
+		$self->{_nick_name} = "";
+		$self->{_joined_channels} = [];
+	}
+
+	bless {}, $self;
+}
+
+###############################################################################
+# Methods used by code/plugins under test
+sub yield {
+	my ($self, $event, @data) = @_;
+	switch($event) {
+		case "join" {
+			my $channel = $data[0];
+			unless (grep {$_ eq $channel} @{$self->{_joined_channels}}) {
+				push @{$self->{_joined_channels}}, $channel;
+			}
+		}
+		case "part" {
+			# FIXME supports multi args?
+			my $channel = $data[0];
+			@{$self->{_joined_channels}} = grep {$_ ne $channel} @{$self->{_joined_channels}};
+		}
+		case "nick" {
+			($self->{_nick_name}) = @data;
+		}
+		else {
+			die "Unsupported event type: $event\n";
+		}
+	}
+}
+
+sub nick_name {
+	my ($self) = @_;
+	return $self->{_nick_name};
+}
+
+
+###############################################################################
+# Methods used test-side follow
+sub idalius_get_channels {
+	my ($self) = @_;
+	return @{$self->{_joined_channels}};
+}
+
+sub idalius_is_joined_to {
+	my ($self, $channel) = @_;
+	return grep {$_ eq $channel} @{$self->{_joined_channels}};
+}
+1;
-- 
cgit v1.1