#lang zuo

(require "harness.zuo")

(alert "module paths")

(check (module-path? 'zuo))
(check (module-path? 'zuo/main))
(check (module-path? 'zuo/private/main))
(check (module-path? '/zuo) #f)
(check (module-path? 'zuo/) #f)
(check (module-path? 'zuo//main) #f)
(check (module-path? 'zuo?) #f)
(check (module-path? 'zuo/?/x) #f)

(check (module-path? "main.zuo"))
(check (module-path? "private/main.zuo"))
(check (module-path? "private/../main.zuo"))
(check (module-path? "./../main.zuo"))
(check (module-path? "main"))
(check (module-path? "main.rkt"))
(check (module-path? " main.zuo "))
(check (module-path? "") #f)
(check (module-path? "a\0b") #f)

(check (module-path? 1) #f)
(check (module-path? '(zuo)) #f)

(check (build-module-path 'zuo "list.zuo") 'zuo/list)
(check (build-module-path 'zuo/main "list.zuo") 'zuo/list)
(check (build-module-path 'zuo/private/main "list.zuo") 'zuo/private/list)
(check (build-module-path 'zuo "helper/list.zuo") 'zuo/helper/list)
(check (build-module-path 'zuo/main "helper/list.zuo") 'zuo/helper/list)
(check (build-module-path 'zuo/private/main "helper/list.zuo") 'zuo/private/helper/list)
(check (build-module-path 'zuo/private/main "../list.zuo") 'zuo/list)
(check (build-module-path 'zuo/private/main "./list.zuo") 'zuo/private/list)
(check (build-module-path 'zuo/private/main "./././../././list.zuo") 'zuo/list)
(check-arg-fail (build-module-path 'zuo "list") "lacks \".zuo\"")
(check-arg-fail (build-module-path 'zuo "../list.zuo") "too many up elements")
(check-arg-fail (build-module-path 'zuo "x//list.zuo") "not a relative module library path")
(check-arg-fail (build-module-path 'zuo "..//list.zuo") "not a relative module library path")
(check-arg-fail (build-module-path 'zuo "list@.zuo") "not a relative module library path")
(check-arg-fail (build-module-path 'zuo "@/list.zuo") "not a relative module library path")
(check-arg-fail (build-module-path 'zuo "list.rkt") "not a relative module library path")
(check-arg-fail (build-module-path 'zuo "x.y/list.zuo") "not a relative module library path")

(check (build-module-path "lib/zuo/main.zuo" "list.zuo") "lib/zuo/list.zuo")
(check (build-module-path "lib/zuo/main.zuo" "../list.zuo") "lib/list.zuo")
(check (build-module-path "lib.zuo" "list.zuo") "list.zuo")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "list") "lacks \".zuo\"")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "x//list.zuo") "not a relative module library path")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "..//list.zuo") "not a relative module library path")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "list@.zuo") "not a relative module library path")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "@/list.zuo") "not a relative module library path")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "list.rkt") "not a relative module library path")
(check-arg-fail (build-module-path "lib/zuo/main.zuo" "x.y/list.zuo") "not a relative module library path")

(check-arg-fail (build-module-path "" "x.zuo") "not a module path")
(check-arg-fail (build-module-path 1 "x.zuo") "not a module path")
(check-arg-fail (build-module-path "main.zuo" 1) "not a module path")
(check-arg-fail (build-module-path 'zuo 1) "not a module path")

(check (hash? (module->hash 'zuo)))
(check-arg-fail (module->hash 8) "not a module path")
