|
1 | 1 | package lang_test
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 | 4 | "testing"
|
6 | 5 |
|
| 6 | + // Namespace imports |
| 7 | + . "github.com/mutablelogic/go-sqlite" |
7 | 8 | . "github.com/mutablelogic/go-sqlite/pkg/lang"
|
8 | 9 | )
|
9 | 10 |
|
10 | 11 | func Test_Create_000(t *testing.T) {
|
11 | 12 | tests := []struct {
|
12 |
| - In Statement |
13 |
| - String string |
14 |
| - Query string |
| 13 | + In SQStatement |
| 14 | + Query string |
15 | 15 | }{
|
16 |
| - {N("foo").CreateTable(), `CREATE TABLE foo ()`, ``}, |
17 |
| - {N("foo").CreateTable().WithTemporary(), `CREATE TEMPORARY TABLE foo ()`, ``}, |
18 |
| - {N("foo").CreateTable().IfNotExists(), `CREATE TABLE IF NOT EXISTS foo ()`, ``}, |
19 |
| - {N("foo").CreateTable(C("a"), C("b")), `CREATE TABLE foo (a TEXT,b TEXT)`, ``}, |
20 |
| - {N("test").CreateTable(), "CREATE TABLE test ()", ""}, |
21 |
| - {N("test").WithSchema("main").CreateTable(), "CREATE TABLE main.test ()", ""}, |
22 |
| - {N("test").CreateTable().WithTemporary(), "CREATE TEMPORARY TABLE test ()", ""}, |
23 |
| - {N("test").CreateTable().IfNotExists(), "CREATE TABLE IF NOT EXISTS test ()", ""}, |
24 |
| - {N("test").CreateTable().WithoutRowID(), "CREATE TABLE test () WITHOUT ROWID", ""}, |
25 |
| - {N("foo").CreateTable(C("a").NotNull(), C("b").NotNull()), `CREATE TABLE foo (a TEXT NOT NULL,b TEXT NOT NULL)`, ``}, |
26 |
| - {N("foo").CreateTable(C("a").WithPrimary(), C("b")), `CREATE TABLE foo (a TEXT NOT NULL PRIMARY KEY,b TEXT)`, ``}, |
27 |
| - {N("test").CreateTable(N("a").WithType("TEXT"), N("b").WithType("TEXT")), "CREATE TABLE test (a TEXT,b TEXT)", ""}, |
28 |
| - {N("test").CreateTable(N("a").WithType("TEXT").NotNull(), N("b").WithType("TEXT").NotNull()), "CREATE TABLE test (a TEXT NOT NULL,b TEXT NOT NULL)", ""}, |
29 |
| - {N("test").CreateTable(N("a").WithType("CUSTOM TYPE")), "CREATE TABLE test (a \"CUSTOM TYPE\")", ""}, |
30 |
| - {N("test").CreateTable(N("a").WithType("CUSTOM TYPE").NotNull()), "CREATE TABLE test (a \"CUSTOM TYPE\" NOT NULL)", ""}, |
31 |
| - {N("test").CreateTable(N("a").WithType("TEXT").WithPrimary()), "CREATE TABLE test (a TEXT NOT NULL PRIMARY KEY)", ""}, |
32 |
| - {N("test").CreateTable(N("a").WithType("TEXT").WithPrimary(), N("b").WithType("TEXT").WithPrimary()), "CREATE TABLE test (a TEXT NOT NULL,b TEXT NOT NULL,PRIMARY KEY (a,b))", ""}, |
33 |
| - {N("test").CreateTable(N("a").WithType("TEXT")).WithIndex("a"), "CREATE TABLE test (a TEXT,INDEX (a))", ""}, |
34 |
| - {N("test").CreateTable(N("a").WithType("TEXT"), N("b").WithType("TEXT")).WithIndex("a", "b"), "CREATE TABLE test (a TEXT,b TEXT,INDEX (a,b))", ""}, |
35 |
| - {N("test").CreateTable(N("a").WithType("TEXT"), N("b").WithType("TEXT")).WithUnique("a").WithUnique("b"), "CREATE TABLE test (a TEXT,b TEXT,UNIQUE (a),UNIQUE (b))", ""}, |
36 |
| - {N("test").CreateTable(N("a").WithType("TEXT").WithPrimary(), N("b").WithType("TEXT")).WithUnique("b"), "CREATE TABLE test (a TEXT NOT NULL PRIMARY KEY,b TEXT,UNIQUE (b))", ""}, |
37 |
| - {N("test").CreateTable(N("a").WithType("TEXT").WithAutoIncrement(), N("b").WithType("TEXT")).WithUnique("b"), "CREATE TABLE test (a TEXT NOT NULL PRIMARY KEY AUTOINCREMENT,b TEXT,UNIQUE (b))", ""}, |
| 16 | + {N("foo").CreateTable(), `CREATE TABLE foo ()`}, |
| 17 | + {N("foo").CreateTable().WithTemporary(), `CREATE TEMPORARY TABLE foo ()`}, |
| 18 | + {N("foo").CreateTable().IfNotExists(), `CREATE TABLE IF NOT EXISTS foo ()`}, |
| 19 | + {N("foo").CreateTable(C("a"), C("b")), `CREATE TABLE foo (a TEXT,b TEXT)`}, |
| 20 | + {N("test").CreateTable(), "CREATE TABLE test ()"}, |
| 21 | + {N("test").WithSchema("main").CreateTable(), "CREATE TABLE main.test ()"}, |
| 22 | + {N("test").CreateTable().WithTemporary(), "CREATE TEMPORARY TABLE test ()"}, |
| 23 | + {N("test").CreateTable().IfNotExists(), "CREATE TABLE IF NOT EXISTS test ()"}, |
| 24 | + {N("test").CreateTable().WithoutRowID(), "CREATE TABLE test () WITHOUT ROWID"}, |
| 25 | + {N("foo").CreateTable(C("a").NotNull(), C("b").NotNull()), `CREATE TABLE foo (a TEXT NOT NULL,b TEXT NOT NULL)`}, |
| 26 | + {N("foo").CreateTable(C("a").WithPrimary(), C("b")), `CREATE TABLE foo (a TEXT NOT NULL PRIMARY KEY,b TEXT)`}, |
| 27 | + {N("test").CreateTable(N("a").WithType("TEXT"), N("b").WithType("TEXT")), "CREATE TABLE test (a TEXT,b TEXT)"}, |
| 28 | + {N("test").CreateTable(N("a").WithType("TEXT").NotNull(), N("b").WithType("TEXT").NotNull()), "CREATE TABLE test (a TEXT NOT NULL,b TEXT NOT NULL)"}, |
| 29 | + {N("test").CreateTable(N("a").WithType("CUSTOM TYPE")), "CREATE TABLE test (a \"CUSTOM TYPE\")"}, |
| 30 | + {N("test").CreateTable(N("a").WithType("CUSTOM TYPE").NotNull()), "CREATE TABLE test (a \"CUSTOM TYPE\" NOT NULL)"}, |
| 31 | + {N("test").CreateTable(N("a").WithType("TEXT").WithPrimary()), "CREATE TABLE test (a TEXT NOT NULL PRIMARY KEY)"}, |
| 32 | + {N("test").CreateTable(N("a").WithType("TEXT").WithPrimary(), N("b").WithType("TEXT").WithPrimary()), "CREATE TABLE test (a TEXT NOT NULL,b TEXT NOT NULL,PRIMARY KEY (a,b))"}, |
| 33 | + {N("test").CreateTable(N("a").WithType("TEXT")).WithIndex("a"), "CREATE TABLE test (a TEXT,INDEX (a))"}, |
| 34 | + {N("test").CreateTable(N("a").WithType("TEXT"), N("b").WithType("TEXT")).WithIndex("a", "b"), "CREATE TABLE test (a TEXT,b TEXT,INDEX (a,b))"}, |
| 35 | + {N("test").CreateTable(N("a").WithType("TEXT"), N("b").WithType("TEXT")).WithUnique("a").WithUnique("b"), "CREATE TABLE test (a TEXT,b TEXT,UNIQUE (a),UNIQUE (b))"}, |
| 36 | + {N("test").CreateTable(N("a").WithType("TEXT").WithPrimary(), N("b").WithType("TEXT")).WithUnique("b"), "CREATE TABLE test (a TEXT NOT NULL PRIMARY KEY,b TEXT,UNIQUE (b))"}, |
| 37 | + {N("test").CreateTable(N("a").WithType("TEXT").WithAutoIncrement(), N("b").WithType("TEXT")).WithUnique("b"), "CREATE TABLE test (a TEXT NOT NULL PRIMARY KEY AUTOINCREMENT,b TEXT,UNIQUE (b))"}, |
38 | 38 | }
|
39 | 39 |
|
40 | 40 | for _, test := range tests {
|
41 |
| - if v := fmt.Sprint(test.In); v != test.String { |
42 |
| - t.Errorf("Unexpected return from String(): %q, wanted %q", v, test.String) |
43 |
| - } else { |
44 |
| - t.Log(v) |
45 |
| - } |
46 |
| - if test.Query != "" { |
47 |
| - if v := test.In.Query(); v != test.Query { |
48 |
| - t.Errorf("Unexpected return from Query(): %q, wanted %q", v, test.Query) |
49 |
| - } |
| 41 | + if v := test.In.Query(); v != test.Query { |
| 42 | + t.Errorf("Unexpected return from Query(): %q, wanted %q", v, test.Query) |
50 | 43 | }
|
51 | 44 | }
|
52 | 45 | }
|
53 | 46 |
|
54 | 47 | func Test_Create_001(t *testing.T) {
|
55 | 48 | tests := []struct {
|
56 |
| - In Statement |
57 |
| - String string |
58 |
| - Query string |
| 49 | + In SQStatement |
| 50 | + Query string |
59 | 51 | }{
|
60 |
| - {N("foo").CreateTable(N("a").WithType("TEXT")).WithForeignKey(N("bar").ForeignKey(), "a"), `CREATE TABLE foo (a TEXT,FOREIGN KEY (a) REFERENCES bar)`, ``}, |
61 |
| - {N("foo").CreateTable(N("a").WithType("TEXT")).WithForeignKey(N("bar").ForeignKey("x", "y"), "a"), `CREATE TABLE foo (a TEXT,FOREIGN KEY (a) REFERENCES bar (x,y))`, ``}, |
62 |
| - {N("foo").CreateTable(N("a").WithType("TEXT")).WithForeignKey(N("bar").ForeignKey(), "a"), `CREATE TABLE foo (a TEXT,FOREIGN KEY (a) REFERENCES bar)`, ``}, |
| 52 | + {N("foo").CreateTable(N("a").WithType("TEXT")).WithForeignKey(N("bar").ForeignKey(), "a"), `CREATE TABLE foo (a TEXT,FOREIGN KEY (a) REFERENCES bar)`}, |
| 53 | + {N("foo").CreateTable(N("a").WithType("TEXT")).WithForeignKey(N("bar").ForeignKey("x", "y"), "a"), `CREATE TABLE foo (a TEXT,FOREIGN KEY (a) REFERENCES bar (x,y))`}, |
| 54 | + {N("foo").CreateTable(N("a").WithType("TEXT")).WithForeignKey(N("bar").ForeignKey(), "a"), `CREATE TABLE foo (a TEXT,FOREIGN KEY (a) REFERENCES bar)`}, |
63 | 55 | }
|
64 | 56 |
|
65 | 57 | for _, test := range tests {
|
66 |
| - if v := fmt.Sprint(test.In); v != test.String { |
67 |
| - t.Errorf("Unexpected return from String(): %q, wanted %q", v, test.String) |
68 |
| - } else { |
69 |
| - t.Log(v) |
70 |
| - } |
71 |
| - if test.Query != "" { |
72 |
| - if v := test.In.Query(); v != test.Query { |
73 |
| - t.Errorf("Unexpected return from Query(): %q, wanted %q", v, test.Query) |
74 |
| - } |
| 58 | + if v := test.In.Query(); v != test.Query { |
| 59 | + t.Errorf("Unexpected return from Query(): %q, wanted %q", v, test.Query) |
75 | 60 | }
|
76 | 61 | }
|
77 | 62 | }
|
0 commit comments