forked from yavuztor/JsonLogic.Net
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinqPad-JsonLogicTestCaseHarvester.linq
53 lines (50 loc) · 3.25 KB
/
LinqPad-JsonLogicTestCaseHarvester.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Query Kind="Statements">
<Reference><RuntimeDirectory>\Microsoft.Build.Framework.dll</Reference>
<Reference><RuntimeDirectory>\Microsoft.Build.Tasks.v4.0.dll</Reference>
<Reference><RuntimeDirectory>\Microsoft.Build.Utilities.v4.0.dll</Reference>
<Reference><RuntimeDirectory>\System.ComponentModel.DataAnnotations.dll</Reference>
<Reference><RuntimeDirectory>\System.Configuration.dll</Reference>
<Reference><RuntimeDirectory>\System.Design.dll</Reference>
<Reference><RuntimeDirectory>\System.DirectoryServices.dll</Reference>
<Reference><RuntimeDirectory>\System.DirectoryServices.Protocols.dll</Reference>
<Reference><RuntimeDirectory>\System.EnterpriseServices.dll</Reference>
<Reference><RuntimeDirectory>\System.Runtime.Caching.dll</Reference>
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Reference><RuntimeDirectory>\System.ServiceProcess.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.ApplicationServices.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.RegularExpressions.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.Services.dll</Reference>
<Reference><RuntimeDirectory>\System.Windows.Forms.dll</Reference>
<Reference><RuntimeDirectory>\WPF\PresentationCore.dll</Reference>
<Reference><RuntimeDirectory>\WPF\WindowsBase.dll</Reference>
<Reference><RuntimeDirectory>\System.Xaml.dll</Reference>
<Reference><RuntimeDirectory>\WPF\UIAutomationTypes.dll</Reference>
<Reference><RuntimeDirectory>\WPF\System.Windows.Input.Manipulations.dll</Reference>
<Reference><RuntimeDirectory>\WPF\UIAutomationProvider.dll</Reference>
<Reference><RuntimeDirectory>\System.Deployment.dll</Reference>
<NuGetReference>HtmlAgilityPack.Net45</NuGetReference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>HtmlAgilityPack</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
<Namespace>System.Web</Namespace>
</Query>
// This process is bound to break, so might require amending!
// 1. Navigate to http://jsonlogic.com/operations.html
// 2. After page fully loads, save it as Html (single page). I used Firefox for this
// 3. Point the "file" variable below to the results of step 2
// 4. Execute the script and save clipboard contents to "jsonlogic.com_tests.json" file
var file = @"CHANGEME.html";
var doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(file);
var testRows = doc.DocumentNode.SelectNodes("/html/body/div/div/section/div/div[contains(@class, 'row')]");
var testStrings = testRows.Select(row => new []
{
HttpUtility.HtmlDecode(row.SelectSingleNode("div[contains(@class, 'logic')]/textarea").InnerText),
HttpUtility.HtmlDecode(row.SelectSingleNode("div[contains(@class, 'data')]/textarea").InnerText),
HttpUtility.HtmlDecode(row.SelectSingleNode("div[contains(@class, 'result')]/textarea").InnerText)
});
var testJson = new JArray(testStrings.Select(scenario => new JArray(scenario.Select(txt => JToken.Parse(txt)).ToArray())).ToArray());
System.Windows.Forms.Clipboard.Clear();
System.Windows.Forms.Clipboard.SetText(testJson.ToString().Dump());