Skip to content

Commit

Permalink
aichaos#82 Allow uppercase at object and minor indent fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hungtu committed Feb 24, 2017
1 parent 9488582 commit e604ff3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions rivescript/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ def check_syntax(self, cmd, line):
if search:
return "Topics should be lowercased and contain only numbers and letters"
elif parts[0] == "object":
search = re.search(RE.name_syntax, line)
search = re.search(RE.obj_syntax, line) # Upper case is allowed
if search:
return "Objects can only contain numbers and letters" # TODO Acceptance of uppercase letter?
return "Objects can only contain numbers and letters"
elif cmd == '+' or cmd == '%' or cmd == '@':
# + Trigger, % Previous, @ Redirect
# This one is strict. The triggers are to be run through the regexp engine,
Expand Down
1 change: 1 addition & 0 deletions rivescript/regexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class RE(object):
array = re.compile(r'\@(.+?)\b')
def_syntax = re.compile(r'^.+(?:\s+.+|)\s*=\s*.+?$')
name_syntax = re.compile(r'[^a-z0-9_\-\s]')
obj_syntax = re.compile(r'[^A-Za-z0-9_\-\s]')
utf8_trig = re.compile(r'[A-Z\\.]')
trig_syntax = re.compile(r'[^a-z0-9(\|)\[\]*_#@{}<>=\s]')
cond_syntax = re.compile(r'^.+?\s*(?:==|eq|!=|ne|<>|<|<=|>|>=)\s*.+?=>.+?$')
Expand Down
38 changes: 22 additions & 16 deletions tests/test_format_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,28 @@ def test_format_triggers(self):

def test_invalid_character_raise_exception(self):
self.assertRaises(Exception, self.new, """
+ $hello
- hi
""") # This test passes with `match`, which only check at the beginning
+ $hello
- hi
""") # This test passes with `match`, which only check at the beginning
self.assertRaises(Exception, self.new, """
+ hello$
- hi
""") # This test does not pass because the beginning is good, no $
+ hello$
- hi
""") # This test does not pass because the beginning is good, no $
self.assertRaises(Exception, self.new, """
> topic Greetings
+ hello
- hi
<topics
""")
> topic Greetings
+ hello
- hi
<topics
""")
self.assertRaises(Exception, self.new, """
> object hash %perl
my ($rs, $args) = @_;
my $method = shift @{$args};
<object
""") # Test for character violation in object, no %
> object hash %perl
my ($rs, $args) = @_;
my $method = shift @{$args};
<object
""") # Test for character violation in object, no %
self.new("""
> object hash Perl
my ($rs, $args) = @_;
my $method = shift @{$args};
<object
""") # No exception raised for uppercase character in object

0 comments on commit e604ff3

Please sign in to comment.