Добавил возможность не указывать кавычки при указании значений в файле настроек
This commit is contained in:
parent
88b4de94c8
commit
f42e2fce3c
|
|
@ -7,9 +7,27 @@ class TestSettingsLineParser(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.parser = SettingsLineParser()
|
self.parser = SettingsLineParser()
|
||||||
|
|
||||||
def test_getPathAndValue(self):
|
def test_whiteSpaces(self):
|
||||||
line = "abc.123.some_name = 'crazy value ±~ ../ 123'"
|
self.checkPathAndValue("abc.123.some_name = 'crazy value ±~ ../ 123'", 'abc.123.some_name', 'crazy value ±~ ../ 123')
|
||||||
|
self.checkPathAndValue("a.b.c = 'value'", 'a.b.c', 'value')
|
||||||
|
self.checkPathAndValue("a.b.c= 'value'", 'a.b.c', 'value')
|
||||||
|
self.checkPathAndValue("a.b.c ='value'", 'a.b.c', 'value')
|
||||||
|
self.checkPathAndValue("a.b.c='value'", 'a.b.c', 'value')
|
||||||
|
|
||||||
|
def test_valueWithoutComma(self):
|
||||||
|
self.checkPathAndValue("a.b.c = value", 'a.b.c', 'value')
|
||||||
|
self.checkPathAndValue("a.b.c = some value", 'a.b.c', 'some value')
|
||||||
|
self.checkPathAndValue("a.b.c = some value ", 'a.b.c', 'some value')
|
||||||
|
|
||||||
|
def test_valueWithEscapeComma(self):
|
||||||
|
self.checkPathAndValue("a.b.c = '\"value\"' ", 'a.b.c', '"value"')
|
||||||
|
self.checkPathAndValue('a.b.c = "\'value\'" ', 'a.b.c', "'value'")
|
||||||
|
|
||||||
|
self.checkPathAndValue('a.b.c = ""value"" ', 'a.b.c', 'value')
|
||||||
|
self.checkPathAndValue("a.b.c = ''value'' ", 'a.b.c', 'value')
|
||||||
|
|
||||||
|
def checkPathAndValue(self, line, expectedPath, expectedValue):
|
||||||
result = self.parser.splitToPathAndValue(line)
|
result = self.parser.splitToPathAndValue(line)
|
||||||
|
|
||||||
self.assertEqual('abc.123.some_name', result[0])
|
self.assertEqual(expectedPath, result[0])
|
||||||
self.assertEqual('crazy value ±~ ../ 123', result[1])
|
self.assertEqual(expectedValue, result[1])
|
||||||
|
|
|
||||||
|
|
@ -27,17 +27,35 @@ class SettingsLineParser(LineParser):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def splitToPathAndValue(self, line):
|
def splitToPathAndValue(self, line):
|
||||||
|
# some.path = some_value
|
||||||
|
result = line.split('=')
|
||||||
|
|
||||||
propPathRegexp = r"^(?P<prop_path>[\w.]+)"
|
propPath = self.getPropertyPath(result[0])
|
||||||
valueRegexp = "'(?P<value>.*)'"
|
value = self.getValue(result[1])
|
||||||
|
|
||||||
regexpSource = propPathRegexp + r'\s*=\s*' + valueRegexp
|
return propPath, value
|
||||||
regexp = re.compile(regexpSource, re.UNICODE)
|
|
||||||
|
|
||||||
match = regexp.match(line)
|
def getPropertyPath(self, rawPropertyPath):
|
||||||
self._guardMatch(match, line, regexpSource)
|
assert rawPropertyPath is not None
|
||||||
|
stripped = rawPropertyPath.strip()
|
||||||
|
|
||||||
|
propPathRegexp = r"^(?P<prop_path>[\w.]+)$"
|
||||||
|
regexp = re.compile(propPathRegexp, re.UNICODE)
|
||||||
|
|
||||||
|
match = regexp.match(stripped)
|
||||||
|
self._guardMatch(match, stripped, propPathRegexp)
|
||||||
|
|
||||||
propPath = match.group('prop_path')
|
propPath = match.group('prop_path')
|
||||||
value = match.group('value')
|
return propPath
|
||||||
|
|
||||||
return propPath, value
|
def getValue(self, rawValue):
|
||||||
|
assert rawValue is not None
|
||||||
|
stripped = rawValue.strip()
|
||||||
|
|
||||||
|
old = stripped
|
||||||
|
stripped = stripped.strip("'")
|
||||||
|
|
||||||
|
if old == stripped:
|
||||||
|
stripped = stripped.strip('"')
|
||||||
|
|
||||||
|
return stripped
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# global settings
|
# global settings
|
||||||
build_tool = '/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool'
|
build_tool='/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool'
|
||||||
version = '0.0.0' # комментарий в тойже строке
|
version=0.0.0 # комментарий в тойже строке
|
||||||
configs = 'appstore, staging'
|
configs = 'appstore, staging'
|
||||||
|
|
||||||
# ios platform settings
|
# ios platform settings
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue