VAR.Json first commit
This commit is contained in:
129
VAR.Json.Tests/Program.cs
Normal file
129
VAR.Json.Tests/Program.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Json.Tests
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// http://www.json.org/JSON_checker/
|
||||
|
||||
string currentPath = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
currentPath = FindPath(currentPath, "tests");
|
||||
|
||||
// Test all files
|
||||
string[] files;
|
||||
files = Directory.GetFiles(currentPath, "*.json");
|
||||
foreach (string file in files)
|
||||
{
|
||||
TestFile(file);
|
||||
}
|
||||
|
||||
Console.Read();
|
||||
}
|
||||
|
||||
private static void TestFile(string fileName)
|
||||
{
|
||||
string testName = Path.GetFileNameWithoutExtension(fileName);
|
||||
string fileContent = File.ReadAllText(fileName, Encoding.UTF8);
|
||||
if (testName.StartsWith("fail"))
|
||||
{
|
||||
TestFailCase(testName, fileContent);
|
||||
}
|
||||
if (testName.StartsWith("pass"))
|
||||
{
|
||||
TestPassCase(testName, fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TestFailCase(string testName, string fileContent)
|
||||
{
|
||||
JsonParser parser = new JsonParser();
|
||||
object result;
|
||||
try
|
||||
{
|
||||
result = parser.Parse(fileContent);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OutputFailure(testName, fileContent, ex);
|
||||
return;
|
||||
}
|
||||
if (parser.Tainted == false)
|
||||
{
|
||||
OutputFailure(testName, fileContent, result);
|
||||
return;
|
||||
}
|
||||
Console.Out.WriteLine("OK! {0}", testName);
|
||||
}
|
||||
|
||||
private static void TestPassCase(string testName, string fileContent)
|
||||
{
|
||||
JsonParser parser = new JsonParser();
|
||||
object result;
|
||||
try
|
||||
{
|
||||
result = parser.Parse(fileContent);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OutputFailure(testName, fileContent, ex);
|
||||
return;
|
||||
}
|
||||
if (parser.Tainted)
|
||||
{
|
||||
OutputFailure(testName, fileContent, result);
|
||||
return;
|
||||
}
|
||||
Console.Out.WriteLine("OK! {0}", testName);
|
||||
}
|
||||
|
||||
private static void OutputFailure(string testName, string fileContent, object obj)
|
||||
{
|
||||
Console.Out.WriteLine("Failure! {0}", testName);
|
||||
Console.Out.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
Console.Out.WriteLine("Content:\n{0}", fileContent);
|
||||
Console.Out.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
if (obj is Exception)
|
||||
{
|
||||
Exception ex = obj as Exception;
|
||||
Console.Out.WriteLine("Ex.Message: {0}", ex.Message);
|
||||
Console.Out.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
Console.Out.WriteLine("Ex.Stacktrace:\n{0}", ex.StackTrace);
|
||||
Console.Out.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
if (obj != null && (obj is Exception) == false)
|
||||
{
|
||||
JsonWriter writter = new JsonWriter(true);
|
||||
Console.Out.WriteLine("Parsed:\n{0}", writter.Write(obj));
|
||||
Console.Out.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
private static string FindPath(string currentPath, string directory)
|
||||
{
|
||||
do
|
||||
{
|
||||
string testPath = Path.Combine(currentPath, directory);
|
||||
if (Directory.Exists(testPath))
|
||||
{
|
||||
currentPath = testPath;
|
||||
Console.Out.WriteLine(testPath);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo dirInfo = Directory.GetParent(currentPath);
|
||||
if (dirInfo == null)
|
||||
{
|
||||
throw new Exception(string.Format("FindPath: Directory {0} not found", directory));
|
||||
}
|
||||
currentPath = dirInfo.ToString();
|
||||
}
|
||||
} while (string.IsNullOrEmpty(currentPath) == false);
|
||||
return currentPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
VAR.Json.Tests/Properties/AssemblyInfo.cs
Normal file
14
VAR.Json.Tests/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("VAR.Json.Tests")]
|
||||
[assembly: AssemblyDescription("Json Tests")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("VAR")]
|
||||
[assembly: AssemblyProduct("VAR.Json.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © VAR 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("576297b8-423d-4533-b75a-f186ccff0d2a")]
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
95
VAR.Json.Tests/VAR.Json.Tests.csproj
Normal file
95
VAR.Json.Tests/VAR.Json.Tests.csproj
Normal file
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{576297B8-423D-4533-B75A-F186CCFF0D2A}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>VAR.Json.Tests</RootNamespace>
|
||||
<AssemblyName>VAR.Json.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="tests\fail01.json" />
|
||||
<None Include="tests\fail10.json" />
|
||||
<None Include="tests\fail11.json" />
|
||||
<None Include="tests\fail12.json" />
|
||||
<None Include="tests\fail13.json" />
|
||||
<None Include="tests\fail14.json" />
|
||||
<None Include="tests\fail15.json" />
|
||||
<None Include="tests\fail16.json" />
|
||||
<None Include="tests\fail17.json" />
|
||||
<None Include="tests\fail18.json" />
|
||||
<None Include="tests\fail19.json" />
|
||||
<None Include="tests\fail02.json" />
|
||||
<None Include="tests\fail20.json" />
|
||||
<None Include="tests\fail21.json" />
|
||||
<None Include="tests\fail22.json" />
|
||||
<None Include="tests\fail23.json" />
|
||||
<None Include="tests\fail24.json" />
|
||||
<None Include="tests\fail25.json" />
|
||||
<None Include="tests\fail26.json" />
|
||||
<None Include="tests\fail27.json" />
|
||||
<None Include="tests\fail28.json" />
|
||||
<None Include="tests\fail29.json" />
|
||||
<None Include="tests\fail03.json" />
|
||||
<None Include="tests\fail30.json" />
|
||||
<None Include="tests\fail31.json" />
|
||||
<None Include="tests\fail32.json" />
|
||||
<None Include="tests\fail33.json" />
|
||||
<None Include="tests\fail04.json" />
|
||||
<None Include="tests\fail05.json" />
|
||||
<None Include="tests\fail06.json" />
|
||||
<None Include="tests\fail07.json" />
|
||||
<None Include="tests\fail08.json" />
|
||||
<None Include="tests\fail09.json" />
|
||||
<None Include="tests\pass01.json" />
|
||||
<None Include="tests\pass02.json" />
|
||||
<None Include="tests\pass03.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VAR.Json\VAR.Json.csproj">
|
||||
<Project>{28b3f937-145c-4fd4-a75b-a25ea4cc0428}</Project>
|
||||
<Name>VAR.Json</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
1
VAR.Json.Tests/tests/fail01.json
Normal file
1
VAR.Json.Tests/tests/fail01.json
Normal file
@@ -0,0 +1 @@
|
||||
"A JSON payload should be an object or array, not a string."
|
||||
1
VAR.Json.Tests/tests/fail02.json
Normal file
1
VAR.Json.Tests/tests/fail02.json
Normal file
@@ -0,0 +1 @@
|
||||
["Unclosed array"
|
||||
1
VAR.Json.Tests/tests/fail03.json
Normal file
1
VAR.Json.Tests/tests/fail03.json
Normal file
@@ -0,0 +1 @@
|
||||
{unquoted_key: "keys must be quoted"}
|
||||
1
VAR.Json.Tests/tests/fail04.json
Normal file
1
VAR.Json.Tests/tests/fail04.json
Normal file
@@ -0,0 +1 @@
|
||||
["extra comma",]
|
||||
1
VAR.Json.Tests/tests/fail05.json
Normal file
1
VAR.Json.Tests/tests/fail05.json
Normal file
@@ -0,0 +1 @@
|
||||
["double extra comma",,]
|
||||
1
VAR.Json.Tests/tests/fail06.json
Normal file
1
VAR.Json.Tests/tests/fail06.json
Normal file
@@ -0,0 +1 @@
|
||||
[ , "<-- missing value"]
|
||||
1
VAR.Json.Tests/tests/fail07.json
Normal file
1
VAR.Json.Tests/tests/fail07.json
Normal file
@@ -0,0 +1 @@
|
||||
["Comma after the close"],
|
||||
1
VAR.Json.Tests/tests/fail08.json
Normal file
1
VAR.Json.Tests/tests/fail08.json
Normal file
@@ -0,0 +1 @@
|
||||
["Extra close"]]
|
||||
1
VAR.Json.Tests/tests/fail09.json
Normal file
1
VAR.Json.Tests/tests/fail09.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Extra comma": true,}
|
||||
1
VAR.Json.Tests/tests/fail10.json
Normal file
1
VAR.Json.Tests/tests/fail10.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Extra value after close": true} "misplaced quoted value"
|
||||
1
VAR.Json.Tests/tests/fail11.json
Normal file
1
VAR.Json.Tests/tests/fail11.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Illegal expression": 1 + 2}
|
||||
1
VAR.Json.Tests/tests/fail12.json
Normal file
1
VAR.Json.Tests/tests/fail12.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Illegal invocation": alert()}
|
||||
1
VAR.Json.Tests/tests/fail13.json
Normal file
1
VAR.Json.Tests/tests/fail13.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Numbers cannot have leading zeroes": 013}
|
||||
1
VAR.Json.Tests/tests/fail14.json
Normal file
1
VAR.Json.Tests/tests/fail14.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Numbers cannot be hex": 0x14}
|
||||
1
VAR.Json.Tests/tests/fail15.json
Normal file
1
VAR.Json.Tests/tests/fail15.json
Normal file
@@ -0,0 +1 @@
|
||||
["Illegal backslash escape: \x15"]
|
||||
1
VAR.Json.Tests/tests/fail16.json
Normal file
1
VAR.Json.Tests/tests/fail16.json
Normal file
@@ -0,0 +1 @@
|
||||
[\naked]
|
||||
1
VAR.Json.Tests/tests/fail17.json
Normal file
1
VAR.Json.Tests/tests/fail17.json
Normal file
@@ -0,0 +1 @@
|
||||
["Illegal backslash escape: \017"]
|
||||
1
VAR.Json.Tests/tests/fail18.json
Normal file
1
VAR.Json.Tests/tests/fail18.json
Normal file
@@ -0,0 +1 @@
|
||||
[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]
|
||||
1
VAR.Json.Tests/tests/fail19.json
Normal file
1
VAR.Json.Tests/tests/fail19.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Missing colon" null}
|
||||
1
VAR.Json.Tests/tests/fail20.json
Normal file
1
VAR.Json.Tests/tests/fail20.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Double colon":: null}
|
||||
1
VAR.Json.Tests/tests/fail21.json
Normal file
1
VAR.Json.Tests/tests/fail21.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Comma instead of colon", null}
|
||||
1
VAR.Json.Tests/tests/fail22.json
Normal file
1
VAR.Json.Tests/tests/fail22.json
Normal file
@@ -0,0 +1 @@
|
||||
["Colon instead of comma": false]
|
||||
1
VAR.Json.Tests/tests/fail23.json
Normal file
1
VAR.Json.Tests/tests/fail23.json
Normal file
@@ -0,0 +1 @@
|
||||
["Bad value", truth]
|
||||
1
VAR.Json.Tests/tests/fail24.json
Normal file
1
VAR.Json.Tests/tests/fail24.json
Normal file
@@ -0,0 +1 @@
|
||||
['single quote']
|
||||
1
VAR.Json.Tests/tests/fail25.json
Normal file
1
VAR.Json.Tests/tests/fail25.json
Normal file
@@ -0,0 +1 @@
|
||||
[" tab character in string "]
|
||||
1
VAR.Json.Tests/tests/fail26.json
Normal file
1
VAR.Json.Tests/tests/fail26.json
Normal file
@@ -0,0 +1 @@
|
||||
["tab\ character\ in\ string\ "]
|
||||
2
VAR.Json.Tests/tests/fail27.json
Normal file
2
VAR.Json.Tests/tests/fail27.json
Normal file
@@ -0,0 +1,2 @@
|
||||
["line
|
||||
break"]
|
||||
2
VAR.Json.Tests/tests/fail28.json
Normal file
2
VAR.Json.Tests/tests/fail28.json
Normal file
@@ -0,0 +1,2 @@
|
||||
["line\
|
||||
break"]
|
||||
1
VAR.Json.Tests/tests/fail29.json
Normal file
1
VAR.Json.Tests/tests/fail29.json
Normal file
@@ -0,0 +1 @@
|
||||
[0e]
|
||||
1
VAR.Json.Tests/tests/fail30.json
Normal file
1
VAR.Json.Tests/tests/fail30.json
Normal file
@@ -0,0 +1 @@
|
||||
[0e+]
|
||||
1
VAR.Json.Tests/tests/fail31.json
Normal file
1
VAR.Json.Tests/tests/fail31.json
Normal file
@@ -0,0 +1 @@
|
||||
[0e+-1]
|
||||
1
VAR.Json.Tests/tests/fail32.json
Normal file
1
VAR.Json.Tests/tests/fail32.json
Normal file
@@ -0,0 +1 @@
|
||||
{"Comma instead if closing brace": true,
|
||||
1
VAR.Json.Tests/tests/fail33.json
Normal file
1
VAR.Json.Tests/tests/fail33.json
Normal file
@@ -0,0 +1 @@
|
||||
["mismatch"}
|
||||
58
VAR.Json.Tests/tests/pass01.json
Normal file
58
VAR.Json.Tests/tests/pass01.json
Normal file
@@ -0,0 +1,58 @@
|
||||
[
|
||||
"JSON Test Pattern pass1",
|
||||
{"object with 1 member":["array with 1 element"]},
|
||||
{},
|
||||
[],
|
||||
-42,
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
{
|
||||
"integer": 1234567890,
|
||||
"real": -9876.543210,
|
||||
"e": 0.123456789e-12,
|
||||
"E": 1.234567890E+34,
|
||||
"": 23456789012E66,
|
||||
"zero": 0,
|
||||
"one": 1,
|
||||
"space": " ",
|
||||
"quote": "\"",
|
||||
"backslash": "\\",
|
||||
"controls": "\b\f\n\r\t",
|
||||
"slash": "/ & \/",
|
||||
"alpha": "abcdefghijklmnopqrstuvwyz",
|
||||
"ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ",
|
||||
"digit": "0123456789",
|
||||
"0123456789": "digit",
|
||||
"special": "`1~!@#$%^&*()_+-={':[,]}|;.</>?",
|
||||
"hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A",
|
||||
"true": true,
|
||||
"false": false,
|
||||
"null": null,
|
||||
"array":[ ],
|
||||
"object":{ },
|
||||
"address": "50 St. James Street",
|
||||
"url": "http://www.JSON.org/",
|
||||
"comment": "// /* <!-- --",
|
||||
"# -- --> */": " ",
|
||||
" s p a c e d " :[1,2 , 3
|
||||
|
||||
,
|
||||
|
||||
4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7],
|
||||
"jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}",
|
||||
"quotes": "" \u0022 %22 0x22 034 "",
|
||||
"\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?"
|
||||
: "A key can be any string"
|
||||
},
|
||||
0.5 ,98.6
|
||||
,
|
||||
99.44
|
||||
,
|
||||
|
||||
1066,
|
||||
1e1,
|
||||
0.1e1,
|
||||
1e-1,
|
||||
1e00,2e+00,2e-00
|
||||
,"rosebud"]
|
||||
1
VAR.Json.Tests/tests/pass02.json
Normal file
1
VAR.Json.Tests/tests/pass02.json
Normal file
@@ -0,0 +1 @@
|
||||
[[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]]
|
||||
6
VAR.Json.Tests/tests/pass03.json
Normal file
6
VAR.Json.Tests/tests/pass03.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"JSON Test Pattern pass3": {
|
||||
"The outermost value": "must be an object or array.",
|
||||
"In this test": "It is an object."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user