diff --git a/db/select_test.go b/db/select_test.go index 895601c8..d0196ca5 100644 --- a/db/select_test.go +++ b/db/select_test.go @@ -1470,6 +1470,41 @@ func TestSelect(t *testing.T) { setupDB(1) + txt := ` + USE NS test DB test; + CREATE |person:1..10|; + UPDATE person:3 SET test = "ändrew"; + UPDATE person:5 SET test = "Another"; + UPDATE person:7 SET test = "alexander"; + UPDATE person:9 SET test = "Alexander"; + UPDATE person:2 SET test = "Tobie"; + UPDATE person:4 SET test = "1000"; + UPDATE person:6 SET test = "2"; + UPDATE person:8 SET test = null; + SELECT test FROM person ORDER BY test COLLATE ASC; + ` + + res, err := Execute(permsKV(), txt, nil) + So(err, ShouldBeNil) + So(res, ShouldHaveLength, 11) + So(res[10].Result, ShouldHaveLength, 10) + So(data.Consume(res[10].Result[0]).Get("test").Data(), ShouldEqual, nil) + So(data.Consume(res[10].Result[1]).Get("test").Data(), ShouldEqual, nil) + So(data.Consume(res[10].Result[2]).Get("test").Data(), ShouldEqual, nil) + So(data.Consume(res[10].Result[3]).Get("test").Data(), ShouldEqual, "1000") + So(data.Consume(res[10].Result[4]).Get("test").Data(), ShouldEqual, "2") + So(data.Consume(res[10].Result[5]).Get("test").Data(), ShouldEqual, "Alexander") + So(data.Consume(res[10].Result[6]).Get("test").Data(), ShouldEqual, "alexander") + So(data.Consume(res[10].Result[7]).Get("test").Data(), ShouldEqual, "ändrew") + So(data.Consume(res[10].Result[8]).Get("test").Data(), ShouldEqual, "Another") + So(data.Consume(res[10].Result[9]).Get("test").Data(), ShouldEqual, "Tobie") + + }) + + Convey("Order records with en-GB collation", t, func() { + + setupDB(1) + txt := ` USE NS test DB test; CREATE |person:1..10|; @@ -1505,6 +1540,41 @@ func TestSelect(t *testing.T) { setupDB(1) + txt := ` + USE NS test DB test; + CREATE |person:1..10|; + UPDATE person:3 SET test = "ändrew"; + UPDATE person:5 SET test = "Another"; + UPDATE person:7 SET test = "alexander"; + UPDATE person:9 SET test = "Alexander"; + UPDATE person:2 SET test = "Tobie"; + UPDATE person:4 SET test = "1000"; + UPDATE person:6 SET test = "2"; + UPDATE person:8 SET test = null; + SELECT test FROM person ORDER BY test COLLATE NUMERIC ASC; + ` + + res, err := Execute(permsKV(), txt, nil) + So(err, ShouldBeNil) + So(res, ShouldHaveLength, 11) + So(res[10].Result, ShouldHaveLength, 10) + So(data.Consume(res[10].Result[0]).Get("test").Data(), ShouldEqual, nil) + So(data.Consume(res[10].Result[1]).Get("test").Data(), ShouldEqual, nil) + So(data.Consume(res[10].Result[2]).Get("test").Data(), ShouldEqual, nil) + So(data.Consume(res[10].Result[3]).Get("test").Data(), ShouldEqual, "2") + So(data.Consume(res[10].Result[4]).Get("test").Data(), ShouldEqual, "1000") + So(data.Consume(res[10].Result[5]).Get("test").Data(), ShouldEqual, "Alexander") + So(data.Consume(res[10].Result[6]).Get("test").Data(), ShouldEqual, "alexander") + So(data.Consume(res[10].Result[7]).Get("test").Data(), ShouldEqual, "ändrew") + So(data.Consume(res[10].Result[8]).Get("test").Data(), ShouldEqual, "Another") + So(data.Consume(res[10].Result[9]).Get("test").Data(), ShouldEqual, "Tobie") + + }) + + Convey("Order records with en-GB collation and numeric sorting", t, func() { + + setupDB(1) + txt := ` USE NS test DB test; CREATE |person:1..10|; @@ -1536,7 +1606,7 @@ func TestSelect(t *testing.T) { }) - Convey("Order records with collation and numeric and insensitive sorting using unicode definition", t, func() { + Convey("Order records with en-GB collation and numeric and insensitive sorting using unicode definition", t, func() { setupDB(1) diff --git a/sql/exprs.go b/sql/exprs.go index 67a6c1b0..4b13d735 100644 --- a/sql/exprs.go +++ b/sql/exprs.go @@ -289,23 +289,23 @@ func (p *parser) parseType() (t, k string, err error) { } -func (p *parser) parseLanguage() (language.Tag, error) { +func (p *parser) parseLanguage() (tag language.Tag, err error) { - _, lit, err := p.shouldBe(IDENT, STRING) - if err != nil { - return language.English, &ParseError{Found: lit, Expected: []string{"string"}} - } + tag = language.English + + if _, lit, exi := p.mightBe(IDENT, STRING); exi { + + if tag, err = language.Parse(lit); err != nil { + return tag, &ParseError{Found: lit, Expected: []string{"BCP47 language"}} + } - tag, err := language.Parse(lit) - if err != nil { - return language.English, &ParseError{Found: lit, Expected: []string{"BCP47 language"}} } if _, _, exi := p.mightBe(NUMERIC); exi { tag, _ = tag.SetTypeForKey("kn", "true") } - return tag, err + return tag, nil }