@@ -19,7 +19,7 @@ public class ConformanceTests
1919 public void ConformanceTestPasses ( string id , string testname , ConformanceCase conformanceCase )
2020 {
2121 JToken result = conformanceCase . run ( ) ;
22- if ( id . Contains ( " error" ) )
22+ if ( conformanceCase . error != null )
2323 {
2424 Assert . True ( ( ( string ) result [ "error" ] ) . StartsWith ( ( string ) conformanceCase . error ) , "Resulting error doesn't match expectations." ) ;
2525 }
@@ -42,7 +42,7 @@ public class ConformanceCase
4242
4343 public class ConformanceCases : IEnumerable < object [ ] >
4444 {
45- string [ ] manifests = new [ ] { "compact-manifest.jsonld" , "error-manifest.jsonld" , "expand-manifest.jsonld" , "flatten-manifest.jsonld" , "frame-manifest.jsonld" , "normalize -manifest.jsonld" } ;
45+ string [ ] manifests = new [ ] { "compact-manifest.jsonld" , "error-manifest.jsonld" , "expand-manifest.jsonld" , "flatten-manifest.jsonld" , "frame-manifest.jsonld" , "remote-doc -manifest.jsonld" } ;
4646
4747 public ConformanceCases ( )
4848 {
@@ -57,81 +57,104 @@ public IEnumerator<object[]> GetEnumerator()
5757
5858 manifestJson = GetJson ( manifest ) ;
5959
60- foreach ( var testcase in manifestJson [ "sequence" ] )
60+ foreach ( JObject testcase in manifestJson [ "sequence" ] )
6161 {
6262 Func < JToken > run ;
6363 ConformanceCase newCase = new ConformanceCase ( ) ;
6464
6565 newCase . input = GetJson ( testcase [ "input" ] ) ;
66- newCase . output = GetJson ( testcase [ "expect" ] ) ;
6766 newCase . context = GetJson ( testcase [ "context" ] ) ;
6867 newCase . frame = GetJson ( testcase [ "frame" ] ) ;
69- newCase . error = testcase [ "expect" ] ;
7068
7169 var options = new JsonLdOptions ( "http://json-ld.org/test-suite/tests/" + ( string ) testcase [ "input" ] ) ;
7270
73- if ( manifest . StartsWith ( "compact" ) )
71+ var testType = ( JArray ) testcase [ "@type" ] ;
72+
73+ if ( testType . Any ( ( s ) => ( string ) s == "jld:NegativeEvaluationTest" ) )
7474 {
75- if ( ( ( string ) testcase [ "@id" ] ) . Contains ( "0070" ) )
76- {
77- options . SetCompactArrays ( false ) ;
78- }
79- run = ( ) => JsonLdProcessor . Compact ( newCase . input , newCase . context , options ) ;
75+ newCase . error = testcase [ "expect" ] ;
76+ }
77+ else if ( testType . Any ( ( s ) => ( string ) s == "jld:PositiveEvaluationTest" ) )
78+ {
79+ newCase . output = GetJson ( testcase [ "expect" ] ) ;
8080 }
81- else if ( manifest . StartsWith ( "expand" ) )
81+ else
8282 {
83- if ( ( ( string ) testcase [ "@id" ] ) . Contains ( "0076" ) )
83+ throw new Exception ( "Expecting either positive or negative evaluation test." ) ;
84+ }
85+
86+ JToken optionToken ;
87+ JToken value ;
88+
89+ if ( testcase . TryGetValue ( "option" , out optionToken ) )
90+ {
91+ JObject optionDescription = ( JObject ) optionToken ;
92+
93+ if ( optionDescription . TryGetValue ( "compactArrays" , out value ) )
8494 {
85- options . SetBase ( "http://example/base/" ) ;
95+ options . SetCompactArrays ( ( bool ) value ) ;
8696 }
87- if ( ( ( string ) testcase [ "@id" ] ) . Contains ( "0077" ) )
97+ if ( optionDescription . TryGetValue ( "base" , out value ) )
98+ {
99+ options . SetBase ( ( string ) value ) ;
100+ }
101+ if ( optionDescription . TryGetValue ( "expandContext" , out value ) )
88102 {
89103 newCase . context = GetJson ( testcase [ "option" ] [ "expandContext" ] ) ;
90104 options . SetExpandContext ( ( JObject ) newCase . context ) ;
91105 }
92- run = ( ) => JsonLdProcessor . Expand ( newCase . input , options ) ;
93106 }
94- else if ( manifest . StartsWith ( "error" ) )
107+
108+ if ( testType . Any ( ( s ) => ( string ) s == "jld:CompactTest" ) )
95109 {
96- newCase . output = new JObject ( ) ;
97- newCase . output [ "error" ] = newCase . error ;
98- run = ( ) => {
99- try {
100- JsonLdProcessor . Flatten ( newCase . input , newCase . context , options ) ;
101- }
102- catch ( JsonLdError err )
103- {
104- JObject result = new JObject ( ) ;
105- result [ "error" ] = err . Message ;
106- return result ;
107- }
108- return new JValue ( ( object ) null ) ;
109- } ;
110+ run = ( ) => JsonLdProcessor . Compact ( newCase . input , newCase . context , options ) ;
110111 }
111- else if ( manifest . StartsWith ( "flatten" ) )
112+ else if ( testType . Any ( ( s ) => ( string ) s == "jld:ExpandTest" ) )
113+ {
114+ run = ( ) => JsonLdProcessor . Expand ( newCase . input , options ) ;
115+ }
116+ else if ( testType . Any ( ( s ) => ( string ) s == "jld:FlattenTest" ) )
112117 {
113- if ( ( ( string ) testcase [ "@id" ] ) . Contains ( "0044" ) )
114- {
115- options . SetCompactArrays ( false ) ;
116- }
117118 run = ( ) => JsonLdProcessor . Flatten ( newCase . input , newCase . context , options ) ;
118119 }
119- else if ( manifest . StartsWith ( "frame ") )
120+ else if ( testType . Any ( ( s ) => ( string ) s == "jld:FrameTest ") )
120121 {
121122 run = ( ) => JsonLdProcessor . Frame ( newCase . input , newCase . frame , options ) ;
122123 }
123- else if ( manifest . StartsWith ( "remote-doc" ) )
124+ else
124125 {
126+ run = ( ) => { throw new Exception ( "Couldn't find a test type, apparently." ) ; } ;
127+ }
128+
129+ if ( ( string ) manifestJson [ "name" ] == "Remote document" )
130+ {
131+ Func < JToken > innerRun = run ;
125132 run = ( ) =>
126133 {
127- var doc = new DocumentLoader ( ) . LoadDocument ( "http://json-ld.org/test-suite/tests/" + testcase [ "input" ] ) . Document ;
128- return JsonLdProcessor . Expand ( doc , options ) ;
134+ var remoteDoc = options . documentLoader . LoadDocument ( "http://json-ld.org/test-suite/tests/" + ( string ) testcase [ "input" ] ) ;
135+ newCase . input = remoteDoc . Document ;
136+ options . SetBase ( remoteDoc . DocumentUrl ) ;
137+ options . SetExpandContext ( ( JObject ) remoteDoc . Context ) ;
138+ return innerRun ( ) ;
129139 } ;
130140 }
131- else
141+
142+ if ( testType . Any ( ( s ) => ( string ) s == "jld:NegativeEvaluationTest" ) )
132143 {
133- continue ;
134- run = ( ) => { throw new Exception ( ) ; } ;
144+ Func < JToken > innerRun = run ;
145+ run = ( ) =>
146+ {
147+ try
148+ {
149+ return innerRun ( ) ;
150+ }
151+ catch ( JsonLdError err )
152+ {
153+ JObject result = new JObject ( ) ;
154+ result [ "error" ] = err . Message ;
155+ return result ;
156+ }
157+ } ;
135158 }
136159
137160 newCase . run = run ;
0 commit comments