File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed
Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -20,17 +20,16 @@ def scan_until(pattern)
2020 %x{
2121 var self = this;
2222
23-
2423 pattern = self.$anchor(pattern);
2524
2625 var pos = self.pos,
2726 working = self.working,
2827 result;
2928
3029 while (true) {
31- var isEmpty = working.length === 0;
32- result = pattern.exec(working);
33- pos += 1;
30+ var isEmpty = working.length === 0;
31+ result = pattern.exec(working);
32+ pos += 1;
3433 working = working.substr(1);
3534
3635 if (result == null) {
@@ -41,12 +40,11 @@ def scan_until(pattern)
4140 continue;
4241 }
4342
44- self.matched = self.string.substr(self.pos, pos - self.pos - 1 + result[0].length);
45- self.prev_pos = pos - 1;
46- self.pos = pos;
43+ self.prev_pos = self.pos;
44+ self.pos = pos + result[0].length - 1;
4745 self.working = working.substr(result[0].length - 1);
4846
49- return self.matched;
47+ return self.matched = self.string.substr(self.prev_pos, self.pos - self.prev_pos) ;
5048 }
5149 }
5250 end
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai' ;
2+ import DynamicLoader from './loader/dynamic_loader' ;
3+ import { I18n } from './internal' ;
4+ import { mockRandomizer } from './test/randomizer' ;
5+
6+ describe ( 'Choice command' , ( ) => {
7+ it ( 'keeps last item when multiple spaces between items' , async ( ) => {
8+ I18n . $clear_translate_table ( ) ;
9+ const loader = new DynamicLoader ( ) ;
10+ const GameSystemClass = await loader . dynamicLoad ( 'DiceBot' ) ;
11+ const gameSystem = new GameSystemClass ( 'choice 123 456 789' ) ;
12+
13+ const $random = mockRandomizer ( gameSystem ) ;
14+ $random . onCall ( 0 ) . returns ( 3 ) ;
15+ $random . onCall ( 1 ) . throwsException ( new Error ( 'Unexpected call for $random' ) ) ;
16+
17+ const res = gameSystem . eval ( ) ;
18+ expect ( res ?. text ) . to . equal ( '(choice 123 456 789) > 789' ) ;
19+ } ) ;
20+ } ) ;
You can’t perform that action at this time.
0 commit comments