summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--examples/18-database/output/sqlite3/test.py24
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java13
3 files changed, 38 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index c99b777..761e9ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/.idea
/target
last-test-run.properties
+__pycache__
diff --git a/examples/18-database/output/sqlite3/test.py b/examples/18-database/output/sqlite3/test.py
new file mode 100644
index 0000000..885212b
--- /dev/null
+++ b/examples/18-database/output/sqlite3/test.py
@@ -0,0 +1,24 @@
+import os.path
+import sqlite3
+import unittest
+
+
+class DataTestCase(unittest.TestCase):
+ def test_create(self):
+ sql_script_path = os.path.join(os.path.dirname(__file__), "scripts/data/Data.sql")
+ with open(sql_script_path, "rt", encoding="utf-8") as sql_script_file:
+ sql_script = sql_script_file.read()
+
+ connection = sqlite3.connect(":memory:", autocommit=False)
+ cursor = connection.cursor()
+ cursor.executescript(sql_script)
+ connection.commit()
+
+ cursor.execute("INSERT INTO authors VALUES (1, 'Alice')")
+ cursor.execute("INSERT INTO authors VALUES (2, 'Bob')")
+ cursor.execute("INSERT INTO authors VALUES (3, 'Carol')")
+
+ cursor.execute("SELECT id, name FROM authors WHERE id > 1 ORDER BY id")
+ rows = cursor.fetchall()
+
+ self.assertEqual(rows, [(2, "Bob"), (3, "Carol")])
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
index dbd1227..d1f177d 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
@@ -32,6 +32,7 @@ public class ExampleTests {
var javaOutputPath = verifyJavaOutput(exampleSet);
var rustOutputPath = verifyRustOutput(exampleSet);
+ verifySqlite3Output(exampleSet);
verifyTypescriptOutput(exampleSet);
var transient0OutputDirs = Stream.of(javaOutputPath, rustOutputPath)
@@ -68,6 +69,18 @@ public class ExampleTests {
return verifyOutput(exampleSet, "rust", List.of(List.of("cargo", "test")));
}
+ private void verifySqlite3Output(
+ ExampleSet exampleSet
+ ) throws NoSuchAlgorithmException, IOException, InterruptedException {
+ verifyOutput(
+ exampleSet,
+ "sqlite3",
+ List.of(
+ List.of("python3", "-m", "unittest", "test.py")
+ )
+ );
+ }
+
private Optional<Path> verifyTypescriptOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException {
return verifyOutput(exampleSet, "typescript", List.of(
List.of("pnpm", "install"),