Skip to content

Commit 631257f

Browse files
committed
import test cases and create test class
1 parent 7ebc6cd commit 631257f

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

tests/JsonLD.Test/JsonLD.Test.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@
5858
</ItemGroup>
5959
<ItemGroup>
6060
<Compile Include="ConformanceTests.cs" />
61+
<Compile Include="NQuadsParserTests.cs" />
6162
<Compile Include="Properties\AssemblyInfo.cs" />
6263
</ItemGroup>
64+
<ItemGroup>
65+
<Content Include="NQuads\*">
66+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
67+
</Content>
68+
</ItemGroup>
6369
<ItemGroup>
6470
<Content Include="W3C\compact-0001-context.jsonld">
6571
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@@ -3005,6 +3011,7 @@
30053011
<Name>JsonLD</Name>
30063012
</ProjectReference>
30073013
</ItemGroup>
3014+
<ItemGroup />
30083015
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
30093016
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
30103017
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# blank nodes with hyphen and period
2+
_:aa-aa <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> _:bb.bb .
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using JsonLD.Core;
6+
using JsonLD.Impl;
7+
using Newtonsoft.Json.Linq;
8+
using Xunit;
9+
using Xunit.Extensions;
10+
11+
namespace JsonLD.Test
12+
{
13+
public class NQuadsParserTests
14+
{
15+
private const string BasePath = @"NQuads\";
16+
private const string ManifestPath = BasePath + "manifest.ttl";
17+
private static readonly JObject ManifestFrame = JObject.Parse(@"
18+
{
19+
'@context': {
20+
'mf': 'http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#',
21+
'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
22+
'rdft': 'http://www.w3.org/ns/rdftest#',
23+
'mf:entries': { '@container': '@list'},
24+
'mf:action': { '@type': '@id'}
25+
},
26+
'@type': 'mf:Manifest'
27+
}");
28+
29+
private readonly NQuadRDFParser _parser;
30+
31+
public NQuadsParserTests()
32+
{
33+
_parser = new NQuadRDFParser();
34+
}
35+
36+
[Theory]
37+
[PropertyData("PositiveTestCases")]
38+
public void PositiveParseTest(string path)
39+
{
40+
// given
41+
string quads = File.ReadAllText(BasePath + path);
42+
43+
// when
44+
_parser.Parse(quads);
45+
}
46+
47+
[Theory]
48+
[PropertyData("NegativeTestCases")]
49+
public void NegativeParseTest(string path)
50+
{
51+
// given
52+
string quads = File.ReadAllText(BasePath + path);
53+
54+
// when
55+
Assert.Throws<JsonLdError>(() => _parser.Parse(quads));
56+
}
57+
58+
[Fact]
59+
public void ParseBlankNodesTest()
60+
{
61+
// given
62+
const string path = "rdf11blanknodes.nq";
63+
string quads = File.ReadAllText(BasePath + path);
64+
65+
// when
66+
_parser.Parse(quads);
67+
}
68+
69+
public static IEnumerable<object[]> PositiveTestCases
70+
{
71+
get
72+
{
73+
var manifest = JsonLdProcessor.FromRDF(File.ReadAllText(ManifestPath), new TurtleRDFParser());
74+
var framed = JsonLdProcessor.Frame(manifest, ManifestFrame, new JsonLdOptions());
75+
76+
return from testCase in framed["@graph"][0]["mf:entries"]
77+
where (string)testCase["@type"] != "rdft:TestNQuadsNegativeSyntax"
78+
select new object[] { (string)testCase["mf:action"] };
79+
}
80+
}
81+
82+
public static IEnumerable<object[]> NegativeTestCases
83+
{
84+
get
85+
{
86+
var manifest = JsonLdProcessor.FromRDF(File.ReadAllText(ManifestPath), new TurtleRDFParser());
87+
var framed = JsonLdProcessor.Frame(manifest, ManifestFrame, new JsonLdOptions());
88+
89+
return from testCase in framed["@graph"][0]["mf:entries"]
90+
where (string)testCase["@type"] == "rdft:TestNQuadsNegativeSyntax"
91+
select new object[] { (string)testCase["mf:action"] };
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)