home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / test / macpath.sml < prev    next >
Encoding:
Text File  |  1995-09-17  |  16.6 KB  |  396 lines  |  [TEXT/Moml]

  1. (* test/macpath.sml 6 -- for Unix, 1995-05-23 *)
  2.  
  3. (* Mac: changed "/" to ":"; isAbs changed appropriately
  4.         lots of other changes -- 17Sep95 e *)
  5.  
  6. use "auxil.sml";
  7.  
  8. local 
  9.     open Path
  10. in
  11.     
  12. val test1a = 
  13.     check'(fn _ => fromString "" = {isAbs=true, vol = "", arcs = []});
  14. val test1b = 
  15.     check'(fn _ => fromString ":" = {isAbs=false, vol="", arcs=[""]});
  16. val test1c = 
  17.     check'(fn _ => fromString "::" = {isAbs=false, vol="", arcs=["", ""]});
  18. val test1d = 
  19.     check'(fn _ => fromString "a" = {isAbs=false, vol = "", arcs = ["a"]});
  20. val test1e = 
  21.     check'(fn _ => fromString ":a" = {isAbs=false, vol="", arcs=["a"]});
  22. val test1f = 
  23.     check'(fn _ => fromString "::a" = {isAbs=false, vol="", arcs=["","a"]});
  24. val test1g = 
  25.     check'(fn _ => fromString "a:" = {isAbs=true, vol = "", arcs = ["a", ""]});
  26. val test1h = 
  27.     check'(fn _ => fromString "a::" = {isAbs=true, vol = "", arcs = ["a", "", ""]});
  28. val test1i = 
  29.     check'(fn _ => fromString "a:b" = {isAbs=true, vol = "", arcs = ["a", "b"]});
  30. val test1j = 
  31.     check'(fn _ => fromString "a.b:c" = {isAbs=true, vol = "", arcs = ["a.b", "c"]});
  32. val test1k = 
  33.     check'(fn _ => fromString "a.b:c:" = {isAbs=true, vol = "", arcs = ["a.b", "c", ""]});
  34. val test1l = 
  35.     check'(fn _ => fromString "a:.:c" = {isAbs=true, vol = "", arcs = ["a", ".", "c"]});
  36. val test1m = 
  37.     check'(fn _ => fromString "a:..:c" = {isAbs=true, vol = "", arcs = ["a", "..", "c"]});
  38. val test1n = 
  39.     check'(fn _ => fromString "." = {isAbs=false, vol = "", arcs = ["."]});
  40.  
  41. val test2a =
  42.     check'(fn _ => toString {isAbs=true, vol = "", arcs = []} = "");
  43. val test2b = 
  44.     check'(fn _ => toString {isAbs=false, vol="", arcs=[""]} = ":");
  45. val test2c = 
  46.     check'(fn _ => toString {isAbs=false, vol="", arcs=["",""]} = "::");
  47. val test2d = 
  48.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a"]} = "a");
  49. val test2e = 
  50.     check'(fn _ => toString {isAbs=false, vol="", arcs=["a"]} = ":a");
  51. val test2f = 
  52.     check'(fn _ => toString {isAbs=false, vol="", arcs=["","a"]} = "::a");
  53. val test2g = 
  54.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", ""]} = "a:");
  55. val test2h = 
  56.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", "", ""]} = "a::");
  57. val test2i = 
  58.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", "b"]} = "a:b");
  59. val test2j = 
  60.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a.b", "c"]} = "a.b:c");
  61. val test2k = 
  62.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a.b", "c", ""]} = "a.b:c:");
  63. val test2l = 
  64.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", ".", "c"]} = "a:.:c");
  65. val test2m = 
  66.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", "..", "c"]} = "a:..:c");
  67. val test2n = 
  68.     check'(fn _ => toString {isAbs=false, vol="", arcs=["a", "..", "c"]} = ":a:..:c");
  69. val test2o = (toString {isAbs=true, vol = "foo", arcs =  ["", "a"]} seq "WRONG")
  70.              handle Path => "OK" | _ => "WRONG";
  71. val test2p = 
  72.     (toString {isAbs=true, vol = "C:", arcs =  ["windows"]} seq "WRONG")
  73.     handle Path => "OK" | _ => "WRONG";
  74.  
  75. val test3b = 
  76.     check'(fn _ => getVolume ":" = "");
  77. val test3c = 
  78.     check'(fn _ => getVolume "::" = "");
  79. val test3d = 
  80.     check'(fn _ => getVolume "a::b:c:" = "");
  81. val test3e = 
  82.     check'(fn _ => getVolume ".:" = "");
  83. val test3f = 
  84.     check'(fn _ => getVolume "..:" = "");
  85. val test3g = 
  86.     check'(fn _ => getVolume "" = "");
  87. val test3h = 
  88.     check'(fn _ => getVolume "C:" = "");
  89.  
  90. val test4a = 
  91.     check'(fn _ => 
  92.            not (List.all isRelative ["", ".", "..", "a::"])
  93.            andalso List.exists isRelative [":", ":a", "::"]);
  94. val test4b = 
  95.     check'(fn _ => 
  96.            not (List.all isAbsolute [":", ":a", "::", ":.", ":.."])
  97.            andalso List.exists isAbsolute ["", ".", "..", "a::"]);
  98.  
  99. val test5a = 
  100.     check'(fn _ => 
  101.            getParent ":" = "::"
  102.            andalso getParent "a" = ":" (* flip a coin -- consistent *)
  103.            andalso getParent "a:" = "" (* flip a coin -- consistent *)
  104.            andalso getParent ":a" = ":"
  105.            andalso getParent ":a:" = ":"
  106.            andalso getParent "a:::" = "a::::"
  107.            andalso getParent "a:b" = "a:"
  108.            andalso getParent "a:b:" = "a:"
  109.            andalso getParent ":a:b" = ":a:"
  110.            andalso getParent ":a:b:" = ":a:"
  111.            andalso getParent ":a::b:" = ":a::" (* not canonical, but input wasn't either *)
  112.            andalso getParent "::" = ":::"
  113.            andalso getParent ":::" = "::::"
  114.            andalso getParent "" = "");
  115.  
  116. val test6a = 
  117.     check'(fn _ => 
  118.            concat("a", "b") = ":a:b"
  119.            andalso concat("a", ":b:c") = ":a:b:c"
  120.            andalso concat(":", ":b:c") = ":b:c"
  121.            andalso concat("", ":b:c") = "b:c"
  122.            andalso concat(":a", ":b:c") = ":a:b:c"
  123.            andalso concat("a:", ":b:c") = "a:b:c"
  124.            andalso concat("a::", ":b:c") = "a::b:c"
  125.            andalso concat("a:b", "::") = "a:b::"
  126.            andalso concat("a:b", "::c") = "a:b::c");
  127. val test6b = (concat ("a", "b:") seq "WRONG")
  128.              handle Path => "OK" | _ => "WRONG";
  129.  
  130. val test7a = 
  131.     check'(fn _ => 
  132.            mkAbsolute("a:b", "c:d") = "a:b"
  133.            andalso mkAbsolute("", "c:d") = ""
  134.            andalso mkAbsolute(":a:b", "c:d") = "c:d:a:b");
  135. val test7b = (mkAbsolute("a:", ":c:d") seq "WRONG")
  136.              handle Path => "OK" | _ => "WRONG";
  137. val test7c = (mkAbsolute(":a", ":c:d") seq "WRONG")
  138.               handle Path => "OK" | _ => "WRONG";
  139.  
  140. val test8a = 
  141.     check'(fn _ => 
  142.                    mkRelative(":a:b", "c:d")     = ":a:b"
  143.            andalso mkRelative("", "a:b:c")       = "::::"
  144.            andalso mkRelative("a:", "a:b:c")     = ":::"
  145.            andalso mkRelative("a:b", "a:c")      = "::b"
  146.            andalso mkRelative("a:b", "a:c:")     = "::b"
  147.            andalso mkRelative("a:b:", "a:c")     = "::b:"
  148.            andalso mkRelative("a:b:", "a:c:")    = "::b:"
  149.            andalso mkRelative(":", "")           = ":"
  150.            andalso mkRelative("", "")            = ":"
  151.            andalso mkRelative("", "a:")          = "::"
  152.            andalso mkRelative("a:b::c", "a:d")   = "::b::c"
  153.            andalso mkRelative("a:b", "c:d")      = ":::a:b"
  154.            andalso mkRelative("c:a:b", "c:d")    = "::a:b"
  155.            andalso mkRelative("c:d:a:b", "c:d")  = ":a:b"
  156.            andalso mkRelative("c:d:a:b:", "c:d") = ":a:b:"
  157.            andalso mkRelative("c:d:a:b:", "c:d:")= ":a:b:"
  158.            andalso mkRelative("a:b:", "a:b:")    = ":"
  159.            andalso mkRelative("a:b:", "a:b:c:")  = "::"
  160.            andalso mkRelative("a:b:", "a:b:c:d:")= ":::"
  161.            andalso mkRelative("a:b:", "a:b")     = ":"
  162.            andalso mkRelative("a:b:", "a:b:c")   = "::"
  163.            andalso mkRelative("a:b:", "a:b:c:d") = ":::"
  164.            andalso mkRelative("a:b", "a:b:")     = ":"
  165.            andalso mkRelative("a:b", "a:b:c:")   = "::"
  166.            andalso mkRelative("a:b", "a:b:c:d:") = ":::"
  167.            andalso mkRelative("a:b", "a:b")      = ":"
  168.            andalso mkRelative("a:b", "a:b:c")    = "::"
  169.            andalso mkRelative("a:b", "a:b:c:d")  = ":::"
  170.            );
  171. val test8b = (mkRelative("a:", ":c:d") seq "WRONG")
  172.               handle Path => "OK" | _ => "WRONG";
  173. val test8c = (mkRelative(":a", ":c:d") seq "WRONG")
  174.               handle Path => "OK" | _ => "WRONG";
  175.  
  176.  
  177. val test9a = let
  178.     fun chkCanon (a, b) =
  179.           (mkCanonical a = b) 
  180.           andalso (mkCanonical b = b)
  181.           andalso (isCanonical b)
  182.     in
  183.       check'(fn _ => 
  184.            chkCanon("", "")
  185.            andalso chkCanon(":", ":")
  186.            andalso chkCanon("::", "::")
  187.            andalso chkCanon(":::", ":::")
  188.            andalso chkCanon("b", ":b")
  189.            andalso chkCanon("a:b", "a:b")
  190.            andalso chkCanon(":a:b", ":a:b")
  191.            andalso chkCanon("a:b:", "a:b:")
  192.            andalso chkCanon("a:b::", "a:")
  193.            andalso chkCanon(":a:::b", "::b")
  194.            andalso chkCanon(":a::", ":")
  195.            andalso chkCanon("a::", "")
  196.            andalso chkCanon("a:", "a:")
  197.            andalso chkCanon(":a::b:", ":b:")
  198.            andalso chkCanon("x:::a:b", "a:b")
  199.            andalso chkCanon("x::", "")
  200.        (*  andalso chkCanon("a::b", "b")            Mac problem    *)
  201.            andalso chkCanon("a::b:", "b:")
  202.            )
  203.     end;
  204.  
  205. val test9b = check'(fn _ => 
  206.                   mkCanonical "" = ""
  207.                   andalso mkCanonical "a::b" = "b"  (* see above *)
  208.                   andalso mkCanonical "b" = ":b"    (* see above *)
  209.                   andalso mkCanonical ":" = ":"
  210.                   andalso mkCanonical "::" = "::"
  211.                   andalso mkCanonical ":::" = ":::"
  212.                   andalso mkCanonical "a" = ":a"
  213.                   andalso mkCanonical "a:" = "a:"
  214.                   andalso mkCanonical ":a" = ":a"
  215.                   andalso mkCanonical ":a:" = ":a:"
  216.                   andalso mkCanonical "a::b" = "b"
  217.                   andalso mkCanonical ":a::b" = ":b"
  218.                   andalso mkCanonical ":a::" = ":"
  219.                   andalso mkCanonical ":a::b::c" = ":c"
  220.                   andalso mkCanonical "a::b::c:" = "c:"
  221.                   andalso mkCanonical "a::b::c" = "c"
  222.                   andalso mkCanonical "a:b:c:::d" = "a:d"
  223.                   andalso mkCanonical ":a:b:c:::d" = ":a:d"
  224.                   andalso mkCanonical "a:b:c::::d" = "d"
  225.                   andalso mkCanonical ":a:b:c::::d" = ":d"
  226.                   andalso mkCanonical ":a:b:c:::::d" = "::d"
  227.                   andalso mkCanonical "a:b:c:::d:" = "a:d:"
  228.                   andalso mkCanonical ":a:b:c:::d:" = ":a:d:"
  229.                   andalso mkCanonical "a:b:c::::d:" = "d:"
  230.                   andalso mkCanonical ":a:b:c::::d:" = ":d:"
  231.                   andalso mkCanonical ":a:b:c:::::d:" = "::d:"
  232.                   );
  233.  
  234. val test10a = 
  235.     check'(fn _ => 
  236.            isCanonical ":"
  237.            andalso isCanonical "::"
  238.            andalso isCanonical ""
  239.            andalso isCanonical ":a"
  240.            andalso isCanonical ":a:b"
  241.            andalso isCanonical ":a:b:");
  242.  
  243.                 
  244. val test10b = 
  245.     check'(fn _ => 
  246.            not (isCanonical ":x::"
  247.                 orelse isCanonical "x::"
  248.                 orelse isCanonical "a::"
  249.                 orelse isCanonical ":a::b"
  250.                 orelse isCanonical ":a::"
  251.                 orelse isCanonical ":a:::"));
  252.  
  253. val test10c = check'(fn _ => isCanonical "b"); (* Mac beppoe *)
  254.  
  255. val test11a = 
  256.     check'(fn _ => 
  257.            splitDirFile "" = {dir = "", file = ""}
  258.            andalso splitDirFile "." = {dir = ":", file = "."}
  259.            andalso splitDirFile ".." = {dir = ":", file = ".."}
  260.            andalso splitDirFile "b" = {dir = ":", file = "b"}
  261.            andalso splitDirFile "b:" = {dir = "b:", file = ""}
  262.            andalso splitDirFile "a:b" = {dir = "a:", file = "b"}
  263.            andalso splitDirFile ":a" = {dir = ":", file = "a"}
  264.            andalso splitDirFile ":a:b" = {dir = ":a:", file = "b"}
  265.            andalso splitDirFile ":c:a:b" = {dir = ":c:a:", file = "b"}
  266.            andalso splitDirFile ":c:a:b:" = {dir = ":c:a:b:", file = ""}
  267.            andalso splitDirFile ":c:a:b.foo.bar" = {dir = ":c:a:", file="b.foo.bar"}
  268.            andalso splitDirFile ":c:a:b.foo" = {dir = ":c:a:", file = "b.foo"});
  269.  
  270. (*    
  271. val test11b = (splitDirFile "" seq "WRONG") 
  272.               handle Path => "OK" | _ => "WRONG";
  273. *)
  274. val test11b = (splitDirFile "" seq splitDirFile ":" seq "DIFFERENT");
  275.  
  276. val test12 = 
  277.     check'(fn _ => 
  278.            "" = joinDirFile {dir = "", file = ""}
  279.            andalso "b" = joinDirFile {dir = "", file = "b"}
  280.            andalso ":" = joinDirFile {dir = ":", file = ""}
  281.            andalso ":b" = joinDirFile {dir = ":", file = "b"}
  282.            andalso "a:b" = joinDirFile {dir = "a:", file = "b"}
  283.            andalso ":a:b" = joinDirFile {dir = ":a", file = "b"}
  284.            andalso ":c:a:b" = joinDirFile {dir = ":c:a", file = "b"}
  285.            andalso ":c:a:b:" = joinDirFile {dir = ":c:a:b", file = ""}
  286.            andalso ":c:a:b.foo.bar" = joinDirFile {dir = ":c:a", file="b.foo.bar"}
  287.            andalso ":c:a:b.foo" = joinDirFile {dir = ":c:a", file = "b.foo"});
  288.  
  289. val test13 = 
  290.     check'(fn _ => 
  291.            dir "b" = ":"
  292.            andalso dir "a:" = "a:"
  293.            andalso dir "a:b" = "a:"
  294.            andalso dir ":" = ":"
  295.            andalso dir ":b" = ":"
  296.            andalso dir ":a:b" = ":a:"
  297.            andalso dir ":c:a:b" = ":c:a:"
  298.            andalso dir ":c:a:b:" = ":c:a:b:"
  299.            andalso dir ":c:a:b.foo.bar" = ":c:a:"
  300.            andalso dir ":c:a:b.foo" = ":c:a:");
  301.  
  302. val test14 = 
  303.     check'(fn _ => 
  304.            file "b" = "b"
  305.            andalso file "a:b" = "b"
  306.            andalso file ":" = ""
  307.            andalso file ":b" = "b"
  308.            andalso file ":a:b" = "b"
  309.            andalso file ":c:a:b" = "b"
  310.            andalso file ":c:a:b:" = ""
  311.            andalso file ":c:a:b.foo.bar" = "b.foo.bar"
  312.            andalso file ":c:a:b.foo" = "b.foo");
  313.  
  314. val test15 = 
  315.     check'(fn _ => 
  316.            splitBaseExt "" = {base = "", ext = NONE}
  317.            andalso splitBaseExt ".login" = {base = ".login", ext = NONE}
  318.            andalso splitBaseExt ":.login" = {base = ":.login", ext = NONE}
  319.            andalso splitBaseExt "a" = {base = "a", ext = NONE}
  320.            andalso splitBaseExt "a." = {base = "a.", ext = NONE}
  321.            andalso splitBaseExt "a.b" = {base = ":a", ext = SOME "b"} (* weird *)
  322.            andalso splitBaseExt "a.b.c" = {base = ":a.b", ext = SOME "c"} (* weird *)
  323.            andalso splitBaseExt ":a.b" = {base = ":a", ext = SOME "b"}
  324.            andalso splitBaseExt ":c:a.b" = {base = ":c:a", ext = SOME "b"}
  325.            andalso splitBaseExt ":c:a:b:.d" = {base = ":c:a:b:.d", ext = NONE}
  326.            andalso splitBaseExt ":c.a:b.d" = {base = ":c.a:b", ext = SOME "d"}
  327.            andalso splitBaseExt ":c.a:bd" = {base = ":c.a:bd", ext = NONE}
  328.            andalso splitBaseExt ":c:a:b.foo.bar" = {base=":c:a:b.foo",ext=SOME "bar"}
  329.            andalso splitBaseExt ":c:a:b.foo" = {base = ":c:a:b", ext = SOME "foo"});
  330.  
  331. val test16 = 
  332.     check'(fn _ => 
  333.            "" = joinBaseExt {base = "", ext = NONE}
  334.            andalso ".login" = joinBaseExt {base = ".login", ext = NONE}
  335.            andalso "a" = joinBaseExt {base = "a", ext = NONE}
  336.            andalso "a." = joinBaseExt {base = "a", ext = SOME ""}
  337.            andalso "a.b" = joinBaseExt {base = "a", ext = SOME "b"}
  338.            andalso "a.b.c" = joinBaseExt {base = "a.b", ext = SOME "c"}
  339.            andalso "a.b.c.d" = joinBaseExt {base = "a.b", ext = SOME "c.d"}
  340.            andalso ":a.b" = joinBaseExt {base = ":a", ext = SOME "b"}
  341.            andalso ":c:a.b" = joinBaseExt {base = ":c:a", ext = SOME "b"}
  342.            andalso ":c:a:b:.d" = joinBaseExt {base = ":c:a:b:", ext = SOME "d"}
  343.            andalso ":c:a:b.foo.bar" = joinBaseExt {base=":c:a:b",ext=SOME "foo.bar"}
  344.            andalso ":c:a:b.foo" = joinBaseExt {base = ":c:a:b", ext = SOME "foo"});
  345.  
  346. val test17 = 
  347.     check'(fn _ => 
  348.            ext "" = NONE
  349.            andalso ext ".login" = NONE
  350.            andalso ext ":.login" = NONE
  351.            andalso ext "a" = NONE
  352.            andalso ext "a." = NONE
  353.            andalso ext "a.b" = SOME "b"
  354.            andalso ext "a.b.c" = SOME "c"
  355.            andalso ext "a.b.c.d" = SOME "d"
  356.            andalso ext ":a.b" = SOME "b"
  357.            andalso ext ":c:a.b" = SOME "b"
  358.            andalso ext ":c:a:b:.d" = NONE
  359.            andalso ext ":c.a:b.d" = SOME "d"
  360.            andalso ext ":c.a:bd" = NONE
  361.            andalso ext ":c:a:b.foo.bar" = SOME "bar"
  362.            andalso ext ":c:a:b.foo" = SOME "foo");
  363.  
  364. val test18 = 
  365.     check'(fn _ => 
  366.            base "" = ""
  367.            andalso base ".d" = ".d"
  368.            andalso base ".login" = ".login"
  369.            andalso base ":.login" = ":.login"
  370.            andalso base "a" = "a"
  371.            andalso base "a." = "a."
  372.            andalso base "a.b" = ":a"             (* weird *)
  373.            andalso base "a.b.c" = ":a.b"         (* weird *)
  374.            andalso base "a.b.c.d" = ":a.b.c"     (* weird *)
  375.            andalso base "x:a.b" = "x:a"
  376.            andalso base "x:c:a.b" = "x:c:a"
  377.            andalso base "x:c:a:b:.d" = "x:c:a:b:.d"
  378.            andalso base ":a.b" = ":a"
  379.            andalso base ":c:a.b" = ":c:a"
  380.            andalso base ":c:a:b:.d" = ":c:a:b:.d"
  381.            andalso base ":c.a:b.d" = ":c.a:b"
  382.            andalso base ":c.a:bd" = ":c.a:bd"
  383.            andalso base ":c:a:b.foo.bar" = ":c:a:b.foo"
  384.            andalso base ":c:a:b.foo" = ":c:a:b");
  385.  
  386. val test19 = 
  387.     check'(fn () => validVolume{isAbs=false, vol=""}
  388.            andalso validVolume{isAbs=true, vol=""}
  389.            andalso not (validVolume{isAbs=true, vol=":"}
  390.                         orelse validVolume{isAbs=false, vol=":"} 
  391.                         orelse validVolume{isAbs=true, vol="C:"}
  392.                         orelse validVolume{isAbs=false, vol="C:"}
  393.                         orelse validVolume{isAbs=true, vol=" "}
  394.                         orelse validVolume{isAbs=false, vol=" "})); 
  395. end
  396.