Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: format JSON using JSON.NET & test #1292

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4.1.1

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- run: dotnet test

67 changes: 67 additions & 0 deletions JsonTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using Manx_Search_Data.TestData;
using Manx_Search_Data.TestUtil;
using NUnit.Framework;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace Manx_Search_Data;

[TestFixture]
public class JsonTest
{
[DatapointSource]
// ReSharper disable once UnusedMember.Global
public OpenSourceDocument[] AllDocuments = Documents.AllDocuments.OfType<OpenSourceDocument>().ToArray();

public dynamic ReadNewtonsoft(string input) => Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(input);

public dynamic DeserializeJson(string input)
{
return JsonSerializer.Deserialize<dynamic>(input, options: new JsonSerializerOptions
{
AllowTrailingCommas = true,
});

// catch
// {
// Newtonsoft can handle newlines in strings
// return ReadNewtonsoft(input);
// throw;
// }
}

private JsonSerializerOptions _options = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true,
};

/// <summary>
/// Ensure each file is valid for JSON.NET, which parses more strictly than Newtonsoft
/// </summary>
/// <param name="document"></param>
[Theory]
public void CsvFileIsJalidJsonNet(OpenSourceDocument document)
{
var path = document.LocationOnDisk + "/manifest.json.txt";

var input = File.ReadAllText(path);

var inputJson = DeserializeJson(input);

// var output = JsonConvert.SerializeObject(inputJson, new JsonSerializerSettings()
// {
// Formatting = Formatting.Indented,
// Converters = { new ExpandoObjectConverter() },
// });

var output = JsonSerializer.Serialize(inputJson, _options);

// This modifies files in the test dir, not under source control.
// Copy them over if you want to replace
// File.WriteAllText(path, output);
Assert.AreEqual(input, output);
}
}
3 changes: 2 additions & 1 deletion Manx-Search-Data.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Manx_Search_Data</RootNamespace>

<IsPackable>false</IsPackable>

<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions OpenData/Acts/1909/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1909-06-05",
"ident": "Acts-1909",
"name": "Slattysyn 1909",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on June 5th 1909."
}
"created": "1909-06-05",
"ident": "Acts-1909",
"name": "Slattysyn 1909",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on June 5th 1909."
}
16 changes: 8 additions & 8 deletions OpenData/Acts/1911/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1911-09-05",
"ident": "Acts-1911",
"name": "Slattysyn 1911",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on September 5th 1911."
}
"created": "1911-09-05",
"ident": "Acts-1911",
"name": "Slattysyn 1911",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on September 5th 1911."
}
16 changes: 8 additions & 8 deletions OpenData/Acts/1912/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1912-07-05",
"ident": "Acts-1912",
"name": "Slattysyn 1912",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1912."
}
"created": "1912-07-05",
"ident": "Acts-1912",
"name": "Slattysyn 1912",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1912."
}
16 changes: 8 additions & 8 deletions OpenData/Acts/1929/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1929-07-05",
"ident": "Acts-1929",
"name": "Slattysyn 1929",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1929."
}
"created": "1929-07-05",
"ident": "Acts-1929",
"name": "Slattysyn 1929",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1929."
}
21 changes: 10 additions & 11 deletions OpenData/Acts/Speech by Mr E. U. Savage/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"created": "1901-02-16",
"ident": "Speech-by-MR-SAVAGE",
"name": "Speech by MR E.U. SAVAGE",
"notes": "Speech to the Liverpool Manx Society",
"original": "Manx",
"author": "Mr E.U. Savage",
"mnhNewsComponent": "Ar00800",
"source": "Speech by MR E.U. SAVAGE to the Liverpool Manx Society: Isle of Man Examiner, Saturday, February 16, 1901; Page: 8",
}

