Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] can't connect using non-directions

  • Loading branch information...
commit e0290f34333d4ff2cddeac09cf450bc2dd24c8ee 1 parent 0e3976e
Carl Mäsak authored July 04, 2012

Showing 1 changed file with 38 additions and 1 deletion. Show diff stats Hide diff stats

  1. 39  bin/crypt
39  bin/crypt
@@ -233,8 +233,28 @@ class Adventure::TwoRoomsConnected does Event {
233 233
     has $.direction;
234 234
 }
235 235
 
  236
+class X::Adventure is Exception {
  237
+}
  238
+
  239
+class X::Adventure::NoSuchDirection is X::Adventure {
  240
+    has $.action;
  241
+    has $.direction;
  242
+
  243
+    method message($_:) {
  244
+        qq[Cannot {.action}: direction "{.direction}" does not exist]
  245
+    }
  246
+}
  247
+
236 248
 class Adventure::Engine {
  249
+    my @possible_directions = <
  250
+        north south east west
  251
+        northeast northwest southeast southwest
  252
+    >;
  253
+
237 254
     method connect(@rooms, $direction) {
  255
+        die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
  256
+            unless $direction eq any(@possible_directions);
  257
+
238 258
         Adventure::TwoRoomsConnected.new(:@rooms, :$direction);
239 259
     }
240 260
 }
@@ -444,7 +464,24 @@ multi MAIN('test') {
444 464
                 :@rooms,
445 465
                 :$direction,
446 466
             ),
447  
-            'connecting two rooms';
  467
+            'connecting two rooms (+)';
  468
+    }
  469
+
  470
+    {
  471
+        my $engine = Adventure::Engine.new();
  472
+
  473
+        my $direction = 'oops';
  474
+        throws_exception
  475
+            { $engine.connect(<boat lawn>, $direction) },
  476
+            X::Adventure::NoSuchDirection,
  477
+            'connecting two rooms (-) no such direction',
  478
+            {
  479
+                is .action, 'connect rooms', '.action attribute';
  480
+                is .direction, $direction, '.direction attribute';
  481
+                is .message,
  482
+                    'Cannot connect rooms: direction "oops" does not exist',
  483
+                    '.message attribute';
  484
+            };
448 485
     }
449 486
 }
450 487
 

0 notes on commit e0290f3

Please sign in to comment.
Something went wrong with that request. Please try again.