Skip to content

Commit 8f5d044

Browse files
committed
added tryparse to default an invalid weight to zero
1 parent 856821f commit 8f5d044

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Jump.Location.Specs/FileStoreProviderSpec.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public void It_can_Revive_multiple_records_of_correctly_formatted_text()
5454
db.Records.Count().ShouldEqual(3);
5555
}
5656

57+
[Fact]
58+
public void It_can_Revive_a_record_with_invalid_weight()
59+
{
60+
var lines = new[] {"INVALID_WEIGHT\tFS::C:\\blah"};
61+
File.WriteAllLines(path, lines);
62+
var provider = new FileStoreProvider(path);
63+
64+
var db = provider.Revive();
65+
db.Records.Count().ShouldEqual(1);
66+
db.Records.First().Weight.ShouldEqual(0M);
67+
db.Records.First().Path.ShouldEqual("C:\\blah");
68+
}
69+
5770
[Fact]
5871
public void It_skips_blank_and_empty_lines()
5972
{

Jump.Location/FileStoreProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public IDatabase Revive()
6767
if (columns == null || columns.Length != 2)
6868
throw new InvalidOperationException("Row of file didn't have 2 columns separated by a tab");
6969

70-
var weight = decimal.Parse(columns[0], CultureInfo.InvariantCulture);
70+
var weight = 0M;
71+
decimal.TryParse(columns[0], NumberStyles.Any, CultureInfo.InvariantCulture, out weight);
7172
var record = new Record(columns[1], weight);
7273
db.Add(record);
7374
}

0 commit comments

Comments
 (0)