Simplified the parsing code; all code paths of the configuration file store are now covered by tests

git-svn-id: file:///srv/devel/repo-conversion/nusu@307 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
Markus Ewald 2014-07-21 12:03:22 +00:00
parent 55b3ffd923
commit 03ada146e5
2 changed files with 10 additions and 10 deletions

View File

@ -239,18 +239,15 @@ namespace Nuclex.Support.Settings {
if(value.Count >= 2) {
int index = value.Offset;
if(ParserHelper.SkipInteger(value.Text, ref index)) {
if(index < value.Offset + value.Count) {
if(value.Text[index] == '.') {
return typeof(float);
}
if(index >= value.Offset + value.Count) {
return typeof(int);
}
if(value.Text[index] == '.') {
return typeof(float);
}
return typeof(int);
}
} else if(value.Count >= 1) { // If it's at least one character, it may be a number
int index = value.Offset;
ParserHelper.SkipNumericals(value.Text, ref index);
if(index > value.Offset) {
} else { // If it's just a single character, it may be a number
if(char.IsNumber(value.Text, value.Offset)) {
return typeof(int);
}
}

View File

@ -356,10 +356,13 @@ namespace Nuclex.Support.Settings {
/// </summary>
[
Test,
TestCase("nothing=", typeof(string)),
TestCase("text = world", typeof(string)),
TestCase("short=9", typeof(int)),
TestCase("integer = 123", typeof(int)),
TestCase("integer = 123 ", typeof(int)),
TestCase("string=x", typeof(string)),
TestCase("string = 123s", typeof(string)),
TestCase("float = 123.45", typeof(float)),
TestCase("float = 123.45 ", typeof(float)),
TestCase("boolean = true", typeof(bool)),