Skip to content

Commit

Permalink
Release v0.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
mithrandie committed Jul 10, 2017
2 parents ac361ac + 93a8d47 commit 84c1b00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 13 additions & 2 deletions lib/query/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/mithrandie/csvq/lib/cmd"
"github.com/mithrandie/csvq/lib/parser"
"github.com/mithrandie/csvq/lib/ternary"
)

var fullWidthTable = &unicode.RangeTable{
Expand Down Expand Up @@ -280,7 +281,12 @@ func formatCSVCell(c Cell) string {
case parser.Boolean:
s = strconv.FormatBool(primary.(parser.Boolean).Bool())
case parser.Ternary:
s = strconv.FormatBool(primary.(parser.Ternary).Bool())
t := primary.(parser.Ternary)
if t.Ternary() == ternary.UNKNOWN {
s = ""
} else {
s = strconv.FormatBool(t.Bool())
}
case parser.Datetime:
s = quote(escapeCSVString(primary.(parser.Datetime).Format()))
case parser.Null:
Expand Down Expand Up @@ -323,7 +329,12 @@ func formatJsonCell(c Cell) string {
case parser.Boolean:
s = strconv.FormatBool(primary.(parser.Boolean).Bool())
case parser.Ternary:
s = strconv.FormatBool(primary.(parser.Ternary).Bool())
t := primary.(parser.Ternary)
if t.Ternary() == ternary.UNKNOWN {
s = "null"
} else {
s = strconv.FormatBool(t.Bool())
}
case parser.Datetime:
s = quote(escapeJsonString(primary.(parser.Datetime).Format()))
case parser.Null:
Expand Down
15 changes: 11 additions & 4 deletions lib/query/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ var encodeViewTests = []struct {
Header: NewHeaderWithoutId("test", []string{"c1", "c2\nsecond line", "c3"}),
Records: []Record{
NewRecordWithoutId([]parser.Primary{parser.NewInteger(-1), parser.NewTernary(ternary.UNKNOWN), parser.NewBoolean(true)}),
NewRecordWithoutId([]parser.Primary{parser.NewInteger(-1), parser.NewTernary(ternary.FALSE), parser.NewBoolean(true)}),
NewRecordWithoutId([]parser.Primary{parser.NewFloat(2.0123), parser.NewDatetimeFromString("2016-02-01T16:00:00.123456-07:00"), parser.NewString("abcdef")}),
NewRecordWithoutId([]parser.Primary{parser.NewInteger(34567890), parser.NewString(" abcdefghijklmnopqrstuvwxyzabcdefg\nhi\"jk\n"), parser.NewNull()}),
},
},
Format: cmd.CSV,
Result: "\"c1\",\"c2\nsecond line\",\"c3\"\n" +
"-1,,true\n" +
"-1,false,true\n" +
"2.0123,\"2016-02-01 16:00:00.123456\",\"abcdef\"\n" +
"34567890,\" abcdefghijklmnopqrstuvwxyzabcdefg\nhi\"\"jk\n\",",
Expand All @@ -88,7 +90,7 @@ var encodeViewTests = []struct {
Format: cmd.TSV,
WriteDelimiter: '\t',
Result: "\"c1\"\t\"c2\nsecond line\"\t\"c3\"\n" +
"-1\tfalse\ttrue\n" +
"-1\t\ttrue\n" +
"2.0123\t\"2016-02-01 16:00:00.123456\"\t\"abcdef\"\n" +
"34567890\t\" abcdefghijklmnopqrstuvwxyzabcdefg\nhi\"\"jk\n\"\t",
},
Expand All @@ -104,7 +106,7 @@ var encodeViewTests = []struct {
},
Format: cmd.CSV,
WithoutHeader: true,
Result: "-1,false,true\n" +
Result: "-1,,true\n" +
"2.0123,\"2016-02-01 16:00:00.123456\",\"abcdef\"\n" +
"34567890,\" abcdefghijklmnopqrstuvwxyzabcdefg\nhi\"\"jk\n\",",
},
Expand All @@ -121,7 +123,7 @@ var encodeViewTests = []struct {
Format: cmd.CSV,
LineBreak: cmd.CRLF,
Result: "\"c1\",\"c2\r\nsecond line\",\"c3\"\r\n" +
"-1,false,true\r\n" +
"-1,,true\r\n" +
"2.0123,\"2016-02-01 16:00:00.123456\",\"abcdef\"\r\n" +
"34567890,\" abcdefghijklmnopqrstuvwxyzabcdefg\r\nhi\"\"jk\r\n\",",
},
Expand All @@ -131,12 +133,18 @@ var encodeViewTests = []struct {
Header: NewHeaderWithoutId("test", []string{"c1", "c2\nsecond line", "c3"}),
Records: []Record{
NewRecordWithoutId([]parser.Primary{parser.NewInteger(-1), parser.NewTernary(ternary.UNKNOWN), parser.NewBoolean(true)}),
NewRecordWithoutId([]parser.Primary{parser.NewInteger(-1), parser.NewTernary(ternary.FALSE), parser.NewBoolean(true)}),
NewRecordWithoutId([]parser.Primary{parser.NewFloat(2.0123), parser.NewDatetimeFromString("2016-02-01T16:00:00.123456-07:00"), parser.NewString("abcdef")}),
NewRecordWithoutId([]parser.Primary{parser.NewInteger(34567890), parser.NewString(" abc\\defghi/jklmn\topqrstuvwxyzabcdefg\nhi\"jk\n"), parser.NewNull()}),
},
},
Format: cmd.JSON,
Result: "[" +
"{" +
"\"c1\":-1," +
"\"c2\\nsecond line\":null," +
"\"c3\":true" +
"}," +
"{" +
"\"c1\":-1," +
"\"c2\\nsecond line\":false," +
Expand Down Expand Up @@ -190,7 +198,6 @@ func TestEncodeView(t *testing.T) {
}
if s != v.Result {
t.Errorf("%s, result = %q, want %q", v.Name, s, v.Result)
t.Log(s)
}
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/urfave/cli"
)

var version = "v0.2.9"
var version = "v0.2.10"

func main() {
cli.AppHelpTemplate = appHHelpTemplate
Expand Down

0 comments on commit 84c1b00

Please sign in to comment.