@@ -57,121 +57,92 @@ describe('BaseIRI', () => {
57
57
} ) ;
58
58
59
59
describe ( 'A BaseIRI instance' , ( ) => {
60
- it ( 'should relativize http://' , ( ) => {
61
- const baseIri = new BaseIRI ( 'http://example.org/foo/' ) ;
60
+ relativizes ( 'an HTTP URL' , ' http://example.org/foo/' ,
61
+ 'http://example.org/foo/baz' , 'baz ') ;
62
62
63
- const iri = ` ${ baseIri . base } baz` ;
64
- const relativized = baseIri . toRelative ( iri ) ;
63
+ relativizes ( 'an HTTPS URL' , 'https://example.org/foo/' ,
64
+ 'https://example.org/foo/baz' , 'baz' ) ;
65
65
66
- expect ( relativized ) . toBe ( 'baz' ) ;
67
- } ) ;
66
+ relativizes ( 'a file URL' , 'file:///tmp/foo/bar' ,
67
+ 'file:///tmp/foo/bar/baz' ) ;
68
68
69
- it ( 'should relativize https://' , ( ) => {
70
- const baseIri = new BaseIRI ( 'https://example.org/ foo/') ;
69
+ relativizes ( 'a base IRI without scheme' , '/tmp/foo/bar' ,
70
+ '/tmp/ foo/bar/baz ') ;
71
71
72
- const iri = ` ${ baseIri . base } baz` ;
73
- const relativized = baseIri . toRelative ( iri ) ;
72
+ relativizes ( 'a base IRI containing //' , 'http://example.org/foo//bar' ,
73
+ 'http://example.org/foo//bar/baz' ) ;
74
74
75
- expect ( relativized ) . toBe ( 'baz' ) ;
76
- } ) ;
75
+ relativizes ( 'a base IRI containing ./' , 'http://example.org/foo/./bar' ,
76
+ 'http://example.org/foo/./bar/baz' ) ;
77
77
78
- it ( 'should not relativize a base IRI with a file scheme ', ( ) => {
79
- const baseIri = new BaseIRI ( 'file :///tmp/ foo/bar') ;
78
+ relativizes ( ' a base IRI containing ../ ', 'http://example.org/foo/../bar' ,
79
+ 'http ://example.org/ foo/../ bar/baz ') ;
80
80
81
- const iri = ` ${ baseIri . base } /baz` ;
82
- const relativized = baseIri . toRelative ( iri ) ;
81
+ relativizes ( 'a base IRI ending in //' , 'http://example.org/foo//' ,
82
+ 'http://example.org/foo//baz' ) ;
83
83
84
- expect ( relativized ) . toBe ( iri ) ;
85
- } ) ;
84
+ relativizes ( 'a base IRI ending in ./' , 'http://example.org/foo/.' ,
85
+ 'http://example.org/foo/./baz' ) ;
86
86
87
- it ( 'should not relativize a base IRI without scheme ', ( ) => {
88
- const baseIri = new BaseIRI ( '/tmp/ foo/bar ') ;
87
+ relativizes ( ' a base IRI ending in ../ ', 'http://example.org/foo/..' ,
88
+ 'http://example.org/ foo/../baz ') ;
89
89
90
- const iri = ` ${ baseIri . base } /baz` ;
91
- const relativized = baseIri . toRelative ( iri ) ;
90
+ relativizes ( 'an IRI ending in //' , 'http://example.org/foo/' ,
91
+ 'http://example.org/foo//' ) ;
92
92
93
- expect ( relativized ) . toBe ( iri ) ;
94
- } ) ;
93
+ relativizes ( 'an IRI ending in /.' , 'http://example.org/foo/' ,
94
+ 'http://example.org/foo/.' ) ;
95
95
96
- it ( 'should not relativize a base IRI containing `//`' , ( ) => {
97
- const baseIri = new BaseIRI ( 'http://example.org/foo//bar ' ) ;
96
+ relativizes ( 'an IRI ending in /..' , 'http://example.org/foo/' ,
97
+ 'http://example.org/foo/.. ' ) ;
98
98
99
- const iri = ` ${ baseIri . base } /baz` ;
100
- const relativized = baseIri . toRelative ( iri ) ;
99
+ relativizes ( 'an IRI ending in /./' , 'http://example.org/foo/' ,
100
+ 'http://example.org/foo/./' ) ;
101
101
102
- expect ( relativized ) . toBe ( iri ) ;
103
- } ) ;
102
+ relativizes ( 'an IRI ending in /../' , 'http://example.org/foo/' ,
103
+ 'http://example.org/foo/../' ) ;
104
104
105
- it ( 'should not relativize a base IRI containing `/./`' , ( ) => {
106
- const baseIri = new BaseIRI ( 'http://example.org/foo/./bar ' ) ;
105
+ relativizes ( 'an IRI containing // at the matching position' , 'http://example.org/foo/' ,
106
+ 'http://example.org/foo//baz ' ) ;
107
107
108
- const iri = ` ${ baseIri . base } /baz` ;
109
- const relativized = baseIri . toRelative ( iri ) ;
108
+ relativizes ( 'an IRI containing ./ at the matching position' , 'http://example.org/foo/' ,
109
+ 'http://example.org/foo/./baz' ) ;
110
110
111
- expect ( relativized ) . toBe ( iri ) ;
112
- } ) ;
111
+ relativizes ( 'an IRI containing ../ at the matching position' , 'http://example.org/foo/' ,
112
+ 'http://example.org/foo/../baz' ) ;
113
113
114
- it ( 'should not relativize a base IRI containing `/../` ', ( ) => {
115
- const baseIri = new BaseIRI ( 'http://example.org/foo/../ bar' ) ;
114
+ relativizes ( 'an IRI containing // ', 'http://example.org/foo/' ,
115
+ 'http://example.org/foo/bar//baz ' ) ;
116
116
117
- const iri = ` ${ baseIri . base } /baz` ;
118
- const relativized = baseIri . toRelative ( iri ) ;
117
+ relativizes ( 'an IRI containing ./' , 'http://example.org/foo/' ,
118
+ 'http://example.org/foo/bar/./baz' ) ;
119
119
120
- expect ( relativized ) . toBe ( iri ) ;
121
- } ) ;
120
+ relativizes ( 'an IRI containing ../' , 'http://example.org/foo/' ,
121
+ 'http://example.org/foo/bar/../baz' ) ;
122
122
123
- it ( 'should not relativize a base IRI ending in `/.`' , ( ) => {
124
- const baseIri = new BaseIRI ( 'http://example.org/foo/. ' ) ;
123
+ relativizes ( 'an IRI containing // in its query string' , 'http://example.org/foo/' ,
124
+ 'http://example.org/foo/baz?bar//baz' , 'baz?bar//baz ') ;
125
125
126
- const iri = ` ${ baseIri . base } /baz` ;
127
- const relativized = baseIri . toRelative ( iri ) ;
126
+ relativizes ( 'an IRI containing ./ in its query string' , 'http://example.org/foo/' ,
127
+ 'http://example.org/foo/baz?bar/./baz' , 'baz?bar/./baz' ) ;
128
128
129
- expect ( relativized ) . toBe ( iri ) ;
130
- } ) ;
129
+ relativizes ( 'an IRI containing ../ in its query string' , 'http://example.org/foo/' ,
130
+ 'http://example.org/foo/baz?bar/../baz' , 'baz?bar/../baz' ) ;
131
131
132
- it ( 'should not relativize a base IRI ending in `/..`' , ( ) => {
133
- const baseIri = new BaseIRI ( 'http://example.org/foo/.. ' ) ;
132
+ relativizes ( 'an IRI containing // in its fragment' , 'http://example.org/foo/' ,
133
+ 'http://example.org/foo/baz#bar//baz' , 'baz#bar//baz ') ;
134
134
135
- const iri = ` ${ baseIri . base } /baz` ;
136
- const relativized = baseIri . toRelative ( iri ) ;
135
+ relativizes ( 'an IRI containing ./ in its fragment' , 'http://example.org/foo/' ,
136
+ 'http://example.org/foo/baz#bar/./baz' , 'baz#bar/./baz' ) ;
137
137
138
- expect ( relativized ) . toBe ( iri ) ;
139
- } ) ;
140
-
141
- it ( 'should not relativize an IRI with file scheme' , ( ) => {
142
- const baseIri = new BaseIRI ( 'http://example.org/foo/' ) ;
143
-
144
- const iri = 'file:///tmp/foo/bar' ;
145
- const relativized = baseIri . toRelative ( iri ) ;
146
-
147
- expect ( relativized ) . toBe ( iri ) ;
148
- } ) ;
149
-
150
- it ( 'should not relativize an IRI containing `//`' , ( ) => {
151
- const baseIri = new BaseIRI ( 'http://example.org/foo/' ) ;
152
-
153
- const iri = 'http://example.org/foo//bar' ;
154
- const relativized = baseIri . toRelative ( iri ) ;
155
-
156
- expect ( relativized ) . toBe ( iri ) ;
157
- } ) ;
158
-
159
- it ( 'should not relativize an IRI containing `/./`' , ( ) => {
160
- const baseIri = new BaseIRI ( 'http://example.org/foo/' ) ;
161
-
162
- const iri = 'http://example.org/foo/./bar' ;
163
- const relativized = baseIri . toRelative ( iri ) ;
164
-
165
- expect ( relativized ) . toBe ( iri ) ;
166
- } ) ;
167
-
168
- it ( 'should not relativize an IRI containing `/../`' , ( ) => {
169
- const baseIri = new BaseIRI ( 'http://example.org/foo/' ) ;
170
-
171
- const iri = 'http://example.org/foo/../bar' ;
172
- const relativized = baseIri . toRelative ( iri ) ;
173
-
174
- expect ( relativized ) . toBe ( iri ) ;
175
- } ) ;
138
+ relativizes ( 'an IRI containing ../ in its fragment' , 'http://example.org/foo/' ,
139
+ 'http://example.org/foo/baz#bar/../baz' , 'baz#bar/../baz' ) ;
176
140
} ) ;
177
141
} ) ;
142
+
143
+ function relativizes ( description , base , absolute , relative ) {
144
+ it ( `${ relative ? 'relativizes' : 'does not relativize' } ${ description } ` , ( ) => {
145
+ const baseIri = new BaseIRI ( base ) ;
146
+ expect ( baseIri . toRelative ( absolute ) ) . toBe ( relative || absolute ) ;
147
+ } ) ;
148
+ }
0 commit comments