public void SourcePath_MakeParent(object[] items, string expectedString) { var path = new SourcePath(); foreach (var item in items) { if (item is int i) { path.AddArrayIndex(i); } else if (item is string s) { path.AddFieldName(s); } } var parent = path.MakeParent(); var result = parent.ArrayString(); Assert.AreEqual(expectedString, result); var origin = parent.AsOrigin(); Assert.AreEqual(parent, origin.Path); Assert.AreEqual(SourceLocation.None, origin.Location); }
public void SourceOrigin_NoLocation_PropertyCheck() { var path = new SourcePath(); path.AddFieldName("topField"); path.AddFieldName("middleField"); path.AddArrayIndex(0); var origin = new SourceOrigin(path); Assert.AreEqual(path, origin.Path); Assert.AreEqual(SourceLocation.None, origin.Location); }
public void SourceOrigin_WithBothParts_PropertyCheck() { var path = new SourcePath(); path.AddFieldName("topField"); path.AddFieldName("middleField"); path.AddArrayIndex(0); var location = new SourceLocation(5, 2, 1); var origin = new SourceOrigin(location, path); Assert.AreEqual(path, origin.Path); Assert.AreEqual(location, origin.Location); // prefer path over source text when available Assert.AreEqual(path.ToString(), origin.ToString()); }