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