Skip to content

Commit

Permalink
Added test related to lang.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arijit Das committed Nov 19, 2019
1 parent a1195a3 commit e0d4b44
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4476,6 +4476,19 @@ func TestInvalidValUsage(t *testing.T) {
require.Contains(t, err.Error(), "Query syntax invalid.")
}

func TestOrderWithMultipleLangFail(t *testing.T) {
query := `
{
me(func: uid(0x1), orderasc: name@en:fr, orderdesc: lastname@ci, orderasc: salary) {
name
}
}
`
_, err := Parse(Request{Str: query})
require.Error(t, err)
require.Contains(t, err.Error(), "Sorting by an attribute: [name@en:fr] can only be done on one language")
}

func TestOrderWithLang(t *testing.T) {
query := `
{
Expand Down
19 changes: 19 additions & 0 deletions types/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ func TestSortStrings(t *testing.T) {
toString(t, list, StringID))
}

func TestSortLanguage(t *testing.T) {
// Sorting strings of german language.
list := getInput(t, StringID, []string{"öffnen", "zumachen"})
ul := getUIDList(2)

require.NoError(t, Sort(list, ul, []bool{false}, "de"))
require.EqualValues(t, []uint64{100, 200}, ul.Uids)
require.EqualValues(t, []string{"öffnen", "zumachen"},
toString(t, list, StringID))

// Sorting strings of swedish language.
list = getInput(t, StringID, []string{"öppna", "zon"})

require.NoError(t, Sort(list, ul, []bool{false}, "sv"))
require.EqualValues(t, []uint64{200, 100}, ul.Uids)
require.EqualValues(t, []string{"zon", "öppna"},
toString(t, list, StringID))
}

func TestSortInts(t *testing.T) {
list := getInput(t, IntID, []string{"22", "111", "11", "212"})
ul := getUIDList(4)
Expand Down

0 comments on commit e0d4b44

Please sign in to comment.