using NUnit.Framework; using System; using Implab.Formats.JSON; namespace Implab.Format.Test { [TestFixture] public class JsonTests { [Test] public void TestScannerValidTokens() { var scanner = new JSONScanner(@"9123, -123, 0, 0.1, -0.2, -0.1e3, 1.3E-3, ""some \t\n\u0020 text"", literal []{}:"); Tuple[] expexted = new [] { new Tuple(JsonTokenType.Number, 9123d), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Number, -123d ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Number, 0d ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Number, 0.1d ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Number, -0.2d ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Number, -0.1e3d ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Number, 1.3E-3d ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.String, "some \t\n text" ), new Tuple(JsonTokenType.ValueSeparator, ", " ), new Tuple(JsonTokenType.Literal, "literal" ), new Tuple(JsonTokenType.BeginArray, " [" ), new Tuple(JsonTokenType.EndArray, "]" ), new Tuple(JsonTokenType.BeginObject, "{" ), new Tuple(JsonTokenType.EndObject, "}" ), new Tuple(JsonTokenType.NameSeparator, ":" ) }; object value; JsonTokenType tokenType; for (var i = 0; i < expexted.Length; i++) { Assert.IsTrue(scanner.ReadToken(out value, out tokenType)); Assert.AreEqual(expexted[i].Item1, tokenType); Assert.AreEqual(expexted[i].Item2, value); } Assert.IsFalse(scanner.ReadToken(out value, out tokenType)); } } }