source: tags/1.5.0/contrib/jss/t/jss-tests.lisp

Last change on this file was 15066, checked in by Mark Evenson, 7 years ago

Further fixes for JSS

JAVAPARSER now "stacks" its macro definition on the existing one it
inherits from JSS.

Refactor all tests to just pollute CL-USER where necessary (strictly
speaking it shouldn't be necessary as all PROVE tests should be able
to use lexical bindings.

Document existence of Java field access via SHARPSIGN-QUOTATION_MARK,
e.g.

(#"{java.lang.System}.{fileSeparator}")

and the new Java DSL

(asdf:make :javaparser)
(#"'#1"new ByteBuddy?()

.subclass(Object.class,t)
.method(ElementMatchers?.named("toString"))
.intercept(FixedValue?.value("Hello World!"))
.make()
.load(getClass().getClassLoader())
.getLoaded()"

File size: 2.3 KB
Line 
1(in-package :cl-user)
2
3(prove:plan 6)
4
5(prove:is
6 (read-from-string "#\"{bar}.{foo}\"")
7 '(get-java-field bar foo t))
8(prove:is
9 (read-from-string "#\"q.bar.{foo}\"")
10 '(get-java-field (load-time-value (find-java-class "q.bar")) foo t))
11(prove:is
12 (read-from-string "#\"{bar}.foo\"")
13 '(get-java-field bar "foo" t))
14(prove:is-error
15 (read-from-string "#\".bar.foo\"")
16 'simple-error)
17;;; http://abcl.org/trac/ticket/205
18(prove:is
19 (with-constant-signature ((substring "substring"))
20   (substring "01234" 2)) "234")
21;;; http://abcl.org/trac/ticket/229 - note: version of test for this ticket was broken in tests.lisp
22(prove:is (#"toString"
23           (find "size" (#"getMethods" (find-java-class "java.util.Collections$UnmodifiableMap"))
24                 :test 'string-equal :key #"getName"))
25    (#"toString" (java::jmethod "java.util.Collections$UnmodifiableMap" "size" )))
26
27;; test that optimized jss is much faster than unoptimized
28(let ()
29  (defun optimized-jss (count)
30    (loop repeat count do (#"compile" 'regex.Pattern ".*")))
31  (let ((jss::*inhibit-jss-optimization* t))
32    (defun unoptimized-jss (count)
33      (loop repeat count do (#"compile" 'regex.Pattern ".*"))))
34  (defun just-loop (count)
35    (loop repeat count))
36  (let ((jss::*inhibit-jss-optimization* nil))
37    (compile 'just-loop)
38    (compile 'optimized-jss))
39  (let ((jss::*inhibit-jss-optimization* t))
40    (compile 'unoptimized-jss))
41
42  (defmacro timeit (&body body)
43    `(let ((start (#"currentTimeMillis" 'system)))
44       ,@body
45       (- (#"currentTimeMillis" 'system) start)))
46
47  (prove:plan 1)
48  (prove:is-type (let ((just-loop (timeit (just-loop 10000))))
49     (+ 0.0 
50        (/ (-  (timeit (optimized-jss 10000)) just-loop)
51      (-  (timeit (unoptimized-jss 10000)) just-loop))))
52                 '(float 0 0.1)
53                 "Testing JSS compiler optimization
"))
54
55(prove:plan 2)
56(let* ((jss::*inhibit-jss-optimization* nil)
57       (optimized-jss
58        (macroexpand (precompiler::precompile-form
59                                    '(#"compile" 'regex.Pattern ".*") t))))
60  (let* ((jss::*inhibit-jss-optimization* t)
61         (unoptimized-jss
62          (macroexpand (precompiler::precompile-form '(#"compile" 'regex.Pattern ".*") t))))
63    (prove:is (car optimized-jss) 'java:jstatic)
64    (prove:is (caar unoptimized-jss) 'lambda)))
65
66(prove:finalize)
67
Note: See TracBrowser for help on using the repository browser.