Skip to content

Commit

Permalink
Adds aget special form, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arohner committed Feb 19, 2010
1 parent 0009641 commit 70648a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/com/reasonr/scriptjure.clj
Expand Up @@ -66,7 +66,7 @@
(defmethod emit :default [expr]
(str expr))

(def special-forms (set ['var '. 'if 'funcall 'fn 'set! 'return 'delete 'new 'do]))
(def special-forms (set ['var '. 'if 'funcall 'fn 'set! 'return 'delete 'new 'do 'aget]))

(def infix-operators (set ['+ '- '/ '* '% '== '=== '< '> '<= '>= '!= '<< '>> '<<< '>>> '!== '& '^ '| '&& '||]))

Expand Down Expand Up @@ -118,6 +118,9 @@
(defmethod emit-special 'new [type [new class & args]]
(str "new " (emit class) (comma-list (map emit args))))

(defmethod emit-special 'aget [type [aget var idx]]
(str (emit var) "[" (emit idx) "]"))

(defn emit-do [exprs]
(str/join "" (map (comp statement emit) exprs)))

Expand Down
5 changes: 4 additions & 1 deletion test/test_scriptjure.clj
@@ -1,4 +1,4 @@
(ns scriptjure
(ns test-scriptjure
(:use clojure.test)
(:use com.reasonr.scriptjure)
(:require [clojure.contrib.str-utils2 :as str]))
Expand Down Expand Up @@ -53,6 +53,9 @@
(deftest test-array
(is (= (js [1 "2" :foo]) "[1, \"2\", foo]")))

(deftest test-aget
(is (= (js (aget foo 2)) "foo[2]")))

(deftest test-map
(is (= (strip-whitespace (js {:packages ["columnchart"]})) "{packages: [\"columnchart\"]}")))

Expand Down

0 comments on commit 70648a4

Please sign in to comment.