source: trunk/abcl/contrib/jss/t/jss-tests.lisp @ 15065

Last change on this file since 15065 was 15065, checked in by Mark Evenson, 6 years ago

Refactor JAVAPARSER dependencies out of JSS

JAVAPARSER needs ABCL-ASDF to load its Maven artifact, but ABCL-ASDF
needs JSS. Therefore we refactor these dependencies into the ASDF
infrastructure rather than dealing with CL:REQUIRE, which isn't going
to work anyways unless there is another mechanism to load Maven
artifacts.

The JAVAPARSER system is not working due to dependency on the missing
symbols CL-USER::REPLACE-ALL and CL-USER::TREE-REPLACE, but that was
the case before this patch as Alan mistakenly didn't include it in his
submitted patch series.

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