{
"created": "1901-02-16",
"ident": "Speech-by-MR-SAVAGE",
"name": "Speech by MR E.U. SAVAGE",
"notes": "Speech to the Liverpool Manx Society",
"original": "Manx",
"author": "Mr E.U. Savage",
"mnhNewsComponent": "Ar00800",
"source": "Speech by MR E.U. SAVAGE to the Liverpool Manx Society: Isle of Man Examiner, Saturday, February 16, 1901; Page: 8"
}
15 changes: 7 additions & 8 deletions OpenData/Acts/proclamation 1901/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"created": "1901-02-02",
"ident": "Cliaghtey-Fockley-Magh-1901",
"name": "Cliaghtey Fockley Magh",
"notes": "Proclamation Ceremony of the New King",
"original": "Bilingual",
"source": "Isle of Man Examiner, Saturday, February 02, 1901; Page: 2",

}
"created": "1901-02-02",
"ident": "Cliaghtey-Fockley-Magh-1901",
"name": "Cliaghtey Fockley Magh",
"notes": "Proclamation Ceremony of the New King",
"original": "Bilingual",
"source": "Isle of Man Examiner, Saturday, February 02, 1901; Page: 2"
}
16 changes: 8 additions & 8 deletions OpenData/Acts/slattysyn 1920/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1920-07-05",
"ident": "Acts-1920",
"name": "Slattysyn 1920",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1920."
}
"created": "1920-07-05",
"ident": "Acts-1920",
"name": "Slattysyn 1920",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1920."
}
16 changes: 8 additions & 8 deletions OpenData/Acts/slattysyn 1941/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1941-07-05",
"ident": "Acts-1941",
"name": "Slattysyn 1941",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1941."
}
"created": "1941-07-05",
"ident": "Acts-1941",
"name": "Slattysyn 1941",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1941."
}
16 changes: 8 additions & 8 deletions OpenData/Acts/slattysyn 1942/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"created": "1942-07-05",
"ident": "Acts-1942",
"name": "Slattysyn 1942",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1942."
}
"created": "1942-07-05",
"ident": "Acts-1942",
"name": "Slattysyn 1942",
"author": "unknown",
"original": "English",
"iMuseum": "MS D200",
"notes": "MS D200. Abstracts of the Acts of Tynwald proclamated on July 5th 1942."
}
15 changes: 7 additions & 8 deletions OpenData/Acts/slattysyn1901/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"created": "1901-07-05",
"ident": "Slattysyn-1901",
"name": "Slattysyn 1901",
"notes": "Acts of Tynwald. Transcribed by R. Teare 2021",
"original": "English",
"source": "ABSTRACTS OF ACTS FOR PROMULGATION. BROWN AND SONS, LIMITED PRINTERS, DOUGLAS.1901.",

}
"created": "1901-07-05",
"ident": "Slattysyn-1901",
"name": "Slattysyn 1901",
"notes": "Acts of Tynwald. Transcribed by R. Teare 2021",
"original": "English",
"source": "ABSTRACTS OF ACTS FOR PROMULGATION. BROWN AND SONS, LIMITED PRINTERS, DOUGLAS.1901."
}
15 changes: 7 additions & 8 deletions OpenData/Ann Kneale/A remarkable Conversion/manifest.json.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"created": "1829-03-01",
"ident": "A-Remarkable-Conversion",
"name": "Lioar Ann Kneale: A Remarkable Conversion / Coontey jeh Dooinney as Ben ayns Saustin.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed & translated": "Rob Teare & Max Wheeler 2021",
"source": "The Arminian Magazine, XVIII, 1795, p. 389-90./ Manx; Manx Museum MS 002182A; Lioar Ann Kneale."

}
"created": "1829-03-01",
"ident": "A-Remarkable-Conversion",
"name": "Lioar Ann Kneale: A Remarkable Conversion / Coontey jeh Dooinney as Ben ayns Saustin.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed \u0026 translated": "Rob Teare \u0026 Max Wheeler 2021",
"source": "The Arminian Magazine, XVIII, 1795, p. 389-90./ Manx; Manx Museum MS 002182A; Lioar Ann Kneale."
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"created": "1829-03-01",
"ident": "Gentleman-at-Bath",
"name": "Lioar Ann Kneale: Anecdote of a Gentleman at Bath / Coontey jeh Dooinney Seyr ayns Bath",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed & translated": "Rob Teare & Max Wheeler 2021",
"source": "English: The Arminian Magazine, vol. XIX, 1796, p 286 (from Wills’s Spiritual Register Vol. iii, 1795.) / Manx; Manx Museum MS 002182A; Lioar Ann Kneale."

}
"created": "1829-03-01",
"ident": "Gentleman-at-Bath",
"name": "Lioar Ann Kneale: Anecdote of a Gentleman at Bath / Coontey jeh Dooinney Seyr ayns Bath",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed \u0026 translated": "Rob Teare \u0026 Max Wheeler 2021",
"source": "English: The Arminian Magazine, vol. XIX, 1796, p 286 (from Wills\u2019s Spiritual Register Vol. iii, 1795.) / Manx; Manx Museum MS 002182A; Lioar Ann Kneale."
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"created": "1829-03-01",
"ident": "Anecdote-on-Family-Religion",
"name": "Lioar Ann Kneale: Anecdote on Family Religion. / Coontey Yindysagh jeh Eirinnagh As Masoonagh.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed & translated": "Rob Teare & Max Wheeler 2021",
"source": "English; The Methodist Magazine, vol. XXII, 1799, pp. 560-3. Manx; Manx Museum MS 002182A; Lioar Ann Kneale."

}
"created": "1829-03-01",
"ident": "Anecdote-on-Family-Religion",
"name": "Lioar Ann Kneale: Anecdote on Family Religion. / Coontey Yindysagh jeh Eirinnagh As Masoonagh.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed \u0026 translated": "Rob Teare \u0026 Max Wheeler 2021",
"source": "English; The Methodist Magazine, vol. XXII, 1799, pp. 560-3. Manx; Manx Museum MS 002182A; Lioar Ann Kneale."
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"created": "1829-03-01",
"ident": "Godwins-Remarkable-Account",
"name": "Lioar Ann Kneale: Rev. Goodwin’s remarkable account / Coontey jeh Dooinney Seyr ayns Wisbeach",
"manxName": "Lioar Ann Kneale: Coontey jeh Dooinney Seyr ayns Wisbeach",
"englishName": "Lioar Ann Kneale: Rev. Goodwin’s remarkable account",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed & translated": "Rob Teare & Max Wheeler 2021",
"source": "English; The Arminian Magazine, vol. VII, 1784, pp. 308-309. Manx; Manx Museum MS 002182A; Lioar Ann Kneale."

}
"created": "1829-03-01",
"ident": "Godwins-Remarkable-Account",
"name": "Lioar Ann Kneale: Rev. Goodwin\u2019s remarkable account / Coontey jeh Dooinney Seyr ayns Wisbeach",
"manxName": "Lioar Ann Kneale: Coontey jeh Dooinney Seyr ayns Wisbeach",
"englishName": "Lioar Ann Kneale: Rev. Goodwin\u2019s remarkable account",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed \u0026 translated": "Rob Teare \u0026 Max Wheeler 2021",
"source": "English; The Arminian Magazine, vol. VII, 1784, pp. 308-309. Manx; Manx Museum MS 002182A; Lioar Ann Kneale."
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"created": "1829-03-01",
"ident": "The-Beneficial-Effect-of-Sunday-Schools",
"name": "Lioar Ann Kneale: The beneficial Effect of Sunday Schools / Coontey jeh Schoillor Doonnee as eh Voir.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed & translated": "Rob Teare & Max Wheeler 2021",
"source": "English: The Methodist Magazine, vol. 36, 1813, p. 442. / Manx; Manx Museum MS 002182A; Lioar Ann Kneale."

}
"created": "1829-03-01",
"ident": "The-Beneficial-Effect-of-Sunday-Schools",
"name": "Lioar Ann Kneale: The beneficial Effect of Sunday Schools / Coontey jeh Schoillor Doonnee as eh Voir.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed \u0026 translated": "Rob Teare \u0026 Max Wheeler 2021",
"source": "English: The Methodist Magazine, vol. 36, 1813, p. 442. / Manx; Manx Museum MS 002182A; Lioar Ann Kneale."
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"created": "1829-03-01",
"ident": "The-Providence-of-God-Asserted",
"name": "Lioar Ann Kneale: The Providence of God Asserted / Coontey jeh Ben ayns Saustin.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed & translated": "Rob Teare & Max Wheeler 2021",
"source": "English: Wesleyan Methodist Magazine, vol. XXIX, 1806, 30-32
Letter from John Pawson / Manx; Manx Museum MS 002182A; Lioar Ann Kneale."

}
"created": "1829-03-01",
"ident": "The-Providence-of-God-Asserted",
"name": "Lioar Ann Kneale: The Providence of God Asserted / Coontey jeh Ben ayns Saustin.",
"notes": "(English originals of and) Manx Versions of Methodist Tracts, written by Ann Kneale, of Regaby (Andreas), 1829",
"transcribed \u0026 translated": "Rob Teare \u0026 Max Wheeler 2021",
"source": "English: Wesleyan Methodist Magazine, vol. XXIX, 1806, 30-32\nLetter from John Pawson / Manx; Manx Museum MS 002182A; Lioar Ann Kneale."
}
Loading
Loading