Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pixie/stdlib.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -2004,13 +2004,13 @@ For more information, see http://clojure.org/special_forms#binding-forms"}
(when (empty? s)
(throw
[:pixie.stdlib/OutOfRangeException
"Index out of Range"]))
"Index out of range"]))
(if (and (pos? n) s)
(recur (next s) (dec n))
(if (zero? n)
(first s)
(throw [:pixie.stdlib/OutOfRangeException
"Index out of Range"])))))
"Index out of range"])))))
(extend -nth-not-found ISeq (fn [s n not-found]
(if (and (pos? n) s)
(recur (next s) (dec n) not-found)
Expand Down Expand Up @@ -2042,7 +2042,7 @@ For more information, see http://clojure.org/special_forms#binding-forms"}
(-nth [self idx]
(if (and (>= idx 0) (< idx n))
x
(throw [:pixie.stdlib/OutOfRangeException "Index out of Range"])))
(throw [:pixie.stdlib/OutOfRangeException "Index out of range"])))
(-nth-not-found [self idx not-found]
(if (and (>= idx 0) (< idx n))
x
Expand Down Expand Up @@ -2093,12 +2093,12 @@ For more information, see http://clojure.org/special_forms#binding-forms"}
IIndexed
(-nth [self idx]
(when (or (= start stop 0) (neg? idx))
(throw [:pixie.stdlib/OutOfRangeException "Index out of Range"]))
(throw [:pixie.stdlib/OutOfRangeException "Index out of range"]))
(let [cmp (if (< start stop) < >)
val (+ start (* idx step))]
(if (cmp val stop)
val
(throw [:pixie.stdlib/OutOfRangeException "Index out of Range"]))))
(throw [:pixie.stdlib/OutOfRangeException "Index out of range"]))))
(-nth-not-found [self idx not-found]
(let [cmp (if (< start stop) < >)
val (+ start (* idx step))]
Expand Down
4 changes: 2 additions & 2 deletions pixie/test.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@
exn#))
([klass body]
`(let [exn# (assert-throws? ~body)]
(assert (= (type exn#) ~klass)
(assert (= (ex-data exn#) ~klass)
(str "Expected " (pr-str (quote ~body))
" to throw exception of class " (pr-str ~klass)
" but got " (pr-str (type exn#))))
" but got " (pr-str (ex-data exn#))))
exn#))
([klass msg body]
`(let [exn# (assert-throws? ~klass ~body)]
Expand Down
5 changes: 3 additions & 2 deletions pixie/vm/array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pixie.vm.rt as rt
import pixie.vm.object as object
from pixie.vm.object import affirm
from pixie.vm.object import affirm, runtime_error
from pixie.vm.code import extend, as_var
from pixie.vm.numbers import Integer
from pixie.vm.primitives import nil
Expand Down Expand Up @@ -48,7 +48,8 @@ def _nth(self, idx):
if ival < len(self.list()):
return self.list()[ival]
else:
affirm(False, u"Index out of Range")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")

@extend(proto._nth_not_found, Array)
def _nth_not_found(self, idx, not_found):
Expand Down
2 changes: 1 addition & 1 deletion pixie/vm/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def invoke(self, args):
runtime_error(u"Invalid number of arguments " + unicode(str(len(args)))
+ u" for function '" + unicode(str(self._name)) + u"'. Expected "
+ unicode(str(self.get_arity())),
u":pixie.stdlib/InvalidArityException")
u"pixie.stdlib/InvalidArityException")

def invoke_with(self, args, this_fn):
try:
Expand Down
18 changes: 11 additions & 7 deletions pixie/vm/persistent_vector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
py_object = object
import pixie.vm.object as object
from pixie.vm.object import affirm
from pixie.vm.object import affirm, runtime_error
from pixie.vm.primitives import nil, true, false
from pixie.vm.numbers import Integer
import pixie.vm.stdlib as proto
Expand Down Expand Up @@ -56,15 +56,17 @@ def array_for(self, i):
assert isinstance(node, Node)
return node._array

affirm(False, u"Index out of Range")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")

def nth(self, i, not_found=None):
if 0 <= i < self._cnt:
node = self.array_for(r_uint(i))
return node[i & 0x01f]

if not_found is None:
affirm(False, u"Index out of Range")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")
else:
return not_found

Expand Down Expand Up @@ -176,8 +178,8 @@ def assoc_at(self, idx, val):
if idx == self._cnt:
return self.conj(val)
else:
object.runtime_error(u"index out of range",
u"pixie.stdlib/OutOfRangeException")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")


def do_assoc(lvl, node, idx, val):
Expand Down Expand Up @@ -319,7 +321,8 @@ def array_for(self, i):
level -= 5
return node._array

affirm(False, u"Index out of Range")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")

def editable_array_for(self, i):
if i >= 0 and i < self._cnt:
Expand All @@ -333,7 +336,8 @@ def editable_array_for(self, i):
level -= 5
return node._array

affirm(False, u"Index out of bounds")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")

def nth(self, i, not_found=nil):
self.ensure_editable()
Expand Down
5 changes: 3 additions & 2 deletions pixie/vm/string.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pixie.vm.rt as rt
from pixie.vm.object import Object, Type, affirm
from pixie.vm.object import Object, Type, affirm, runtime_error
from pixie.vm.code import extend, as_var, wrap_fn
from pixie.vm.primitives import nil, true, false
from pixie.vm.numbers import Integer, _add
Expand Down Expand Up @@ -52,7 +52,8 @@ def _nth(self, idx):
i = idx.int_val()
if 0 <= i < len(self._str):
return Character(ord(self._str[i]))
affirm(False, u"Index out of Range")
runtime_error(u"Index out of range",
u"pixie.stdlib/OutOfRangeException")

@extend(proto._nth_not_found, String)
def _nth_not_found(self, idx, not_found):
Expand Down
16 changes: 8 additions & 8 deletions tests/pixie/tests/test-arrays.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(t/deftest test-alength
(let [a (make-array 10)]
(t/assert= (alength a) 10)
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(alength []))))

(t/deftest test-aget-and-aset
Expand All @@ -25,10 +25,10 @@
(dotimes [i 10]
(t/assert= (aget a i) i))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(aget a 1.0))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(aset a 1.0 :foo))))

