예제 #1
0
 public void CompactifyEncode()
 {
     foreach (var test in Compactify)
     {
         var asGet = Json4Get.Encode(test.Original);
         Assert.AreEqual(test.Normal, asGet, $"trouble with:{test.Original}");
     }
 }
예제 #2
0
 public void SingleValuesEncodeLighter()
 {
     foreach (var test in SimpleValues.Where(s => s.NoQuote != null))
     {
         var json  = JsonConvert.SerializeObject(test.Original);
         var asGet = Json4Get.Encode(json, true);
         Assert.AreEqual(test.NoQuote, asGet, $"trouble with:{test.Original.Val}");
     }
 }
예제 #3
0
 public void SingleValuesEncode()
 {
     foreach (var test in SimpleValues)
     {
         var json  = JsonConvert.SerializeObject(test.Original);
         var asGet = Json4Get.Encode(json);
         Assert.AreEqual(test.Normal, asGet, $"trouble with:{test.Original.Val}");
     }
 }
예제 #4
0
 public void SingleValuesRecode()
 {
     foreach (var test in SimpleValues)
     {
         var json    = JsonConvert.SerializeObject(test.Original);
         var asGet   = Json4Get.Encode(json);
         var decoded = Json4Get.Decode(asGet);
         Assert.AreEqual(json, decoded, $"should be like the original `{test.Original.Val}`");
     }
 }
예제 #5
0
        public void BadInput_Encode_BadOpenCloseCount()
        {
            var badVariations = new[] { "{", "}", "{ { }", "\"value\":\"forgot-to-close" };

            foreach (var test in badVariations)
            {
                try
                {
                    // this line should throw an error
                    Json4Get.Encode(test);

                    // if it didn't throw yet, it's not ok - so throw special
                    Assert.Fail("not-ok-should-throw-before");
                }
                catch (Exception exception)
                {
                    if (exception.Message == "not-ok-should-throw-before")
                    {
                        throw;
                    }
                }
            }
        }
예제 #6
0
        public void EncodeRecodeObject()
        {
            var test = new
            {
                Key       = "something",
                Value     = "something else",
                SomeArray = new[] { "a string", "another string" },
                IntArr    = new[] { 7, 8, 8 },
                Is        = true,
                Isnt      = false,
                Null      = null as string
            };
            var expectedJson4Get = "('Key'!'something'*'Value'!'something_else'*"
                                   + "'SomeArray'!L'a_string'*'another_string'J*"
                                   + "'IntArr'!L7*8*8J*"
                                   + "'Is'!t*'Isnt'!f*'Null'!n)";
            var json   = JsonConvert.SerializeObject(test);
            var result = Json4Get.Encode(json);

            Assert.AreEqual(expectedJson4Get, result);
            var back = Json4Get.Decode(result);

            Assert.AreEqual(json, back, "convert back should work");
        }
예제 #7
0
 public void BadInput_Encode_LeadingSpacesBadValue() => Json4Get.Encode("  bad-json");
예제 #8
0
 public void BadInput_Encode_LeadingSpaces() => Assert.AreEqual("()", Json4Get.Encode("  {}"));
예제 #9
0
 public void BadInput_Encode_EmptyOrWhiteSpace()
 {
     Assert.AreEqual(string.Empty, Json4Get.Encode(string.Empty));
     Assert.AreEqual(" ", Json4Get.Encode(" "));
     Assert.AreEqual("\n \t ", Json4Get.Encode("\n \t "));
 }
예제 #10
0
 public void BadInput_Decode_Null()
 => Assert.IsNull(Json4Get.Encode(null));