From fd7024343f2af07824f78b751f2d7d115cc7dee9 Mon Sep 17 00:00:00 2001 From: Genarito Date: Tue, 4 May 2021 22:16:52 -0300 Subject: [PATCH] + Version 0.2.4 + Fixed $ escaping + Added tests --- gura/GuraParser.py | 3 ++- gura/__init__.py | 2 +- tests/strings/test.py | 12 +++++++++--- tests/strings/tests-files/basic.ura | 1 + tests/strings/tests-files/literal.ura | 5 +++-- tests/strings/tests-files/multiline_basic.ura | 3 ++- tests/strings/tests-files/multiline_literal.ura | 3 ++- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gura/GuraParser.py b/gura/GuraParser.py index cbafb11..8eec3e5 100644 --- a/gura/GuraParser.py +++ b/gura/GuraParser.py @@ -629,7 +629,8 @@ def basic_string(self) -> str: 'r': '\r', 't': '\t', '"': '"', - '\\': '\\' + '\\': '\\', + '$': '$' } while True: diff --git a/gura/__init__.py b/gura/__init__.py index e81cf11..773452e 100644 --- a/gura/__init__.py +++ b/gura/__init__.py @@ -2,7 +2,7 @@ VariableNotDefinedError, DuplicatedImportError, loads, dumps from gura.Parser import ParseError -__version__ = "0.2.3" +__version__ = "0.2.4" loads = loads dumps = dumps diff --git a/tests/strings/test.py b/tests/strings/test.py index 759ba60..de9de20 100644 --- a/tests/strings/test.py +++ b/tests/strings/test.py @@ -16,10 +16,13 @@ class TestStringsGura(unittest.TestCase): def setUp(self): self.file_dir = os.path.dirname(os.path.abspath(__file__)) + escaped_value = '$name is cool' + self.expected_basic = { "str": "I'm a string. \"You can quote me\". Na\bme\tJos\u00E9\nLocation\tSF.", "str_2": "I'm a string. \"You can quote me\". Na\bme\tJos\U000000E9\nLocation\tSF.", "with_var": "Gura is cool", + "escaped_var": escaped_value, "with_env_var": "Gura is very cool" } @@ -36,20 +39,23 @@ def setUp(self): 'str_4': 'Here are two quotation marks: "". Simple enough.', 'str_5': 'Here are three quotation marks: """.', 'str_6': 'Here are fifteen quotation marks: """"""""""""""".', + "escaped_var": escaped_value, } self.expected_literal = { - 'quoted': 'Tom "Dubs" Preston-Werner', + 'quoted': 'John "Dog lover" Wick', 'regex': '<\\i\\c*\\s*>', 'winpath': 'C:\\Users\\nodejs\\templates', 'winpath2': '\\\\ServerX\\admin$\\system32\\', - 'with_var': '$no_parsed variable!' + 'with_var': '$no_parsed variable!', + "escaped_var": escaped_value } self.expected_multiline_literal = { 'lines': 'The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n', 'regex2': "I [dw]on't need \\d{2} apples", - 'with_var': '$no_parsed variable!' + 'with_var': '$no_parsed variable!', + "escaped_var": escaped_value } self.maxDiff = 4096 diff --git a/tests/strings/tests-files/basic.ura b/tests/strings/tests-files/basic.ura index 2887a99..4719636 100644 --- a/tests/strings/tests-files/basic.ura +++ b/tests/strings/tests-files/basic.ura @@ -3,4 +3,5 @@ $name: "Gura" str: "I'm a string. \"You can quote me\". Na\bme\tJos\u00E9\nLocation\tSF." str_2: "I'm a string. \"You can quote me\". Na\bme\tJos\U000000E9\nLocation\tSF." with_var: "$name is cool" +escaped_var: "\$name is cool" with_env_var: "$name is $env_var_value cool" # $env_var_value is defined in corresponding test.py \ No newline at end of file diff --git a/tests/strings/tests-files/literal.ura b/tests/strings/tests-files/literal.ura index 1a8f0a9..e99c781 100644 --- a/tests/strings/tests-files/literal.ura +++ b/tests/strings/tests-files/literal.ura @@ -1,6 +1,7 @@ # What you see is what you get. winpath: 'C:\Users\nodejs\templates' winpath2: '\\ServerX\admin$\system32\' -quoted: 'Tom "Dubs" Preston-Werner' +quoted: 'John "Dog lover" Wick' regex: '<\i\c*\s*>' -with_var: '$no_parsed variable!' \ No newline at end of file +with_var: '$no_parsed variable!' +escaped_var: '$name is cool' \ No newline at end of file diff --git a/tests/strings/tests-files/multiline_basic.ura b/tests/strings/tests-files/multiline_basic.ura index ac40926..3bcb9c5 100644 --- a/tests/strings/tests-files/multiline_basic.ura +++ b/tests/strings/tests-files/multiline_basic.ura @@ -31,4 +31,5 @@ str_with_backslash_2: """\ str_4: """Here are two quotation marks: "". Simple enough.""" str_5: """Here are three quotation marks: ""\".""" -str_6: """Here are fifteen quotation marks: ""\"""\"""\"""\"""\".""" \ No newline at end of file +str_6: """Here are fifteen quotation marks: ""\"""\"""\"""\"""\".""" +escaped_var: """\$name is cool""" \ No newline at end of file diff --git a/tests/strings/tests-files/multiline_literal.ura b/tests/strings/tests-files/multiline_literal.ura index 2fef53d..50ec1f9 100644 --- a/tests/strings/tests-files/multiline_literal.ura +++ b/tests/strings/tests-files/multiline_literal.ura @@ -5,4 +5,5 @@ trimmed in raw strings. All other whitespace is preserved. ''' -with_var: '''$no_parsed variable!''' \ No newline at end of file +with_var: '''$no_parsed variable!''' +escaped_var: '''$name is cool''' \ No newline at end of file