(t/deftest test-aconcat
Expand All @@ -44,10 +44,10 @@
(dotimes [i 20]
(t/assert= (aget a3 i) i)))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(t/aconcat a1 []))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(t/aconcat a1 '()))))

(t/deftest test-aslice
Expand All @@ -62,13 +62,13 @@
(foreach [i (range 0 3)]
(t/assert= (aget a2 i) (+ i 7))))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(aslice [1 2 3 4] 0 2))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(aslice '() 0 2))

(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
(aslice a 1.0 2))))


Expand Down
26 changes: 13 additions & 13 deletions tests/pixie/tests/test-fns.pxi
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
(ns pixie.test.test-fns
(require pixie.test :as t))

(def arity-exception :pixie.stdlib/InvalidArityException)

(t/deftest test-fn-literals
(t/assert= (#(+ 3 4)) 7)
(t/assert= (#(+ 3 %) 4) 7)
Expand All @@ -23,38 +25,36 @@
arity-1-or-3 (fn arity-1-or-3 ([a]) ([a b c]))
arity-0-or-1-or-3-or-more
(fn arity-0-or-1-or-3-or-more ([]) ([a]) ([a b c & more]))]
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Invalid number of arguments 1 for function 'arity-0'. Expected 0"
(arity-0 :foo))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Invalid number of arguments 2 for function 'arity-0'. Expected 0"
(arity-0 :foo :bar))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Invalid number of arguments 0 for function 'arity-1'. Expected 1"
(arity-1))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Invalid number of arguments 2 for function 'arity-1'. Expected 1"
(arity-1 :foo :bar))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Invalid number of arguments 0 for function 'arity-2'. Expected 2"
(arity-2))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Invalid number of arguments 1 for function 'arity-2'. Expected 2"
(arity-2 :foo))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Wrong number of arguments 2 for function 'arity-0-or-1'. Expected 0 or 1"
(arity-0-or-1 :foo :bar))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Wrong number of arguments 3 for function 'arity-0-or-1'. Expected 0 or 1"
(arity-0-or-1 :foo :bar :baz))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Wrong number of arguments 2 for function 'arity-1-or-3'. Expected 1 or 3"
(arity-1-or-3 :foo :bar))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Wrong number of arguments 0 for function 'arity-1-or-3'. Expected 1 or 3"
(arity-1-or-3))
(t/assert-throws? RuntimeException
(t/assert-throws? arity-exception
"Wrong number of arguments 2 for function 'arity-0-or-1-or-3-or-more'. Expected 0, 1 or 3+"
(arity-0-or-1-or-3-or-more :foo :bar))))

(t/deftest test-code-arities)
30 changes: 15 additions & 15 deletions tests/pixie/tests/test-ith.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
(t/assert= (ith nil -1) nil))

(t/deftest test-ith-empty-always-oob
(t/assert= "Index out of Range" (try (ith [] 0) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith [] 1) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith [] -1) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith '() 0) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith '() 1) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith '() -1) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith (range 0 0) 0) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith (range 0 0) 1) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith (range 0 0) -1) (catch e (ex-msg e)))))
(t/assert= "Index out of range" (try (ith [] 0) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith [] 1) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith [] -1) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith '() 0) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith '() 1) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith '() -1) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith (range 0 0) 0) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith (range 0 0) 1) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith (range 0 0) -1) (catch e (ex-msg e)))))

(t/deftest test-ith-out-of-bounds
(let [v [1 2 3 4 5]
l '(1 2 3 4 5)
r (range 1 6)]
(t/assert= "Index out of Range" (try (ith v 5) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith l 5) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith r 5) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith v -6) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith l -6) (catch e (ex-msg e))))
(t/assert= "Index out of Range" (try (ith r -6) (catch e (ex-msg e))))))
(t/assert= "Index out of range" (try (ith v 5) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith l 5) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith r 5) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith v -6) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith l -6) (catch e (ex-msg e))))
(t/assert= "Index out of range" (try (ith r -6) (catch e (ex-msg e))))))

(t/deftest test-ith-doseq
(let [v [1 2 3 4 5]
Expand Down
20 changes: 10 additions & 10 deletions tests/pixie/tests/test-readeval.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,42 @@
(t/assert= (read-string "(foo (bar (baz)))") '(foo (bar (baz)))))

(t/deftest test-list-unclosed-list-fail
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched list open '('"
(read-string "("))
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched list open '('"
(read-string "((foo bar)")))

(t/deftest test-vector-unclosed-list-fail
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched vector open '['"
(read-string "["))
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched vector open '['"
(read-string "[[foo bar]")))

(t/deftest test-map-unclosed-list-fail
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched map open '{'"
(read-string "{"))
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched map open '{'"
(read-string "{foo {a b}")))

(t/deftest test-set-unclosed-list-fail
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched set open '#{'"
(read-string "#{"))
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched set open '#{'"
(read-string "#{foo #{a}")))

(t/deftest test-string-unclosed-fail
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched string quote '\"'"
(read-string "\""))
(t/assert-throws? RuntimeException
(t/assert-throws? :pixie.stdlib/AssertionException
"Unmatched string quote '\"'"
(read-string "\"foo")))

Expand Down
Loading