resolve-uri.scm 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. (test-begin "resolve-uri")
  2. ;; Tests from http://www.ietf.org/rfc/rfc3986.txt
  3. (define base "http://a/b/c/d;p?q")
  4. (define-syntax testu
  5. (syntax-rules ()
  6. ((_ uri resolved)
  7. (begin
  8. (test-equal resolved ((resolve-uri (URI uri) (URI base)):toString))))))
  9. (define-syntax test1
  10. (syntax-rules ()
  11. ((_ uri resolved)
  12. (begin
  13. (test-equal resolved ((resolve-uri (URI uri) (URI base)):toString))
  14. (test-equal resolved ((resolve-uri uri (URI base)):toString))))))
  15. (test1 "g:h" "g:h")
  16. (test1 "g" "http://a/b/c/g")
  17. (test1 "./g" "http://a/b/c/g")
  18. (test1 "g/" "http://a/b/c/g/")
  19. (testu "/g" "http://a/g")
  20. (testu "//g" "http://g")
  21. (test1 "?y" "http://a/b/c/d;p?y")
  22. (test1 "g?y" "http://a/b/c/g?y")
  23. (test1 "#s" "http://a/b/c/d;p?q#s")
  24. (test1 "g#s" "http://a/b/c/g#s")
  25. (test1 "g?y#s" "http://a/b/c/g?y#s")
  26. (test1 ";x" "http://a/b/c/;x")
  27. (test1 "g;x" "http://a/b/c/g;x")
  28. (test1 "g;x?y#s" "http://a/b/c/g;x?y#s")
  29. (test1 "" "http://a/b/c/d;p?q")
  30. (test1 "." "http://a/b/c/")
  31. (test1 "./" "http://a/b/c/")
  32. (test1 ".." "http://a/b/")
  33. (test1 "../" "http://a/b/")
  34. (test1 "../g" "http://a/b/g")
  35. (test1 "../.." "http://a/")
  36. (test1 "../../" "http://a/")
  37. (test1 "../../g" "http://a/g")
  38. (test1 "../../../g" "http://a/g")
  39. (test1 "../../../../g" "http://a/g")
  40. (testu "/./g" "http://a/g")
  41. (testu "/../g" "http://a/g")
  42. (test1 "g." "http://a/b/c/g.")
  43. (test1 ".g" "http://a/b/c/.g")
  44. (test1 "g.." "http://a/b/c/g..")
  45. (test1 "..g" "http://a/b/c/..g")
  46. (test1 "./../g" "http://a/b/g")
  47. (test1 "./g/." "http://a/b/c/g/")
  48. (test1 "g/./h" "http://a/b/c/g/h")
  49. (test1 "g/../h" "http://a/b/c/h")
  50. (test1 "g;x=1/./y" "http://a/b/c/g;x=1/y")
  51. (test1 "g;x=1/../y" "http://a/b/c/y")
  52. (test1 "g?y/./x" "http://a/b/c/g?y/./x")
  53. (test1 "g?y/../x" "http://a/b/c/g?y/../x")
  54. (test1 "g#s/./x" "http://a/b/c/g#s/./x")
  55. (test1 "g#s/../x" "http://a/b/c/g#s/../x")
  56. (define fbase "file:///b/c/d")
  57. (define-syntax testf
  58. (syntax-rules ()
  59. ((_ uri resolved)
  60. (test-equal resolved ((resolve-uri uri (filepath fbase)):toString)))))
  61. (testf "g" "/b/c/g")
  62. (testf "g/" "/b/c/g")
  63. (testf "/g" "/g")
  64. (test-end)