Exemple #1
0
        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}\"", index, previous);
                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, Is.StringMatching("^(0x[0-9A-F]+)?$"), indicator);
                }
                else if (target.IsArray)
                {
                    Assert.That(result, Is.StringMatching(@"^\[\s*([0-9]+(,\s*[0-9]+)*)?\s*\]$"), indicator);
                }
                else if (target.IsDictionary)
                {
                    Assert.That(result, Is.StringMatching(@"^\{\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, Is.StringMatching("^(NaN|Infinity|-Infinity|(-?[0-9]+\\.[0-9]+(E(\\+|-)[0-9]+)?))$"), indicator);
                }
                else if (target.IsTypeOf <bool>().GetValueOrDefault())
                {
                    Assert.That(result, Is.StringMatching("^(True|False)$"), indicator);
                }
                else
                {
                    Assert.That(result, Is.StringMatching("^-?[0-9]+$"), indicator);
                }
            }
        }
 public static void ShouldMatch(this string actual, string pattern)
 {
     Assert.That(actual, Is.StringMatching(pattern));
 }
Exemple #3
0
 public static NUnit.Framework.Constraints.Constraint Match(string regex)
 {
     return(Is.StringMatching(regex));
 }