Skip to content

Commit

Permalink
add test coverage for substitution edgecases involving E notation
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel <[email protected]>
  • Loading branch information
danielcranston committed Feb 1, 2025
1 parent 1842725 commit e11ae22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions launch/test/launch/substitutions/test_equals_substitution.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ def _permute_assertion(left, right, context, output):
_permute_assertion('inf', '-inf', lc, 'false')
_permute_assertion('-inf', '-inf', lc, 'true')

# Numerics (scientific E notation)
_permute_assertion('1234e1', '12340', lc, 'true')
_permute_assertion('1234E2', '123400', lc, 'true')
_permute_assertion('1234E2', '1234E2', lc, 'true')
_permute_assertion("'1234E2'", '123400', lc, 'false')
_permute_assertion("'1234E2'", '1234E2', lc, 'false')
_permute_assertion("'1234E2'", "'1234E2'", lc, 'true')

# Strings
_permute_assertion('wow', 'wow', lc, 'true')
_permute_assertion('wow', True, lc, 'false')
Expand Down
5 changes: 5 additions & 0 deletions launch/test/launch/utilities/test_type_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def test_coercions_given_specific_type(coerce_to_type_impl):
assert coerce_to_type_impl("'off'", data_type=str) == "'off'"
assert coerce_to_type_impl("''1''", data_type=str) == "''1''"
assert coerce_to_type_impl('{1}', data_type=str) == '{1}'
assert coerce_to_type_impl("'1e1'", data_type=str) == "'1e1'"
assert coerce_to_type_impl("'1E1'", data_type=str) == "'1E1'"

assert coerce_to_type_impl('1', data_type=int) == 1
assert coerce_to_type_impl('1000', data_type=int) == 1000
Expand All @@ -230,6 +232,7 @@ def test_coercions_given_specific_type(coerce_to_type_impl):
assert coerce_to_type_impl('1000.0', data_type=float) == 1000.
assert coerce_to_type_impl('0.2', data_type=float) == .2
assert coerce_to_type_impl('.3', data_type=float) == 0.3
assert coerce_to_type_impl('2e1', data_type=float) == 20.0

assert coerce_to_type_impl('on', data_type=bool) is True
assert coerce_to_type_impl('off', data_type=bool) is False
Expand Down Expand Up @@ -543,6 +546,8 @@ def test_perform_typed_substitution():

assert perform_typed_substitution(lc, 1, int) == 1
assert perform_typed_substitution(lc, [TextSubstitution(text='1')], int) == 1
assert perform_typed_substitution(lc, [TextSubstitution(text='1e1')], float) == 10
assert perform_typed_substitution(lc, [TextSubstitution(text='1e1')], str) == '1e1'
assert perform_typed_substitution(
lc, [TextSubstitution(text='[1, 2, 3]')], List[int]) == [1, 2, 3]
assert perform_typed_substitution(
Expand Down

0 comments on commit e11ae22

Please sign in to comment.