Changeset 25791 in project


Ignore:
Timestamp:
01/08/12 14:02:17 (9 years ago)
Author:
sjamaan
Message:

uri-common: Add make-uri constructor (for #699)

Location:
release/4/uri-common/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/uri-common/trunk/tests/run.scm

    r20989 r25791  
    99     ("http:" http)
    1010     ("" #f))
     11    ("host" ,uri-host
     12     ("http://a" "a")
     13     ("http://a:8080" "a")
     14     ("//a" "a")
     15     ("/foo" #f)
     16     ("http://" "") ; Correct?  Seems so, considering the next example
     17     ("http://:123" ""))
    1118    ("port" ,uri-port
    1219     ("http://a" 80)
     
    121128            update-cases))
    122129
     130(define make-cases
     131  `(("http://example.com:123/foo/bar?a=b;c=d#location"
     132     scheme: http host: "example.com" port: 123 path: (/ "foo" "bar")
     133     query: ((a . "b") (c . "d")) fragment: "location")
     134    ("//example.com:123/foo/bar?a=b;c=d#location"
     135     host: "example.com" port: 123 path: (/ "foo" "bar")
     136     query: ((a . "b") (c . "d")) fragment: "location")
     137    ("/foo/bar?a=b;c=d#location"
     138     port: 123 path: (/ "foo" "bar") query: ((a . "b") (c . "d")) fragment: "location")
     139    ("foo/bar?a=b;c=d#location"
     140     path: ("foo" "bar") query: ((a . "b") (c . "d")) fragment: "location")
     141    ("/?a=b;c=d#location"
     142     path: (/ "") query: ((a . "b") (c . "d")) fragment: "location")
     143    ("?a=b;c=d#location"
     144     query: ((a . "b") (c . "d")) fragment: "location")
     145    ("#location"
     146     fragment: "location")
     147    ("//example.com?a=b;c=d"
     148     host: "example.com" query: ((a . "b") (c . "d")))
     149    ("//example.com#location"
     150     host: "example.com" fragment: "location")
     151    ("/"
     152     path: (/ ""))
     153    ("/"
     154     path: (/))                         ; Not sure if this works by accident
     155    (""
     156     path: ())
     157    ("")))
     158
     159(test-group "manual constructor"
     160  (for-each (lambda (u)
     161              (let* ((input (cdr u))
     162                     (oexp (first u))
     163                     (oact (apply make-uri input)))
     164                (test (sprintf "~S -> ~S" input oexp)
     165                      oexp (uri->string oact))))
     166            make-cases))
     167
    123168;; These are more specific tests for the query cases above, but
    124169;; on the direct low-level interface to make it less cumbersome
  • release/4/uri-common/trunk/uri-common.meta

    r23255 r25791  
    1818 ; A list of eggs uri-generic depends on.
    1919
    20  (depends (uri-generic 2.3) defstruct matchable)
     20 (depends (uri-generic 2.37) defstruct matchable)
    2121 (test-depends test)
    2222
  • release/4/uri-common/trunk/uri-common.scm

    r21371 r25791  
    55;; encoding/decoding
    66;;
    7 ; Copyright (c) 2008-2010, Peter Bex
     7; Copyright (c) 2008-2012, Peter Bex
    88; All rights reserved.
    99;
     
    4343  (uri-reference uri-reference? absolute-uri absolute-uri? relative-ref?
    4444   uri->uri-generic uri-generic->uri uri->list
    45    update-uri uri? uri-scheme uri-username uri-password
     45   make-uri update-uri uri? uri-scheme uri-username uri-password
    4646   uri-host uri-port uri-path uri-query uri-fragment
    4747   uri->string form-urlencode form-urldecode form-urlencoded-separator
     
    153153    (or (generic:uri-port u)
    154154        (alist-ref (generic:uri-scheme u) default-ports))))
     155
     156;;; Constructor
     157(define (make-uri . key/values)
     158  (apply update-uri (make-URI-common generic: (generic:make-uri)) key/values))
    155159
    156160;;; Updaters
Note: See TracChangeset for help on using the changeset viewer.