Changeset 217
- Timestamp:
- 06/08/05 05:32:01 (3 years ago)
- Location:
- branches/simplest-thing
- Files:
-
- 2 modified
-
lib/fm/verb.rb (modified) (2 diffs)
-
tests/verb.tests.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simplest-thing/lib/fm/verb.rb
r198 r217 39 39 SVNId = %q$Id$ 40 40 41 # SVN URL 42 SVNURL = %q$URL$ 41 42 ### Generate a default set of words for a verb which doesn't explicitly 43 ### provide them. 44 def self::generateWords 45 word = self.name. 46 sub( /^.*::/, ''). 47 sub( /(\w+)Verb/, "\\1" ). 48 downcase 49 return [word] 50 end 43 51 44 52 … … 47 55 ################################################################# 48 56 57 ### Set up the verb's internal structure 58 def initialize # :notnew: 59 super 60 @words = self.class.generateWords() 61 end 62 63 64 ###### 65 public 66 ###### 67 68 ### CommandParser interface: query the verb for the word/s which cause it to 69 ### be invoked. By default this returns the name of the verb class with the 70 ### 'verb' part removed. 71 attr_reader :words 72 73 49 74 ### Event interface: "run" the verb, generating the event/s necessary to 50 75 ### express the action in the game world. The given +instigator+, +origin+, 51 76 ### and +target+ will be used when building event/s. See 52 77 ### FaerieMUD::Event::new for definitions 53 def happen( instigator, origin, target=nil )78 def invoke( instigator, origin, target=nil ) 54 79 raise NotImplementedError, 55 "Required method # happennot implemented in %s" %80 "Required method #invoke not implemented in %s" % 56 81 [self.class.name] 57 82 end -
branches/simplest-thing/tests/verb.tests.rb
r191 r217 4 4 # $Id$ 5 5 # 6 # Copyright (c) 2004 The FaerieMUD Consortium.6 # Copyright (c) 2004, 2005 The FaerieMUD Consortium. 7 7 # 8 8 … … 26 26 class TestInstigator < FaerieMUD::GameObject; end 27 27 class TestOrigin < FaerieMUD::Locus; end 28 29 class TestVerb < FaerieMUD::Verb 30 31 end 32 28 33 29 34 def setup … … 56 61 57 62 ### Event-generation interface 58 def test_50_ happen59 printTestHeader "FaerieMUD::Verb: Event-generation interface "63 def test_50_invoke 64 printTestHeader "FaerieMUD::Verb: Event-generation interface: invoke" 60 65 rval = nil 61 66 … … 65 70 66 71 # Should require an instigator and an origin 67 assert_raises( ArgumentError ) { derivObj. happen}68 assert_raises( ArgumentError ) { derivObj. happen(@instigator) }72 assert_raises( ArgumentError ) { derivObj.invoke } 73 assert_raises( ArgumentError ) { derivObj.invoke(@instigator) } 69 74 70 # Derivative classes should override # happen75 # Derivative classes should override #invoke 71 76 assert_raises( NotImplementedError ) { 72 derivObj. happen( @instigator, @origin )77 derivObj.invoke( @instigator, @origin ) 73 78 } 74 79 end 80 81 82 ### CommandParser interface 83 def test_60_words 84 printTestHeader "FaerieMUD::Verb: CommandParser interface: words" 85 rval = nil 86 verb = TestVerb::instance 87 88 assert_nothing_raised do 89 rval = verb.words 90 end 91 92 assert_instance_of Array, rval 93 assert_equal 1, rval.length 94 assert_equal 'test', rval.first 95 end 96 97 75 98 end 76 99
