private InterpreterConfiguration(Dictionary <string, object> properties) { Id = Read(properties, nameof(Id)); _description = Read(properties, nameof(Description)) ?? ""; InterpreterPath = Read(properties, nameof(InterpreterPath)); PathEnvironmentVariable = Read(properties, nameof(PathEnvironmentVariable)); LibraryPath = Read(properties, nameof(LibraryPath)); Architecture = InterpreterArchitecture.TryParse(Read(properties, nameof(Architecture))); try { Version = Version.Parse(Read(properties, nameof(Version))); } catch (Exception ex) when(ex is ArgumentException || ex is FormatException) { Version = new Version(); } if (properties.TryGetValue(nameof(SearchPaths), out object o)) { SearchPaths.Clear(); if (o is string s) { SearchPaths.AddRange(s.Split(';')); } else if (o is IEnumerable <string> ss) { SearchPaths.AddRange(ss); } } }
private InterpreterConfiguration(Dictionary <string, object> properties) { Id = Read(properties, nameof(Id)); _description = Read(properties, nameof(Description)) ?? ""; PrefixPath = Read(properties, nameof(PrefixPath)); InterpreterPath = Read(properties, nameof(InterpreterPath)); WindowsInterpreterPath = Read(properties, nameof(WindowsInterpreterPath)); PathEnvironmentVariable = Read(properties, nameof(PathEnvironmentVariable)); Architecture = InterpreterArchitecture.TryParse(Read(properties, nameof(Architecture))); try { Version = Version.Parse(Read(properties, nameof(Version))); } catch (ArgumentException) { Version = new Version(); } catch (FormatException) { Version = new Version(); } UIMode = 0; foreach (var bit in (Read(properties, nameof(UIMode)) ?? "").Split('|')) { InterpreterUIMode m; if (Enum.TryParse(bit, out m)) { UIMode |= m; } } if (properties.TryGetValue(nameof(SearchPaths), out object o)) { SearchPaths.Clear(); if (o is string s) { SearchPaths.AddRange(s.Split(';')); } else if (o is IEnumerable <string> ss) { SearchPaths.AddRange(ss); } } }
public void Exceptions() { var sp = new SearchPaths(); AssertEx.Equal(new string[0], sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws <ArgumentNullException>(() => sp.AddRange(null)); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws <ArgumentNullException>(() => sp.CopyTo(null, 0)); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws <ArgumentOutOfRangeException>(() => sp.Insert(10, "")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws <ArgumentOutOfRangeException>(() => sp.RemoveAt(-1)); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); }
public void Exceptions() { var sp = new SearchPaths(); AssertEx.Equal(Array.Empty<string>(), sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws<ArgumentNullException>(() => sp.AddRange(null)); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws<ArgumentNullException>(() => sp.CopyTo(null, 0)); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws<ArgumentOutOfRangeException>(() => sp.Insert(10, "")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); Assert.Throws<ArgumentOutOfRangeException>(() => sp.RemoveAt(-1)); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); }
public void ListOperations() { var sp = new SearchPaths(); AssertEx.Equal(Array.Empty<string>(), sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); sp.Add("foo"); AssertEx.Equal(new[] { "foo" }, sp.List.GetNewContent()); Assert.Equal(1, sp.List.Version); sp.AddRange(new[] { "bar" }); AssertEx.Equal(new[] { "foo", "bar" }, sp.List.GetNewContent()); Assert.Equal(2, sp.List.Version); sp.AddRange(new[] { "baz" }); AssertEx.Equal(new[] { "foo", "bar", "baz" }, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); Assert.True(sp.Contains("bar")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); var a = new string[sp.Count + 2]; Assert.Equal(3, sp.List.Version); AssertEx.Equal(null, sp.List.GetNewContent()); sp.CopyTo(a, 1); AssertEx.Equal(new[] { null, "foo", "bar", "baz", null }, a); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); AssertEx.Equal(new[] { "foo", "bar", "baz" }, sp); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); Assert.Equal(2, sp.IndexOf("baz")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); sp.Insert(1, "goo"); AssertEx.Equal(new[] { "foo", "goo", "bar", "baz" }, sp); AssertEx.Equal(new[] { "foo", "goo", "bar", "baz" }, sp.List.GetNewContent()); Assert.Equal(4, sp.List.Version); Assert.False(sp.IsReadOnly); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(4, sp.List.Version); Assert.True(sp.Remove("bar")); Assert.Equal(5, sp.List.Version); AssertEx.Equal(new[] { "foo", "goo", "baz" }, sp); AssertEx.Equal(new[] { "foo", "goo", "baz" }, sp.List.GetNewContent()); Assert.False(sp.Remove("___")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(5, sp.List.Version); sp.RemoveAt(1); AssertEx.Equal(new[] { "foo", "baz" }, sp); AssertEx.Equal(new[] { "foo", "baz" }, sp.List.GetNewContent()); Assert.Equal(6, sp.List.Version); sp.Clear(); AssertEx.Equal(Array.Empty<string>(), sp.List.GetNewContent()); Assert.Equal(7, sp.List.Version); sp.Clear(); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(7, sp.List.Version); }
public void ListOperations() { var sp = new SearchPaths(); AssertEx.Equal(new string[0], sp.List.GetNewContent()); Assert.Equal(0, sp.List.Version); sp.Add("foo"); AssertEx.Equal(new[] { "foo" }, sp.List.GetNewContent()); Assert.Equal(1, sp.List.Version); sp.AddRange(new[] { "bar" }); AssertEx.Equal(new[] { "foo", "bar" }, sp.List.GetNewContent()); Assert.Equal(2, sp.List.Version); sp.AddRange(new[] { "baz" }); AssertEx.Equal(new[] { "foo", "bar", "baz" }, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); Assert.True(sp.Contains("bar")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); var a = new string[sp.Count + 2]; Assert.Equal(3, sp.List.Version); AssertEx.Equal(null, sp.List.GetNewContent()); sp.CopyTo(a, 1); AssertEx.Equal(new[] { null, "foo", "bar", "baz", null }, a); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); AssertEx.Equal(new[] { "foo", "bar", "baz" }, sp); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); Assert.Equal(2, sp.IndexOf("baz")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(3, sp.List.Version); sp.Insert(1, "goo"); AssertEx.Equal(new[] { "foo", "goo", "bar", "baz" }, sp); AssertEx.Equal(new[] { "foo", "goo", "bar", "baz" }, sp.List.GetNewContent()); Assert.Equal(4, sp.List.Version); Assert.False(sp.IsReadOnly); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(4, sp.List.Version); Assert.True(sp.Remove("bar")); Assert.Equal(5, sp.List.Version); AssertEx.Equal(new[] { "foo", "goo", "baz" }, sp); AssertEx.Equal(new[] { "foo", "goo", "baz" }, sp.List.GetNewContent()); Assert.False(sp.Remove("___")); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(5, sp.List.Version); sp.RemoveAt(1); AssertEx.Equal(new[] { "foo", "baz" }, sp); AssertEx.Equal(new[] { "foo", "baz" }, sp.List.GetNewContent()); Assert.Equal(6, sp.List.Version); sp.Clear(); AssertEx.Equal(new string[0], sp.List.GetNewContent()); Assert.Equal(7, sp.List.Version); sp.Clear(); AssertEx.Equal(null, sp.List.GetNewContent()); Assert.Equal(7, sp.List.Version); }