3030from rosidl_parser .definition import UnboundedSequence
3131from rosidl_parser .definition import UnboundedString
3232from rosidl_parser .definition import UnboundedWString
33+ from rosidl_parser .parser import get_ast_from_idl_string
34+ from rosidl_parser .parser import get_string_literals_value
3335from rosidl_parser .parser import parse_idl_file
3436
3537MESSAGE_IDL_LOCATOR = IdlLocator (
@@ -45,6 +47,38 @@ def message_idl_file():
4547 return parse_idl_file (MESSAGE_IDL_LOCATOR )
4648
4749
50+ def test_whitespace_at_start_of_string ():
51+ # Repeat to check ros2/rosidl#676
52+ for _ in range (10 ):
53+ ast = get_ast_from_idl_string ('const string foo = " e";' )
54+ token = next (ast .find_pred (lambda t : 'string_literals' == t .data ))
55+ assert ' e' == get_string_literals_value (token )
56+
57+
58+ def test_whitespace_at_start_of_wide_string ():
59+ # Repeat to check ros2/rosidl#676
60+ for _ in range (10 ):
61+ ast = get_ast_from_idl_string ('const wstring foo = L" e";' )
62+ token = next (ast .find_pred (lambda t : 'wide_string_literals' == t .data ))
63+ assert ' e' == get_string_literals_value (token , allow_unicode = True )
64+
65+
66+ def test_whitespace_at_end_of_string ():
67+ # Repeat to check ros2/rosidl#676
68+ for _ in range (10 ):
69+ ast = get_ast_from_idl_string ('const string foo = "e ";' )
70+ token = next (ast .find_pred (lambda t : 'string_literals' == t .data ))
71+ assert 'e ' == get_string_literals_value (token )
72+
73+
74+ def test_whitespace_at_end_of_wide_string ():
75+ # Repeat to check ros2/rosidl#676
76+ for _ in range (10 ):
77+ ast = get_ast_from_idl_string ('const wstring foo = L"e ";' )
78+ token = next (ast .find_pred (lambda t : 'wide_string_literals' == t .data ))
79+ assert 'e ' == get_string_literals_value (token , allow_unicode = True )
80+
81+
4882def test_message_parser (message_idl_file ):
4983 messages = message_idl_file .content .get_elements_of_type (Message )
5084 assert len (messages ) == 1
0 commit comments