tests: add a test for the Nity sqlite3 module
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 16 Jul 2014 16:49:46 +0000 (12:49 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 18 Jul 2014 16:06:51 +0000 (12:06 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

tests/sav/test_sqlite3_nity.res [new file with mode: 0644]
tests/test_sqlite3_nity.nit [new file with mode: 0644]

diff --git a/tests/sav/test_sqlite3_nity.res b/tests/sav/test_sqlite3_nity.res
new file mode 100644 (file)
index 0000000..4101597
--- /dev/null
@@ -0,0 +1,12 @@
+####
+uname: Bob
+pass: zzz
+activated: 1
+perc: 77.7
+####
+uname: Guillaume
+pass: xxx
+activated: 1
+perc: 88.8
+true
+false
diff --git a/tests/test_sqlite3_nity.nit b/tests/test_sqlite3_nity.nit
new file mode 100644 (file)
index 0000000..02f238a
--- /dev/null
@@ -0,0 +1,60 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2013 Guillaume Auger <jeho@resist.ca>
+# Copyright 2013-2014 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+module test_sqlite3_nity
+
+import sqlite3
+
+var path = "test_nity.db"
+if path.file_exists then path.file_delete
+
+var db = new Sqlite3DB.open(path)
+assert db.is_open else print db.error or else "no error?"
+
+assert db.create_table("IF NOT EXISTS users (uname TEXT PRIMARY KEY, pass TEXT NOT NULL, activated INTEGER, perc FLOAT)") else
+       print db.error or else "no error?"
+end
+
+assert db.insert("INTO users VALUES('Bob', 'zzz', 1, 77.7)") else
+       print db.error or else "no error?"
+end
+
+assert db.insert("INTO users VALUES('Guillaume', 'xxx', 1, 88.8)") else
+       print db.error or else "no error?"
+end
+
+for row in db.select("* FROM users") do
+       print "####"
+
+       printn "{row[0].name}: "
+       print row[0]
+
+       printn "{row[1].name}: "
+       var val = row[1].value
+       assert val isa Text
+       print val.to_s
+
+       printn "{row[2].name}: "
+       print row[2].to_i
+
+       printn "{row[3].name}: "
+       print row[3].to_f
+end
+
+print db.is_open
+db.close
+print db.is_open