Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use more strict rules for identifiers #25

Merged
merged 2 commits into from
Jul 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions rosidl_parser/rosidl_parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
'time', # for compatibility only
]

VALID_PACKAGE_NAME_PATTERN = re.compile('^[a-z][a-z0-9_]*$')
# TODO replace relaxed patterns used for compatibility
# VALID_FIELD_NAME_PATTERN = re.compile('^[a-z][a-z0-9_]*$')
VALID_FIELD_NAME_PATTERN = re.compile('^[A-Za-z][A-Za-z0-9_]*$')
# TODO replace relaxed patterns used for compatibility
# VALID_MESSAGE_NAME_PATTERN = re.compile('^[A-Z][A-Za-z0-9]*$')
VALID_MESSAGE_NAME_PATTERN = re.compile('^[A-Za-z][A-Za-z0-9]*$')
VALID_CONSTANT_NAME_PATTERN = re.compile('^[A-Z][A-Z0-9_]*$')
VALID_PACKAGE_NAME_PATTERN = re.compile('^[a-z]([a-z0-9_]?[a-z0-9]+)*$')
VALID_FIELD_NAME_PATTERN = re.compile('^[a-z]([a-z0-9_]?[a-z0-9]+)*$')
# relaxed patterns used for compatibility with ROS 1 messages
# VALID_FIELD_NAME_PATTERN = re.compile('^[A-Za-z][A-Za-z0-9_]*$')
VALID_MESSAGE_NAME_PATTERN = re.compile('^[A-Z][A-Za-z0-9]*$')
# relaxed patterns used for compatibility with ROS 1 messages
# VALID_MESSAGE_NAME_PATTERN = re.compile('^[A-Za-z][A-Za-z0-9]*$')
VALID_CONSTANT_NAME_PATTERN = re.compile('^[A-Z]([A-Z0-9_]?[A-Z0-9]+)*$')


class InvalidSpecification(Exception):
Expand Down
16 changes: 8 additions & 8 deletions rosidl_parser/test/test_valid_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@

def test_is_valid_package_name():
for valid_package_name in [
'foo']:
'foo', 'foo_bar']:
assert is_valid_package_name(valid_package_name)
for invalid_package_name in [
'foo-bar']:
'_foo', 'foo_', 'foo__bar', 'foo-bar']:
assert not is_valid_package_name(invalid_package_name)
with assert_raises(InvalidResourceName):
is_valid_package_name(None)


def test_is_valid_field_name():
for valid_field_name in [
'foo']:
'foo', 'foo_bar']:
is_valid_field_name(valid_field_name)
for invalid_field_name in [
'foo-bar']:
'_foo', 'foo_', 'foo__bar', 'foo-bar']:
assert not is_valid_field_name(invalid_field_name)
with assert_raises(InvalidResourceName):
is_valid_field_name(None)


def test_is_valid_message_name():
for valid_message_name in [
'Foo']:
'Foo', 'FooBar']:
assert is_valid_message_name(valid_message_name)
for invalid_message_name in [
'0foo']:
'0foo', '_Foo', 'Foo_', 'Foo_Bar']:
assert not is_valid_message_name(invalid_message_name)
with assert_raises(InvalidResourceName):
is_valid_message_name(None)


def test_is_valid_constant_name():
for valid_constant_name in [
'FOO']:
'FOO', 'FOO_BAR']:
assert is_valid_constant_name(valid_constant_name)
for invalid_constant_name in [
'Foo']:
'_FOO', 'FOO_', 'FOO__BAR', 'Foo']:
assert not is_valid_constant_name(invalid_constant_name)
with assert_raises(InvalidResourceName):
is_valid_constant_name(None)