gosimple / slug

URL-friendly slugify with multiple languages support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TestSubstituteLang is flaky

mwhudson opened this issue · comments

It fails about 12% of the time for me:

--- FAIL: TestSubstituteLang (0.00s)
    slug_test.go:155: 1. Substitute("o a o", map[string]string{"o":"no", "a":"or"}) = "no nor no"; want "no or no"
FAIL

/me subscribes to the bug

Hello, thank you for your report.
I will look into it when I will find some free time (probably this week but I can't promise that, flaky bugs can eat a lot of time to fix...).

OK, I see the problem.

Substitute is taking as input a map: https://github.com/gosimple/slug/blob/master/slug.go#L84
Because in Go maps return keys in random order when iterating over it then in case of this test sometimes replacing a with or run first and then on the second pass o in or gets replaced with no.

There are two possible solutions (without breaking API):

  1. always run substitution in same order (sorting keys alphabetically)
  2. leave it as is but remove this tests and document it's could give different results each time it's run.

I'm in favour of first way, but maybe some users like actual behaviour? What your thoughts?

Same problem could happen in SubstituteRune

I am also in favour of the first solution. It seems better to have reproductible output than removing tests.

Sorry it took so long. Fixed and tagged.

thanks!