(t *testing.T)
| 17 | } |
| 18 | |
| 19 | func TestDialectIdentityWriting(t *testing.T) { |
| 20 | |
| 21 | for _, td := range []testDialect{ |
| 22 | {lex.Token{V: "name"}, "name"}, |
| 23 | {lex.Token{Quote: '`', V: "has.period"}, "`has.period`"}, |
| 24 | {lex.Token{Quote: '`', V: "has`.`period"}, "has.period"}, |
| 25 | {lex.Token{V: "has space"}, "`has space`"}, |
| 26 | } { |
| 27 | dw := NewDefaultWriter() |
| 28 | in := NewIdentityNode(&td.t) |
| 29 | in.WriteDialect(dw) |
| 30 | assert.Equal(t, td.expect, dw.String()) |
| 31 | } |
| 32 | |
| 33 | for _, td := range []testDialect{ |
| 34 | {lex.Token{V: "name"}, "name"}, |
| 35 | {lex.Token{Quote: '`', V: "has.period"}, "'has.period'"}, |
| 36 | {lex.Token{V: "has space"}, "'has space'"}, |
| 37 | } { |
| 38 | dw := NewDialectWriter('"', '\'') |
| 39 | in := NewIdentityNode(&td.t) |
| 40 | in.WriteDialect(dw) |
| 41 | assert.Equal(t, td.expect, dw.String()) |
| 42 | } |
| 43 | |
| 44 | for _, td := range []testDialect{ |
| 45 | {lex.Token{V: "name"}, "name"}, |
| 46 | {lex.Token{Quote: '`', V: "has.period"}, "[has.period]"}, |
| 47 | {lex.Token{V: "has space"}, "[has space]"}, |
| 48 | } { |
| 49 | dw := NewDialectWriter('"', '[') |
| 50 | in := NewIdentityNode(&td.t) |
| 51 | in.WriteDialect(dw) |
| 52 | assert.Equal(t, td.expect, dw.String()) |
| 53 | } |
| 54 | // strip Namespaces |
| 55 | for _, td := range []testDialect{ |
| 56 | {lex.Token{V: "name"}, "name"}, |
| 57 | {lex.Token{Quote: '`', V: "table_name`.`fieldname"}, "fieldname"}, |
| 58 | {lex.Token{V: "has space"}, "`has space`"}, |
| 59 | } { |
| 60 | dw := NewDefaultNoNamspaceWriter() |
| 61 | in := NewIdentityNode(&td.t) |
| 62 | in.WriteDialect(dw) |
| 63 | assert.Equal(t, td.expect, dw.String()) |
| 64 | } |
| 65 | } |
| 66 | func TestDialectValueWriting(t *testing.T) { |
| 67 | // Test value writing |
| 68 | for _, tc := range []struct { |
nothing calls this directly
no test coverage detected