Debian Codegraph @

test/units/parsing/test_unquote.py

raw
1 # coding: utf-8
2 # (c) 2015, Toshio Kuratomi <[email protected]>
3 #
4 # This file is part of Ansible
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18
19 from __future__ import annotations
20
21 from ansible.parsing.quoting import unquote
22
23 import pytest
24
25 UNQUOTE_DATA = (
26 (u'1', u'1'),
27 (u'\'1\'', u'1'),
28 (u'"1"', u'1'),
29 (u'"1 \'2\'"', u'1 \'2\''),
30 (u'\'1 "2"\'', u'1 "2"'),
31 (u'\'1 \'2\'\'', u'1 \'2\''),
32 (u'"1\\"', u'"1\\"'),
33 (u'\'1\\\'', u'\'1\\\''),
34 (u'"1 \\"2\\" 3"', u'1 \\"2\\" 3'),
35 (u'\'1 \\\'2\\\' 3\'', u'1 \\\'2\\\' 3'),
36 (u'"', u'"'),
37 (u'\'', u'\''),
38 # Not entirely sure these are good but they match the current
39 # behaviour
40 (u'"1""2"', u'1""2'),
41 (u'\'1\'\'2\'', u'1\'\'2'),
42 (u'"1" 2 "3"', u'1" 2 "3'),
43 (u'"1"\'2\'"3"', u'1"\'2\'"3'),
44 )
45
46
47 @pytest.mark.parametrize("quoted, expected", UNQUOTE_DATA)
48 def test_unquote(quoted, expected):
49 assert unquote(quoted) == expected