From bd5d75b5f949f40a43c7670c8e867d7469cc2c1b Mon Sep 17 00:00:00 2001 From: kelvinqian00 Date: Tue, 6 Feb 2024 18:50:12 -0500 Subject: [PATCH] Special case for empty list --- src/main/com/yetanalytics/flint/format/triple.cljc | 4 +++- src/test/com/yetanalytics/flint/format/triple_test.cljc | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/com/yetanalytics/flint/format/triple.cljc b/src/main/com/yetanalytics/flint/format/triple.cljc index ea6871d..be7aa6d 100644 --- a/src/main/com/yetanalytics/flint/format/triple.cljc +++ b/src/main/com/yetanalytics/flint/format/triple.cljc @@ -8,7 +8,9 @@ path) (defmethod f/format-ast-node :triple/list [_ [_ list]] - (str "( " (cstr/join " " list) " )")) + (if (empty? list) + "()" ; Special case for empty lists + (str "( " (cstr/join " " list) " )"))) (defmethod f/format-ast-node :triple/bnodes [{:keys [pretty?]} [_ po-pairs]] (if (empty? po-pairs) diff --git a/src/test/com/yetanalytics/flint/format/triple_test.cljc b/src/test/com/yetanalytics/flint/format/triple_test.cljc index 4616622..af775c6 100644 --- a/src/test/com/yetanalytics/flint/format/triple_test.cljc +++ b/src/test/com/yetanalytics/flint/format/triple_test.cljc @@ -61,6 +61,13 @@ [:ax/literal 2] [:triple/list [[:ax/literal 3]]]]]]] {:pretty? true}))) + (is (= "\"v\" :p () ." + (f/format-ast + '[:triple.vec/spo + [[:ax/literal "v"] + [:ax/prefix-iri :p] + [:triple/list []]]] + {:pretty? true}))) (is (= "[ foaf:name ?name ;\n foaf:mbox ] :q \"w\" ." (f/format-ast '[:triple.vec/spo