private static void TestToStringCore(params MessagePackObject[] targets) { string previous = null; int index = -1; foreach (var target in targets) { index++; var result = target.ToString(); var indicator = String.Format("Index:{0}, Next to \"{1}\", '{2}'", index, previous, target.DebugDump()); previous = result; if (target.IsNil) { Assert.That(result, Is.Empty); } else if (target.IsRaw) { try { Assert.AreEqual(target.AsString(), result, indicator); continue; } catch (InvalidOperationException) { } Assert.That(result, Does.Match("^(0x[0-9A-F]+)?$"), indicator); } else if (target.IsArray) { Assert.That(result, Does.Match(@"^\[\s*([0-9]+(,\s*[0-9]+)*)?\s*\]$"), indicator); } else if (target.IsDictionary) { Assert.That(result, Does.Match(@"^\{\s*([0-9]+\s*:\s*[0-9]+(,\s*[0-9]+\s*:\s*[0-9]+)*)?\s*\}$"), indicator); } else if (target.IsTypeOf <float>().GetValueOrDefault() || target.IsTypeOf <double>().GetValueOrDefault()) { Assert.That(result, Does.Match("^(NaN|Infinity|-Infinity|(-?[0-9]+\\.[0-9]+(E(\\+|-)[0-9]+)?))$"), indicator); } else if (target.IsTypeOf <bool>().GetValueOrDefault()) { Assert.That(result, Does.Match("^(True|False)$"), indicator); } else { Assert.That(result, Does.Match("^-?[0-9]+$"), indicator); } } }