Mercurial > lasercutter
view src/clojure/test_clojure/ns_libs.clj @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
line wrap: on
line source
1 ; Copyright (c) Rich Hickey. All rights reserved.2 ; The use and distribution terms for this software are covered by the3 ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)4 ; which can be found in the file epl-v10.html at the root of this distribution.5 ; By using this software in any fashion, you are agreeing to be bound by6 ; the terms of this license.7 ; You must not remove this notice, or any other, from this software.9 ; Authors: Frantisek Sodomka, Stuart Halloway11 (ns clojure.test-clojure.ns-libs12 (:use clojure.test))14 ; http://clojure.org/namespaces16 ; in-ns ns create-ns17 ; alias import intern refer18 ; all-ns find-ns19 ; ns-name ns-aliases ns-imports ns-interns ns-map ns-publics ns-refers20 ; resolve ns-resolve namespace21 ; ns-unalias ns-unmap remove-ns24 ; http://clojure.org/libs26 ; require use27 ; loaded-libs29 (deftest test-require30 (is (thrown? Exception (require :foo)))31 (is (thrown? Exception (require))))33 (deftest test-use34 (is (thrown? Exception (use :foo)))35 (is (thrown? Exception (use))))37 (deftest reimporting-deftypes38 (let [inst1 (binding [*ns* *ns*]39 (eval '(do (ns exporter)40 (defrecord ReimportMe [a])41 (ns importer)42 (import exporter.ReimportMe)43 (ReimportMe. 1))))44 inst2 (binding [*ns* *ns*]45 (eval '(do (ns exporter)46 (defrecord ReimportMe [a b])47 (ns importer)48 (import exporter.ReimportMe)49 (ReimportMe. 1 2))))]50 (testing "you can reimport a changed class and see the changes"51 (is (= [:a] (keys inst1)))52 (is (= [:a :b] (keys inst2))))53 (testing "you cannot import same local name from a different namespace"54 (is (thrown? clojure.lang.Compiler$CompilerException55 #"ReimportMe already refers to: class exporter.ReimportMe in namespace: importer"56 (binding [*ns* *ns*]57 (eval '(do (ns exporter-2)58 (defrecord ReimportMe [a b])59 (ns importer)60 (import exporter-2.ReimportMe)61 (ReimportMe. 1 2)))))))))63 (deftest naming-types64 (testing "you cannot use a name already referred from another namespace"65 (is (thrown? IllegalStateException66 #"String already refers to: class java.lang.String"67 (definterface String)))68 (is (thrown? IllegalStateException69 #"StringBuffer already refers to: class java.lang.StringBuffer"70 (deftype StringBuffer [])))71 (is (thrown? IllegalStateException72 #"Integer already refers to: class java.lang.Integer"73 (defrecord Integer [])))))75 (deftest refer-error-messages76 (let [temp-ns (gensym)]77 (binding [*ns* *ns*]78 (in-ns temp-ns)79 (eval '(def ^{:private true} hidden-var)))80 (testing "referring to something that does not exist"81 (is (thrown-with-msg? IllegalAccessError #"nonexistent-var does not exist"82 (refer temp-ns :only '(nonexistent-var)))))83 (testing "referring to something non-public"84 (is (thrown-with-msg? IllegalAccessError #"hidden-var is not public"85 (refer temp-ns :only '(hidden-var)))))))