Example #1
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}`");
     }
 }
Example #2
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");
        }
Example #3
0
 public void BadInput_Decode_LeadingSpacesBadValue() => Json4Get.Decode("  bad-json");
Example #4
0
 public void BadInput_Decode_LeadingSpaces() => Assert.AreEqual("{}", Json4Get.Decode("  ()"));
Example #5
0
 public void BadInput_Decode_EmptyOrWhiteSpace()
 {
     Assert.AreEqual(string.Empty, Json4Get.Decode(string.Empty));
     Assert.AreEqual(" ", Json4Get.Decode(" "));
     Assert.AreEqual("\n \t ", Json4Get.Decode("\n \t "));
 }