|
| 1 | +package postgres |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func Test_parseDefaultValueValue(t *testing.T) { |
| 6 | + type args struct { |
| 7 | + defaultValue string |
| 8 | + } |
| 9 | + tests := []struct { |
| 10 | + name string |
| 11 | + args args |
| 12 | + want string |
| 13 | + }{ |
| 14 | + { |
| 15 | + name: "it should works with number without colons", |
| 16 | + args: args{defaultValue: "0"}, |
| 17 | + want: "0", |
| 18 | + }, |
| 19 | + { |
| 20 | + name: "it should works with number and two colons", |
| 21 | + args: args{defaultValue: "0::int8"}, |
| 22 | + want: "0", |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "it should works with number and three colons", |
| 26 | + args: args{defaultValue: "0:::int8"}, |
| 27 | + want: "0", |
| 28 | + }, |
| 29 | + { |
| 30 | + name: "it should works with empty string without colons", |
| 31 | + args: args{defaultValue: "''"}, |
| 32 | + want: "''", |
| 33 | + }, |
| 34 | + { |
| 35 | + name: "it should works with empty string with two colons", |
| 36 | + args: args{defaultValue: "''::character varying"}, |
| 37 | + want: "''", |
| 38 | + }, |
| 39 | + { |
| 40 | + name: "it should works with empty string with three colons", |
| 41 | + args: args{defaultValue: "'':::character varying"}, |
| 42 | + want: "''", |
| 43 | + }, |
| 44 | + { |
| 45 | + name: "it should works with string without colons", |
| 46 | + args: args{defaultValue: "'field'"}, |
| 47 | + want: "'field'", |
| 48 | + }, |
| 49 | + { |
| 50 | + name: "it should works with string with two colons", |
| 51 | + args: args{defaultValue: "'field'::character varying"}, |
| 52 | + want: "'field'", |
| 53 | + }, |
| 54 | + { |
| 55 | + name: "it should works with string with three colons", |
| 56 | + args: args{defaultValue: "'field':::character varying"}, |
| 57 | + want: "'field'", |
| 58 | + }, |
| 59 | + { |
| 60 | + name: "it should works with value with two colons", |
| 61 | + args: args{defaultValue: "field"}, |
| 62 | + want: "field", |
| 63 | + }, |
| 64 | + { |
| 65 | + name: "it should works with value without colons", |
| 66 | + args: args{defaultValue: "field::character varying"}, |
| 67 | + want: "field", |
| 68 | + }, |
| 69 | + { |
| 70 | + name: "it should works with value with three colons", |
| 71 | + args: args{defaultValue: "field:::character varying"}, |
| 72 | + want: "field", |
| 73 | + }, |
| 74 | + { |
| 75 | + name: "it should works with function without colons", |
| 76 | + args: args{defaultValue: "now()"}, |
| 77 | + want: "now()", |
| 78 | + }, |
| 79 | + { |
| 80 | + name: "it should works with function with two colons", |
| 81 | + args: args{defaultValue: "now()::timestamp without time zone"}, |
| 82 | + want: "now()", |
| 83 | + }, |
| 84 | + { |
| 85 | + name: "it should works with json without colons", |
| 86 | + args: args{defaultValue: "{}"}, |
| 87 | + want: "{}", |
| 88 | + }, |
| 89 | + { |
| 90 | + name: "it should works with json with two colons", |
| 91 | + args: args{defaultValue: "{}::jsonb"}, |
| 92 | + want: "{}", |
| 93 | + }, |
| 94 | + } |
| 95 | + for _, tt := range tests { |
| 96 | + t.Run(tt.name, func(t *testing.T) { |
| 97 | + if got := parseDefaultValueValue(tt.args.defaultValue); got != tt.want { |
| 98 | + t.Errorf("parseDefaultValueValue() = %v, want %v", got, tt.want) |
| 99 | + } |
| 100 | + }) |
| 101 | + } |
| 102 | +} |
0 commit comments