Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort: StringSlice broken? #10792

Closed
coss opened this issue May 12, 2015 · 2 comments
Closed

sort: StringSlice broken? #10792

coss opened this issue May 12, 2015 · 2 comments

Comments

@coss
Copy link

@coss coss commented May 12, 2015

Maybe I'm missing something, but StringSlice seems broken. The documentation of sort.Strings says

Strings sorts a slice of strings in increasing order.

so I would exptect that it would sort by length instead of comparing lexically byte-wise.

Example:

a := []string{"A", "Ab", "Abc", "Abcd", "Xyz", "Yz", "Z"}
b := []string{"", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"}

Expect:

a = ["A", "Z", "Ab", "Yz", "Abc", "Xyz", "Abcd"]
b = ["", "***", "bar", "foo", "foo", "f00", "Hello", "%*&^*&^&"]

Got:

a = ["A", "Ab", "Abc", "Abcd", "Xyz", "Yz", "Z"]
b = ["", "%*&^*&^&", "***", "Hello", "bar", "f00", "foo", "foo"]

Note that the test case just tests that the input is sorted instead of comparing it against a expected fixture.

@randall77
Copy link
Contributor

@randall77 randall77 commented May 12, 2015

Working as intended. Increasing means lexicographically increasing here. We might want to update the docs.

@randall77
Copy link
Contributor

@randall77 randall77 commented May 12, 2015

Actually, the docs look pretty clear. The ordering is just < on strings.

@randall77 randall77 closed this May 12, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.