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

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


Author: lgiessmann
Date: Wed Dec 15 04:51:01 2010
New Revision: 363

Log:
TM-SPARQL: added some unit-tests for the processing of brackets in FILTER-statements => fixed a bug when a function is behind a supported operator without white space

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 04:51:01 2010
@@ -20,6 +20,10 @@
   "Contains all supported operators, note some unary operators
    are handled as functions, e.g. + and -")
 
+(defparameter *supported-brackets*
+  (list "(" ")")
+  "Contains all supported brackets in a list of strings.")
+
 
 (defun make-sparql-parser-condition(rest-of-query entire-query expected)
   "Creates a spqrql-parser-error object."
@@ -137,13 +141,16 @@
 		      'SPARQL-PARSER-ERROR
 		      :message (format nil "Invalid filter: \"~a\"~%"
 				       query-string)))
-	      (when fragment-before-idx
-		(let ((inner-value
-		       (subseq string-before fragment-before-idx)))
-		  (if (and (> (length inner-value) 1)
-			   (string-starts-with inner-value "("))
-		      (subseq inner-value 1)
-		      inner-value))))))
+	      (if fragment-before-idx
+		  (subseq string-before fragment-before-idx)
+		  nil))))
+    (when fragment-before
+      (mapcan #'(lambda(operator)
+		  (when (and (string-starts-with fragment-before operator)
+			     (> (length fragment-before) (length operator)))
+		    (setf fragment-before
+			  (string-after fragment-before operator))))
+	      (append *supported-operators* *supported-brackets*)))
     (if fragment-before
 	(progn
 	  (when (or (string-starts-with fragment-before "?")
@@ -160,7 +167,7 @@
 	     (make-condition
 	      'SPARQL-PARSER-ERROR
 	      :message
-	      (format nil "Invalid character: ~a, expected characters: ~a"
+	      (format nil "Invalid character: \"~a\", expected characters: ~a"
 		      fragment-before (append *supported-functions* delimiters)))))
 	  (if (find fragment-before *supported-functions* :test #'string=)
 	      nil

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 04:51:01 2010
@@ -1050,7 +1050,11 @@
 	 (str-3
 	  "DATATYPE(?var3) || +?var1 = -?var2
            ?var1 ?var2 ?var3}")
-	 (result-3 (tm-sparql::set-boundings dummy-object str-3)))
+	 (result-3 (tm-sparql::set-boundings dummy-object str-3))
+	 (str-4 "DATATYPE(?var3) ||isLITERAL(+?var1 = -?var2)}")
+	 (result-4 (tm-sparql::set-boundings dummy-object str-4))
+	 (str-5 "DATATYPE(?var3) ||(isLITERAL  (+?var1 = -?var2))}")
+	 (result-5 (tm-sparql::set-boundings dummy-object str-5)))
     (is-true result-1)
     (is-true result-2)
     (is (string= (getf result-1 :filter-string)
@@ -1061,8 +1065,13 @@
     (is (string= (getf result-2 :next-query) "}"))
     (is (string= (getf result-3 :filter-string)
 		 "DATATYPE(?var3) || +?var1 = -?var2"))
-    (is (string= (getf result-3 :next-query) (subseq str-3 34)))))
-
+    (is (string= (getf result-3 :next-query) (subseq str-3 34)))
+    (is (string= (getf result-4 :filter-string)
+		 "DATATYPE(?var3) ||isLITERAL(+?var1 = -?var2)"))
+    (is (string= (getf result-4 :next-query) "}"))
+    (is (string= (getf result-5 :filter-string)
+		 "DATATYPE(?var3) ||(progn isLITERAL  (+?var1 = -?var2))"))
+    (is (string= (getf result-5 :next-query) "}"))))
 
 (defun run-sparql-tests ()
   (it.bese.fiveam:run! 'sparql-test:sparql-tests))




More information about the Isidorus-cvs mailing list