158
|
1 using NUnit.Framework;
|
|
2 using System;
|
182
|
3 using Implab.Formats.JSON;
|
158
|
4
|
|
5 namespace Implab.Format.Test {
|
182
|
6 [TestFixture]
|
158
|
7 public class JsonTests {
|
182
|
8 [Test]
|
|
9 public void TestScannerValidTokens() {
|
|
10 var scanner = new JSONScanner(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:");
|
|
11
|
|
12 Tuple<JsonTokenType,object>[] expexted = new [] {
|
|
13 new Tuple<JsonTokenType,object>(JsonTokenType.Number, 9123d),
|
|
14 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
15 new Tuple<JsonTokenType,object>(JsonTokenType.Number, -123d ),
|
|
16 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
17 new Tuple<JsonTokenType,object>(JsonTokenType.Number, 0d ),
|
|
18 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
19 new Tuple<JsonTokenType,object>(JsonTokenType.Number, 0.1d ),
|
|
20 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
21 new Tuple<JsonTokenType,object>(JsonTokenType.Number, -0.2d ),
|
|
22 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
23 new Tuple<JsonTokenType,object>(JsonTokenType.Number, -0.1e3d ),
|
|
24 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
25 new Tuple<JsonTokenType,object>(JsonTokenType.Number, 1.3E-3d ),
|
|
26 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
27 new Tuple<JsonTokenType,object>(JsonTokenType.String, "some \t\n text" ),
|
|
28 new Tuple<JsonTokenType,object>(JsonTokenType.ValueSeparator, ", " ),
|
|
29 new Tuple<JsonTokenType,object>(JsonTokenType.Literal, "literal" ),
|
|
30 new Tuple<JsonTokenType,object>(JsonTokenType.BeginArray, " [" ),
|
|
31 new Tuple<JsonTokenType,object>(JsonTokenType.EndArray, "]" ),
|
|
32 new Tuple<JsonTokenType,object>(JsonTokenType.BeginObject, "{" ),
|
|
33 new Tuple<JsonTokenType,object>(JsonTokenType.EndObject, "}" ),
|
|
34 new Tuple<JsonTokenType,object>(JsonTokenType.NameSeparator, ":" )
|
|
35 };
|
|
36
|
|
37 object value;
|
|
38 JsonTokenType tokenType;
|
|
39 for (var i = 0; i < expexted.Length; i++) {
|
|
40
|
|
41 Assert.IsTrue(scanner.ReadToken(out value, out tokenType));
|
|
42 Assert.AreEqual(expexted[i].Item1, tokenType);
|
|
43 Assert.AreEqual(expexted[i].Item2, value);
|
|
44 }
|
|
45
|
|
46 Assert.IsFalse(scanner.ReadToken(out value, out tokenType));
|
158
|
47 }
|
|
48 }
|
|
49 }
|
|
50
|