~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to lib/system/test/URITest.hx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-02-16 05:36:32 UTC
  • Revision ID: eda-qa@disemia.com-20100216053632-60lt7fndfi3fgblw
first

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* <license>
 
2
 * This file is part of the dis-Emi-A HaXe Library. Copyright © edA-qa mort-ora-y
 
3
 * For full copyright and license information please refer to doc/license.txt.
 
4
 * </license> 
 
5
 */
 
6
package system.test;
 
7
 
 
8
import system.URI;
 
9
 
 
10
class URITest extends haxe.unit.TestCaseX
 
11
{
 
12
        public function testParseAbsolute()
 
13
        {
 
14
                var uri = URI.parsed( "http://user:pass@somewhere.com:22/pa%20th/to/file.txt?query=one#frag" );
 
15
                
 
16
                assertEquals( "http", uri.scheme );
 
17
                assertEquals( "user:pass@somewhere.com:22", uri.authority );
 
18
                assertEquals( "/pa th/to/file.txt", uri.path );
 
19
                assertEquals( "query=one", uri.query );
 
20
                assertEquals( "frag", uri.fragment );
 
21
                assertFalse( uri.isRelative() );
 
22
                
 
23
                //details checking
 
24
                assertEquals( "user:pass", uri.userinfo );
 
25
                assertEquals( "somewhere.com", uri.host );
 
26
                assertEquals( "22", uri.port );
 
27
                assertEquals( "/pa th/to/", uri.pathdir );
 
28
                assertEquals( "file.txt", uri.filename );
 
29
                
 
30
                //assert toString
 
31
                assertEquals( "http://user:pass@somewhere.com:22/pa th/to/file.txt?query=one#frag", uri.exportFromNormal() );
 
32
                
 
33
                //extremely short test
 
34
                uri = URI.parsed( "ft%70://%74ommy.com" );
 
35
                assertEquals( "ftp", uri.scheme );
 
36
                assertEquals( "tommy.com", uri.authority );
 
37
                assertEquals( "", uri.path );
 
38
                assertNull( uri.query );
 
39
                assertNull( uri.fragment );
 
40
                
 
41
                //absent details check
 
42
                assertNull( uri.userinfo );
 
43
                assertNull( uri.port );
 
44
                assertEquals( "", uri.pathdir );
 
45
                assertEquals( "", uri.filename );
 
46
                
 
47
                assertEquals( "ftp://tommy.com", uri.exportFromNormal() );
 
48
                assertEquals( "ft%70://%74ommy.com", uri.exportFromRaw() );
 
49
                
 
50
                //windows share
 
51
                uri = URI.parsed( "file://server/../.p%3Fath/file.doc", "ascii" );
 
52
                assertEquals( "file", uri.scheme );
 
53
                assertEquals( "server", uri.authority );
 
54
                assertEquals( "/.p?ath/file.doc", uri.path );
 
55
                assertEquals( "/.p%3Fath/file.doc", uri.pathRaw );
 
56
                assertNull( uri.query );
 
57
                assertNull( uri.fragment );
 
58
                
 
59
                assertEquals( "file://server/.p%3Fath/file.doc", uri.exportFromNormal() );
 
60
                
 
61
                //local file
 
62
                uri = URI.parsed( "file:///tmp/./..out/sub/../T%C3%80st%E3%82%A2.swf" );
 
63
                assertEquals( "file", uri.scheme );
 
64
                assertEquals( "", uri.authority );
 
65
                assertEquals( "/tmp/..out/TÀstア.swf", uri.path );
 
66
                
 
67
                assertEquals( "file:///tmp/..out/TÀstア.swf", uri.exportFromNormal() );
 
68
                
 
69
                //isbn check
 
70
                uri = URI.parsed( "urn:isbn:0451450523" );
 
71
                assertEquals( "urn", uri.scheme );
 
72
                assertEquals( "isbn", uri.namespaceID );
 
73
                assertEquals( "0451450523", uri.namespaceString );
 
74
                assertEquals( "urn:isbn:0451450523", uri.toString() );
 
75
                
 
76
                assertNull( uri.authority );
 
77
                assertNull( uri.query );
 
78
                assertNull( uri.fragment );
 
79
        }
 
80
        
 
81
        public function testParseRelative()
 
82
        {
 
83
                var uri = URI.parsed( "/quick/now?query", true );
 
84
                assertEquals( "/quick/now", uri.path );
 
85
                assertEquals( "query", uri.query );
 
86
                assertEquals( "/quick/now?query", uri.toString() );
 
87
                assertTrue( uri.isRelative() );
 
88
        }
 
89
        
 
90
        public function testReference() 
 
91
        {
 
92
                //taken from 5.4 in the RFC
 
93
                var base = URI.parsed( "http://a/b/c/d;p?q" );
 
94
                assertEquals( "http://a/b/c/d;p?q", base.toString() );
 
95
                var checkAll = [
 
96
                        //Normal
 
97
                        [ "g:h"                   ,  "g:h" ],
 
98
                        [ "g"                            ,  "http://a/b/c/g" ],
 
99
                        [ "./g"                   ,  "http://a/b/c/g" ],
 
100
                        [ "g/"                          ,  "http://a/b/c/g/" ],
 
101
                        [ "/g"                          ,  "http://a/g" ],
 
102
                        [ "//g"                   ,  "http://g" ],
 
103
                        [ "?y"                          ,  "http://a/b/c/d;p?y" ],
 
104
                        [ "g?y"                   ,  "http://a/b/c/g?y" ],
 
105
                        [ "#s"                          ,  "http://a/b/c/d;p?q#s" ],
 
106
                        [ "g#s"                   ,  "http://a/b/c/g#s" ],
 
107
                        [ "g?y#s"                       ,  "http://a/b/c/g?y#s" ],
 
108
                        [ ";x"                          ,  "http://a/b/c/;x" ],
 
109
                        [ "g;x"                   ,  "http://a/b/c/g;x" ],
 
110
                        [ "g;x?y#s"              ,  "http://a/b/c/g;x?y#s" ],
 
111
                        [ ""                              ,  "http://a/b/c/d;p?q" ],
 
112
                        [ "."                            ,  "http://a/b/c/" ],
 
113
                        [ "./"                          ,  "http://a/b/c/" ],
 
114
                        [ ".."                          ,  "http://a/b/" ],
 
115
                        [ "../"                   ,  "http://a/b/" ],
 
116
                        [ "../g"                         ,  "http://a/b/g" ],
 
117
                        [ "../.."                       ,  "http://a/" ],
 
118
                        [ "../../"                ,  "http://a/" ],
 
119
                        [ "../../g"              ,  "http://a/g"         ],
 
120
                        
 
121
                        //Abnormal
 
122
                        ["../../../g"    ,  "http://a/g"],
 
123
                        ["../../../../g" ,  "http://a/g"],              
 
124
                        
 
125
                        //Similarly...
 
126
                        [ "/./g"                         ,  "http://a/g"],
 
127
                        ["/../g"                        ,  "http://a/g"],
 
128
                        ["g."                           ,  "http://a/b/c/g."],
 
129
                        [".g"                           ,  "http://a/b/c/.g"],
 
130
                        ["g.."                    ,  "http://a/b/c/g.."],
 
131
                        ["..g"                    ,  "http://a/b/c/..g"],
 
132
                        
 
133
                        //Less likely...
 
134
                        ["./../g"                 ,  "http://a/b/g"],
 
135
                        ["./g/."                        ,  "http://a/b/c/g/"],
 
136
                        ["g/./h"                        ,  "http://a/b/c/g/h"],
 
137
                        ["g/../h"                 ,  "http://a/b/c/h"],
 
138
                        ["g;x=1/./y"      ,  "http://a/b/c/g;x=1/y"],
 
139
                        ["g;x=1/../y"    ,  "http://a/b/c/y"],
 
140
                        
 
141
                        //Some apps...
 
142
                        ["g?y/./x"               ,  "http://a/b/c/g?y/./x"],
 
143
                        ["g?y/../x"             ,  "http://a/b/c/g?y/../x"],
 
144
                        ["g#s/./x"               ,  "http://a/b/c/g#s/./x"],
 
145
                        ["g#s/../x"             ,  "http://a/b/c/g#s/../x"],            
 
146
                        
 
147
                        //strict...
 
148
                        [ "http:g"        ,  "http:g" ] //        ; for strict parsers
 
149
                        ];
 
150
                        
 
151
                for( check in checkAll )
 
152
                {
 
153
                        var rel = check[0];
 
154
                        var expect = check[1];
 
155
                        var result = base.transformReference( URI.parsed( rel, true ) );
 
156
                        assertEquals( expect, result.toString() );
 
157
                }
 
158
        }
 
159
}