2024-10-22 23:32:57 +01:00
|
|
|
package sql3util_test
|
2024-07-03 14:06:07 +01:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2024-10-22 23:32:57 +01:00
|
|
|
"github.com/ncruces/go-sqlite3/util/sql3util"
|
2024-07-03 14:06:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestParse(t *testing.T) {
|
2024-10-22 23:32:57 +01:00
|
|
|
tab, err := sql3util.ParseTable(`CREATE TABLE child(x REFERENCES parent)`)
|
2024-07-03 14:06:07 +01:00
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if got := tab.Name; got != "child" {
|
|
|
|
|
t.Errorf("got %s, want child", got)
|
|
|
|
|
}
|
|
|
|
|
if got := len(tab.Columns); got != 1 {
|
|
|
|
|
t.Errorf("got %d, want 1", got)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
col := tab.Columns[0]
|
|
|
|
|
if got := col.Name; got != "x" {
|
|
|
|
|
t.Errorf("got %s, want x", got)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fk := col.ForeignKeyClause
|
|
|
|
|
if got := fk.Table; got != "parent" {
|
|
|
|
|
t.Errorf("got %s, want parent", got)
|
|
|
|
|
}
|
|
|
|
|
}
|