11import { BaseIRI } from '../src' ;
22
33describe ( 'BaseIRI' , ( ) => {
4+ it ( 'should advertise support for base IRIs' , ( ) => {
5+ expect ( BaseIRI . supports ( 'http://example.org/' ) ) . toBe ( true ) ;
6+
7+ expect ( BaseIRI . supports ( ':' ) ) . toBe ( false ) ;
8+ expect ( BaseIRI . supports ( '/' ) ) . toBe ( false ) ;
9+
10+ expect ( BaseIRI . supports ( 'a:' ) ) . toBe ( true ) ;
11+ expect ( BaseIRI . supports ( 'abc:' ) ) . toBe ( true ) ;
12+ expect ( BaseIRI . supports ( '#:' ) ) . toBe ( false ) ;
13+ expect ( BaseIRI . supports ( '?:' ) ) . toBe ( false ) ;
14+ expect ( BaseIRI . supports ( 'a?b#c:' ) ) . toBe ( false ) ;
15+
16+ expect ( BaseIRI . supports ( '?abc:' ) ) . toBe ( false ) ;
17+ expect ( BaseIRI . supports ( '#abc:' ) ) . toBe ( false ) ;
18+ expect ( BaseIRI . supports ( '/foo/bar?abc:' ) ) . toBe ( false ) ;
19+ expect ( BaseIRI . supports ( '/foo/bar#abc:' ) ) . toBe ( false ) ;
20+
21+ expect ( BaseIRI . supports ( 'file:' ) ) . toBe ( false ) ;
22+ expect ( BaseIRI . supports ( 'file:abc' ) ) . toBe ( false ) ;
23+ expect ( BaseIRI . supports ( 'file:/abc' ) ) . toBe ( false ) ;
24+ expect ( BaseIRI . supports ( 'file://abc' ) ) . toBe ( false ) ;
25+ expect ( BaseIRI . supports ( 'file:///abc' ) ) . toBe ( false ) ;
26+ expect ( BaseIRI . supports ( 'FILE:abc' ) ) . toBe ( false ) ;
27+
28+ expect ( BaseIRI . supports ( 'http://example.org/foo/' ) ) . toBe ( true ) ;
29+ expect ( BaseIRI . supports ( 'http://example.org/foo//' ) ) . toBe ( false ) ;
30+ expect ( BaseIRI . supports ( 'http://example.org/foo/.' ) ) . toBe ( false ) ;
31+ expect ( BaseIRI . supports ( 'http://example.org/foo/./' ) ) . toBe ( false ) ;
32+ expect ( BaseIRI . supports ( 'http://example.org/foo/..' ) ) . toBe ( false ) ;
33+ expect ( BaseIRI . supports ( 'http://example.org/foo/../' ) ) . toBe ( false ) ;
34+ expect ( BaseIRI . supports ( 'http://example.org/foo//bar' ) ) . toBe ( false ) ;
35+ expect ( BaseIRI . supports ( 'http://example.org/foo/./bar' ) ) . toBe ( false ) ;
36+ expect ( BaseIRI . supports ( 'http://example.org/foo/../bar' ) ) . toBe ( false ) ;
37+
38+ expect ( BaseIRI . supports ( 'http://example.org/foo?/' ) ) . toBe ( true ) ;
39+ expect ( BaseIRI . supports ( 'http://example.org/foo?//' ) ) . toBe ( true ) ;
40+ expect ( BaseIRI . supports ( 'http://example.org/foo?/.' ) ) . toBe ( true ) ;
41+ expect ( BaseIRI . supports ( 'http://example.org/foo?/./' ) ) . toBe ( true ) ;
42+ expect ( BaseIRI . supports ( 'http://example.org/foo?/..' ) ) . toBe ( true ) ;
43+ expect ( BaseIRI . supports ( 'http://example.org/foo?/../' ) ) . toBe ( true ) ;
44+ expect ( BaseIRI . supports ( 'http://example.org/foo?//bar' ) ) . toBe ( true ) ;
45+ expect ( BaseIRI . supports ( 'http://example.org/foo?/./bar' ) ) . toBe ( true ) ;
46+ expect ( BaseIRI . supports ( 'http://example.org/foo?/../bar' ) ) . toBe ( true ) ;
47+
48+ expect ( BaseIRI . supports ( 'http://example.org/foo#/' ) ) . toBe ( true ) ;
49+ expect ( BaseIRI . supports ( 'http://example.org/foo#//' ) ) . toBe ( true ) ;
50+ expect ( BaseIRI . supports ( 'http://example.org/foo#/.' ) ) . toBe ( true ) ;
51+ expect ( BaseIRI . supports ( 'http://example.org/foo#/./' ) ) . toBe ( true ) ;
52+ expect ( BaseIRI . supports ( 'http://example.org/foo#/..' ) ) . toBe ( true ) ;
53+ expect ( BaseIRI . supports ( 'http://example.org/foo#/../' ) ) . toBe ( true ) ;
54+ expect ( BaseIRI . supports ( 'http://example.org/foo#//bar' ) ) . toBe ( true ) ;
55+ expect ( BaseIRI . supports ( 'http://example.org/foo#/./bar' ) ) . toBe ( true ) ;
56+ expect ( BaseIRI . supports ( 'http://example.org/foo#/../bar' ) ) . toBe ( true ) ;
57+ } ) ;
58+
459 describe ( 'A BaseIRI instance' , ( ) => {
560 it ( 'should relativize http://' , ( ) => {
661 const baseIri = new BaseIRI ( 'http://example.org/foo/' ) ;
762
8- const iri = `${ baseIri . value } baz` ;
63+ const iri = `${ baseIri . base } baz` ;
964 const relativized = baseIri . toRelative ( iri ) ;
1065
1166 expect ( relativized ) . toBe ( 'baz' ) ;
@@ -14,52 +69,70 @@ describe('BaseIRI', () => {
1469 it ( 'should relativize https://' , ( ) => {
1570 const baseIri = new BaseIRI ( 'https://example.org/foo/' ) ;
1671
17- const iri = `${ baseIri . value } baz` ;
72+ const iri = `${ baseIri . base } baz` ;
1873 const relativized = baseIri . toRelative ( iri ) ;
1974
2075 expect ( relativized ) . toBe ( 'baz' ) ;
2176 } ) ;
2277
23- it ( 'should not relativize when initializing with a file scheme IRI ' , ( ) => {
78+ it ( 'should not relativize a base IRI with a file scheme' , ( ) => {
2479 const baseIri = new BaseIRI ( 'file:///tmp/foo/bar' ) ;
2580
26- const iri = `${ baseIri . value } /baz` ;
81+ const iri = `${ baseIri . base } /baz` ;
2782 const relativized = baseIri . toRelative ( iri ) ;
2883
2984 expect ( relativized ) . toBe ( iri ) ;
3085 } ) ;
3186
32- it ( 'should not relativize when initializing with a IRI without scheme' , ( ) => {
87+ it ( 'should not relativize a base IRI without scheme' , ( ) => {
3388 const baseIri = new BaseIRI ( '/tmp/foo/bar' ) ;
3489
35- const iri = `${ baseIri . value } /baz` ;
90+ const iri = `${ baseIri . base } /baz` ;
3691 const relativized = baseIri . toRelative ( iri ) ;
3792
3893 expect ( relativized ) . toBe ( iri ) ;
3994 } ) ;
4095
41- it ( 'should not relativize when initializing with a IRI containing `//`' , ( ) => {
96+ it ( 'should not relativize a base IRI containing `//`' , ( ) => {
4297 const baseIri = new BaseIRI ( 'http://example.org/foo//bar' ) ;
4398
44- const iri = `${ baseIri . value } /baz` ;
99+ const iri = `${ baseIri . base } /baz` ;
45100 const relativized = baseIri . toRelative ( iri ) ;
46101
47102 expect ( relativized ) . toBe ( iri ) ;
48103 } ) ;
49104
50- it ( 'should not relativize when initializing with a IRI containing `/./`' , ( ) => {
105+ it ( 'should not relativize a base IRI containing `/./`' , ( ) => {
51106 const baseIri = new BaseIRI ( 'http://example.org/foo/./bar' ) ;
52107
53- const iri = `${ baseIri . value } /baz` ;
108+ const iri = `${ baseIri . base } /baz` ;
54109 const relativized = baseIri . toRelative ( iri ) ;
55110
56111 expect ( relativized ) . toBe ( iri ) ;
57112 } ) ;
58113
59- it ( 'should not relativize when initializing with a IRI containing `/../`' , ( ) => {
114+ it ( 'should not relativize a base IRI containing `/../`' , ( ) => {
60115 const baseIri = new BaseIRI ( 'http://example.org/foo/../bar' ) ;
61116
62- const iri = `${ baseIri . value } /baz` ;
117+ const iri = `${ baseIri . base } /baz` ;
118+ const relativized = baseIri . toRelative ( iri ) ;
119+
120+ expect ( relativized ) . toBe ( iri ) ;
121+ } ) ;
122+
123+ it ( 'should not relativize a base IRI ending in `/.`' , ( ) => {
124+ const baseIri = new BaseIRI ( 'http://example.org/foo/.' ) ;
125+
126+ const iri = `${ baseIri . base } /baz` ;
127+ const relativized = baseIri . toRelative ( iri ) ;
128+
129+ expect ( relativized ) . toBe ( iri ) ;
130+ } ) ;
131+
132+ it ( 'should not relativize a base IRI ending in `/..`' , ( ) => {
133+ const baseIri = new BaseIRI ( 'http://example.org/foo/..' ) ;
134+
135+ const iri = `${ baseIri . base } /baz` ;
63136 const relativized = baseIri . toRelative ( iri ) ;
64137
65138 expect ( relativized ) . toBe ( iri ) ;
0 commit comments