Debian Codegraph @

test/unit/test_strings_utility.py

raw symbols SCIP
1 # pyOCD debugger
2 # Copyright (c) 2021 Chris Reed
3 # SPDX-License-Identifier: Apache-2.0
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 from pyocd.utility.strings import (
18 uniquify_name,
19 )
20
21 class TestUniquifyName:
22 def test_empty_with_no_others(self):
23 assert uniquify_name('', []) == ''
24
25 def test_empty_with_others(self):
26 assert uniquify_name('', ['bar', 'buz']) == ''
27
28 def test_empty_with_another_empty(self):
29 assert uniquify_name('', ['bar', 'buz', '']) == '_1'
30
31 def test_no_others(self):
32 assert uniquify_name('foo', []) == 'foo'
33
34 def test_already_unique(self):
35 assert uniquify_name('foo', ['bar']) == 'foo'
36
37 def test_no_trailing_int(self):
38 assert uniquify_name('foo', ['foo']) == 'foo_1'
39
40 def test_1_trailing_int(self):
41 assert uniquify_name('foo1', ['foo1']) == 'foo2'
42
43 def test_multiple_trailing_ints(self):
44 assert uniquify_name('foo1', ['foo1', 'foo2']) == 'foo3'
45
46 def test_name_has_int(self):
47 assert uniquify_name('foo2', ['foo2', 'bar', 'foo3']) == 'foo4'
48
49 def test_multiple_ints_in_name(self):
50 assert uniquify_name('baz 2 monkey-3', ['fun', 'baz 2 monkey-3']) == 'baz 2 monkey-4'
51