@@ -19,7 +19,7 @@ public class ConformanceTests
19
19
public void ConformanceTestPasses ( string id , string testname , ConformanceCase conformanceCase )
20
20
{
21
21
JToken result = conformanceCase . run ( ) ;
22
- if ( id . Contains ( " error" ) )
22
+ if ( conformanceCase . error != null )
23
23
{
24
24
Assert . True ( ( ( string ) result [ "error" ] ) . StartsWith ( ( string ) conformanceCase . error ) , "Resulting error doesn't match expectations." ) ;
25
25
}
@@ -42,7 +42,7 @@ public class ConformanceCase
42
42
43
43
public class ConformanceCases : IEnumerable < object [ ] >
44
44
{
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" } ;
46
46
47
47
public ConformanceCases ( )
48
48
{
@@ -57,81 +57,104 @@ public IEnumerator<object[]> GetEnumerator()
57
57
58
58
manifestJson = GetJson ( manifest ) ;
59
59
60
- foreach ( var testcase in manifestJson [ "sequence" ] )
60
+ foreach ( JObject testcase in manifestJson [ "sequence" ] )
61
61
{
62
62
Func < JToken > run ;
63
63
ConformanceCase newCase = new ConformanceCase ( ) ;
64
64
65
65
newCase . input = GetJson ( testcase [ "input" ] ) ;
66
- newCase . output = GetJson ( testcase [ "expect" ] ) ;
67
66
newCase . context = GetJson ( testcase [ "context" ] ) ;
68
67
newCase . frame = GetJson ( testcase [ "frame" ] ) ;
69
- newCase . error = testcase [ "expect" ] ;
70
68
71
69
var options = new JsonLdOptions ( "http://json-ld.org/test-suite/tests/" + ( string ) testcase [ "input" ] ) ;
72
70
73
- if ( manifest . StartsWith ( "compact" ) )
71
+ var testType = ( JArray ) testcase [ "@type" ] ;
72
+
73
+ if ( testType . Any ( ( s ) => ( string ) s == "jld:NegativeEvaluationTest" ) )
74
74
{
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" ] ) ;
80
80
}
81
- else if ( manifest . StartsWith ( "expand" ) )
81
+ else
82
82
{
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 ) )
84
94
{
85
- options . SetBase ( "http://example/base/" ) ;
95
+ options . SetCompactArrays ( ( bool ) value ) ;
86
96
}
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 ) )
88
102
{
89
103
newCase . context = GetJson ( testcase [ "option" ] [ "expandContext" ] ) ;
90
104
options . SetExpandContext ( ( JObject ) newCase . context ) ;
91
105
}
92
- run = ( ) => JsonLdProcessor . Expand ( newCase . input , options ) ;
93
106
}
94
- else if ( manifest . StartsWith ( "error" ) )
107
+
108
+ if ( testType . Any ( ( s ) => ( string ) s == "jld:CompactTest" ) )
95
109
{
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 ) ;
110
111
}
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" ) )
112
117
{
113
- if ( ( ( string ) testcase [ "@id" ] ) . Contains ( "0044" ) )
114
- {
115
- options . SetCompactArrays ( false ) ;
116
- }
117
118
run = ( ) => JsonLdProcessor . Flatten ( newCase . input , newCase . context , options ) ;
118
119
}
119
- else if ( manifest . StartsWith ( "frame ") )
120
+ else if ( testType . Any ( ( s ) => ( string ) s == "jld:FrameTest ") )
120
121
{
121
122
run = ( ) => JsonLdProcessor . Frame ( newCase . input , newCase . frame , options ) ;
122
123
}
123
- else if ( manifest . StartsWith ( "remote-doc" ) )
124
+ else
124
125
{
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 ;
125
132
run = ( ) =>
126
133
{
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 ( ) ;
129
139
} ;
130
140
}
131
- else
141
+
142
+ if ( testType . Any ( ( s ) => ( string ) s == "jld:NegativeEvaluationTest" ) )
132
143
{
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
+ } ;
135
158
}
136
159
137
160
newCase . run = run ;
0 commit comments