public void Parse() { bool SequenceEqual(IEnumerable <KeyValuePair <string, string> > first, params string[] second) => first.Select(p => p.ToString()).SequenceEqual(second); Assert.True(SequenceEqual(ParamKeyValueParser.Parse("k1=v1"), "[k1, v1]")); Assert.True(SequenceEqual(ParamKeyValueParser.Parse("k1=v1,k2=v2"), "[k1, v1]", "[k2, v2]")); Assert.True(SequenceEqual(ParamKeyValueParser.Parse("k1=v1,,k2=v2"), "[k1, v1]", "[k2, v2]")); Assert.True(SequenceEqual(ParamKeyValueParser.Parse("k1=v1,k2=v2,k3=v3"), "[k1, v1]", "[k2, v2]", "[k3, v3]")); Assert.True(SequenceEqual(ParamKeyValueParser.Parse("key1-value1;key2-value2", ';', '-'), "[key1, value1]", "[key2, value2]")); }
public void ParsePair() { Assert.Equal("[key, value]", ParamKeyValueParser.ParsePair("key=value").ToString()); Assert.Equal("[key, val=ue]", ParamKeyValueParser.ParsePair("key=val=ue").ToString()); Assert.Equal("[k, v]", ParamKeyValueParser.ParsePair("k=v").ToString()); Assert.Equal("[k, ]", ParamKeyValueParser.ParsePair("k=").ToString()); Assert.Equal("[k, v]", ParamKeyValueParser.ParsePair("k,v", ',').ToString()); Assert.Throws <ArgumentNullException>(() => ParamKeyValueParser.ParsePair(null)); Assert.Throws <ArgumentException>(() => ParamKeyValueParser.ParsePair("")); Assert.Throws <ArgumentException>(() => ParamKeyValueParser.ParsePair("k")); Assert.Throws <ArgumentException>(() => ParamKeyValueParser.ParsePair("=v")); }