From e604ff307df17ea8600b1f39d613f972060b60c6 Mon Sep 17 00:00:00 2001 From: hungtu Date: Fri, 24 Feb 2017 22:19:53 +0100 Subject: [PATCH] #82 Allow uppercase at object and minor indent fix --- rivescript/parser.py | 4 ++-- rivescript/regexp.py | 1 + tests/test_format_message.py | 38 +++++++++++++++++++++--------------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/rivescript/parser.py b/rivescript/parser.py index 93973f5..951c39d 100644 --- a/rivescript/parser.py +++ b/rivescript/parser.py @@ -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, diff --git a/rivescript/regexp.py b/rivescript/regexp.py index 45ce8e3..5df6dc0 100644 --- a/rivescript/regexp.py +++ b/rivescript/regexp.py @@ -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*.+?=>.+?$') diff --git a/tests/test_format_message.py b/tests/test_format_message.py index 47fb68f..b21e625 100644 --- a/tests/test_format_message.py +++ b/tests/test_format_message.py @@ -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 - topic Greetings + + hello + - hi + object hash %perl - my ($rs, $args) = @_; - my $method = shift @{$args}; - object hash %perl + my ($rs, $args) = @_; + my $method = shift @{$args}; + object hash Perl + my ($rs, $args) = @_; + my $method = shift @{$args}; +