changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/dat/tests.lisp

changeset 541: 10c4bb778030
parent: c0fc6b87557f
child: b57066450cfa
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 12 Jul 2024 22:33:57 -0400
permissions: -rw-r--r--
description: bit of parquet refactoring, properly generate slot types
1 (defpackage :dat/tests
2  (:use :cl :std :rt :dat))
3 
4 (in-package :dat/tests)
5 
6 (defsuite :dat)
7 (in-suite :dat)
8 (in-readtable :std)
9 
10 (deftest bytes ())
11 
12 (deftest dot ()
13  "Test Graphviz DOT functionality."
14  (let ((g1 (make-instance 'graph:graph)))
15  (graph:add-node g1 "foo")
16  (graph:add-node g1 :bar)
17  (graph:add-node g1 42)
18  (graph:add-edge g1 '("foo" :bar) "a")
19  (graph:add-edge g1 '(:bar 42) "b")
20  (graph:add-edge g1 '(42 "foo") "c")
21  (is (stringp (dat/dot::to-dot g1)))
22  (dat/dot::to-dot-file g1 "/tmp/test")
23  (is (probe-file "/tmp/test"))
24  (is (delete-file "/tmp/test"))))
25 
26 (deftest csv ()
27  "Test CSV functionality."
28  (is
29  (not
30  (sequence:emptyp
31  (with-output-to-string (str)
32  (dat/csv:write-csv-stream
33  str
34  #(#(1 2 3 4) #(2 3 4 5) #(3 4 5 6))))))))
35 
36 (deftest json ()
37  (let ((str (format nil "[~s,2,true,null]" "Hello, world!"))
38  (obj (list "Hello, world!" 2 t nil)))
39  (multiple-value-bind (res pos) (json-decode str)
40  (is (equal obj res))
41  (is (= pos 29)))
42  (is (equal str (with-output-to-string (s) (json-encode obj s)))))
43  (let ((str2 "[1,2,3]"))
44  (is (equal '(1 2 3) (deserialize str2 :json :end (length str2))))
45  (is (equal str2 (with-output-to-string (s) (serialize (list 1 2 3) :json :stream s))))))
46 
47 (deftest xml ()
48  (is (equal "foo" (xml-node-name (xml-parse "<foo></foo>")))))
49 
50 (deftest toml ()
51  "Tests based on https://github.com/toml-lang/toml-test"
52  ;; comment
53  ;; int
54  ;; hex
55  ;; octet
56  ;; binary
57  ;; float
58  ;; bool
59  ;; datetime
60  ;; string
61  ;; array
62  ;; kv
63  )
64 
65 (defparameter *arff-input*
66  "% 1. Title: Iris Plants Database
67 %
68 % 2. Sources:
69 % (a) Creator: R.A. Fisher
70 % (b) Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)
71 % (c) Date: July, 1988
72 %
73 @RELATION iris
74 @ATTRIBUTE sepallength NUMERIC
75 @ATTRIBUTE sepalwidth NUMERIC
76 @ATTRIBUTE petallength NUMERIC
77 @ATTRIBUTE petalwidth NUMERIC
78 @ATTRIBUTE class {Iris-setosa,Iris-versicolor,Iris-virginica}")
79 
80 (deftest arff ()
81  (is (typep (parse-arff-string *arff-input*) 'arff)))
82 
83 (deftest bencode ())
84 
85 (defvar *sxp-test-long* "(edges-1
86 (
87 (1389.886593 1341.567282)
88 (1383.122623 1339.369530)
89 )
90 (
91 (1383.122623 1339.369530)
92 (1387.706464 1325.261939)
93 )
94 (
95 (1387.706464 1325.261939)
96 (1394.470360 1327.459664)
97 )
98 (
99 (1394.470360 1327.459664)
100 (1389.886593 1341.567282)
101 )
102 ) ; edges end
103 
104 (edges-2
105 ( ( 1.1 2.2 ) (2.2 3.3) )
106 ( ( 2.2 3.3 ) (3.3 3.3) )
107 ( ( 3.3 3.3 ) (1.1 2.2) )
108 ) ; end edges of triangle room
109 
110 (= 4 4)
111 (= 5 4)
112 (> 4.0 54.0)
113 (= 4 s)
114 (= (= 4 4) (> 5 4))
115 (not (= 3 3))
116 (not 4)
117 (if (= 4 4) 42 666)
118 (if (= 4.0 4.0) (42))
119 (+ 4 4)
120 (+ 5.0 6.5)
121 (- 4 5)
122 (^ 2 3)
123 (^ 3 2)
124 (^ 3 (+ 2 1))
125 ")
126 
127 (defvar *sxp-test-short* "(FOO 'BAR `(\"test\" ,BAZ ,@QUX) 123 0.0123 1/3 `(,A1 ,A2))")
128 
129 (deftest forms ()
130  (is (formp nil))
131  (is (formp t))
132  (is (formp 3.14))
133  (is (formp "string"))
134  (is (formp (mapc #`(',a1) '(a))))
135  (is (formp ())))
136 
137 (deftest sxp-string ()
138  (let ((f (make-instance 'sxp)))
139  (is (formp (read-sxp-string f *sxp-test-short*)))
140  (is (equalp (read-from-string (write-sxp-string f)) (read-from-string *sxp-test-short*)))))
141 
142 (deftest sxp-stream ()
143  (let ((f (make-instance 'sxp)))
144  (with-input-from-string (s *sxp-test-long*)
145  (read-sxp-stream f s))
146  (with-output-to-string (s)
147  (is (write-sxp-stream f s)))))
148 
149 (deftest parquet-basic ()
150  (is
151  (with-input-from-string
152  (s
153  (with-output-to-string (s)
154  (dat/parquet::parquet-write-magic s)))
155  (dat/parquet::parquet-read-magic s))))