Merge pull request #496 from nicolas-raoul/unit-test-for-issue2907
[mono.git] / mcs / class / System.Json / Test / System.Json / JsonValueTest.cs
1 //
2 // JsonValueTest.cs: Tests for JSonValue
3 //
4 // Copyright 2011 Xamarin, Inc.
5 //
6 // Authors:
7 //   Miguel de Icaza
8 //
9 using NUnit.Framework;
10 using System;
11 using System.IO;
12 using System.Text;
13 using System.Json;
14
15 namespace MonoTests.System
16 {
17         [TestFixture]
18         public class JsonValueTests {
19                 // Tests that a trailing comma is allowed in dictionary definitions
20                 [Test]
21                 public void LoadWithTrailingComma ()
22                 {
23                         var j = JsonValue.Load (new StringReader ("{ \"a\": \"b\",}"));
24                         Assert.AreEqual (1, j.Count, "itemcount");
25                         Assert.AreEqual (JsonType.String, j ["a"].JsonType, "type");
26                         Assert.AreEqual ("b", (string) j ["a"], "value");
27                 }
28
29                 // Test that we correctly serialize JsonArray with null elements.
30                 [Test]
31                 public void ToStringOnJsonArrayWithNulls () {
32                         var j = JsonValue.Load (new StringReader ("[1,2,3,null]"));
33                         Assert.AreEqual (4, j.Count, "itemcount");
34                         Assert.AreEqual (JsonType.Array, j.JsonType, "type");
35                         var str = j.ToString ();
36                         Assert.AreEqual (str, "[1, 2, 3, null]");
37                 }
38         }
39 }