[isidorus-cvs] r365 - in trunk/src: TM-SPARQL unit_tests

Lukas Giessmann lgiessmann at common-lisp.net
Wed Dec 15 18:08:02 UTC 2010


Author: lgiessmann
Date: Wed Dec 15 13:08:01 2010
New Revision: 365

Log:
TM-SPARQL: added some unit-tests for the handling of \!, -, + as unary opertors => fixed some bugs

Modified:
   trunk/src/TM-SPARQL/sparql_filter.lisp
   trunk/src/unit_tests/sparql_test.lisp

Modified: trunk/src/TM-SPARQL/sparql_filter.lisp
==============================================================================
--- trunk/src/TM-SPARQL/sparql_filter.lisp	(original)
+++ trunk/src/TM-SPARQL/sparql_filter.lisp	Wed Dec 15 13:08:01 2010
@@ -58,6 +58,7 @@
   ;;   *=, !=, <, >, <=, >=, +, -, *, /, ||, &&
   ;; *replace function(x), function(x, y), function(x, y, z)
   ;;   by filter-function(x), (filter-function(x, y), filter-function(x, y, z)
+  ;; check if all functions that will e invoked are allowed
   ;; *create and store this filter object
 
 
@@ -115,21 +116,23 @@
 	   (let ((result (bracket-scope cleaned-str)))
 	     (list :next-query (string-after cleaned-str result)
 		   :scope result)))
-	  ((or (string-starts-with "?" cleaned-str)
-	       (string-starts-with "$" cleaned-str))
+	  ((or (string-starts-with cleaned-str "?")
+	       (string-starts-with cleaned-str "$"))
 	   (let ((result (get-filter-variable cleaned-str)))
 	     (list :next-query (string-after cleaned-str result)
 		   :scope result)))
-	  ((string-starts-with "'''" cleaned-str)
+	  ((string-starts-with cleaned-str "'''")
 	   (let ((result (get-literal cleaned-str)))
 	     (list :next-query (getf result :next-query)
 		   :scope (getf result :literal))))
 	  ((string-starts-with-digit cleaned-str)
-	   (separate-leading-digits cleaned-str))
-	  ((string-starts-with "true" cleaned-str)
+	   (let ((result (separate-leading-digits cleaned-str)))
+	     (list :next-query (string-after cleaned-str result)
+		   :scope result)))
+	  ((string-starts-with cleaned-str "true")
 	   (list :next-query (string-after cleaned-str "true")
 		 :scope "true"))
-	  ((string-starts-with "false" cleaned-str)
+	  ((string-starts-with cleaned-str "false")
 	   (list :next-query (string-after cleaned-str "false")
 		 :scope "false"))
 	  ((let ((pos (search-first *supported-functions* cleaned-str)))

Modified: trunk/src/unit_tests/sparql_test.lisp
==============================================================================
--- trunk/src/unit_tests/sparql_test.lisp	(original)
+++ trunk/src/unit_tests/sparql_test.lisp	Wed Dec 15 13:08:01 2010
@@ -30,7 +30,8 @@
 	   :test-set-result-4
 	   :test-set-result-5
 	   :test-result
-	   :test-set-boundings))
+	   :test-set-boundings
+	   :test-set-unary-operators))
 
 
 (in-package :sparql-test)
@@ -1073,5 +1074,44 @@
 		 "DATATYPE(?var3) ||(progn isLITERAL  (+?var1 = -?var2))"))
     (is (string= (getf result-5 :next-query) "}"))))
 
+
+(test test-set-unary-operators
+  "Tests various cases of the function set-unary-operators."
+  (let* ((dummy-object (make-instance 'TM-SPARQL::SPARQL-Query :query "  "))
+	 (str-1 "BOUND(?var1)||(!(+(-(?var1))))}")
+	 (str-2 "!BOUND(?var1) = false}")
+	 (str-3 "+?var1=-$var2}")
+	 (str-4 "!'abc' && (+12 = - 14)}")
+	 (result-1
+	  (getf (tm-sparql::set-boundings dummy-object str-1) :filter-string))
+	 (result-1-1 (tm-sparql::set-unary-operators dummy-object result-1))
+	 (result-2
+	  (getf (tm-sparql::set-boundings dummy-object str-2) :filter-string))
+	 (result-2-1 (tm-sparql::set-unary-operators dummy-object result-2))
+	 (result-3
+	  (getf (tm-sparql::set-boundings dummy-object str-3) :filter-string))
+	 (result-3-1
+	  (tm-sparql::set-unary-operators dummy-object result-3))
+	 (result-4
+	  (getf (tm-sparql::set-boundings dummy-object str-4) :filter-string))
+	 (result-4-1
+	  (tm-sparql::set-unary-operators dummy-object result-4)))
+    (is-true result-1)
+    (is-true result-1-1)
+    (is-true result-2)
+    (is-true result-2-1)
+    (is-true result-3)
+    (is-true result-3-1)
+    (is-true result-4)
+    (is-true result-4-1)
+    (is (string=
+	 result-1-1
+	 "BOUND(?var1)||(progn (not (progn (1+ (progn (1- (progn ?var1)))))))"))
+    (is (string= result-2-1 "(not BOUND(?var1)) = false"))
+    (is (string= result-3-1 "(1+ ?var1)=(1- $var2)"))
+    (is (string= result-4-1 "(not '''abc''') && (progn (1+ 12) = (1- 14))"))))
+	 
+
+
 (defun run-sparql-tests ()
   (it.bese.fiveam:run! 'sparql-test:sparql-tests))




More information about the Isidorus-cvs mailing list