diff --git a/regtest/t006/numeric_test.go b/regtest/t006/numeric_test.go new file mode 100644 index 0000000..492a77c --- /dev/null +++ b/regtest/t006/numeric_test.go @@ -0,0 +1,27 @@ +package t001 + +import ( + "github.com/aj0strow/pgschema/regtest" + "github.com/aj0strow/pgschema/temp" + "testing" +) + +func TestArray(t *testing.T) { + conn, err := temp.Connect("pgschema") + if err != nil { + t.Fatal(err) + } + defer conn.Close() + rt := regtest.RegressionTest{ + Conn: conn, + SetupFile: "./setup.sql", + SourceFile: "./schema.hcl", + } + have, err := rt.Run() + if err != nil { + t.Fatal(err) + } + for _, c := range have { + t.Errorf(c.String()) + } +} diff --git a/regtest/t006/schema.hcl b/regtest/t006/schema.hcl new file mode 100644 index 0000000..dc250a2 --- /dev/null +++ b/regtest/t006/schema.hcl @@ -0,0 +1,8 @@ + +schema "_schema_" { + table "currency_pairs" { + column "tick_size" { + type = "numeric(24, 16)" + } + } +} diff --git a/regtest/t006/setup.sql b/regtest/t006/setup.sql new file mode 100644 index 0000000..97fe2e4 --- /dev/null +++ b/regtest/t006/setup.sql @@ -0,0 +1,4 @@ + +CREATE TABLE currency_pairs ( + tick_size numeric(24, 16) +); diff --git a/source/hcl/column_test.go b/source/hcl/column_test.go index 8bdef34..c172e69 100644 --- a/source/hcl/column_test.go +++ b/source/hcl/column_test.go @@ -69,6 +69,20 @@ func TestConvertColumn(t *testing.T) { }, }, }, + Test{ + "tick_size", + Column{ + Type: "numeric(24, 16)", + }, + db.ColumnNode{ + Column: db.Column{ + ColumnName: "tick_size", + DataType: "numeric", + NumericPrecision: 24, + NumericScale: 16, + }, + }, + }, Test{ "upper4", Column{ diff --git a/source/hcl/hcl.go b/source/hcl/hcl.go index eedab4e..aef015c 100644 --- a/source/hcl/hcl.go +++ b/source/hcl/hcl.go @@ -112,7 +112,7 @@ func convertTable(tableName string, v Table) db.TableNode { } } -var numericRe = regexp.MustCompile(`numeric\((\d+),(\d+)\)`) +var numericRe = regexp.MustCompile(`numeric\((\d+),\s*(\d+)\)`) var arrayRe = regexp.MustCompile(`^(.+)(?:\[\d*\])+$`) func convertColumn(k string, v Column) db.ColumnNode {