| 1 |
# Test of import de-duplication behavior. |
| 2 |
# |
| 3 |
# In packages a and b, there are three fixes, |
| 4 |
# each adding one of two imports, but in different order. |
| 5 |
# |
| 6 |
# In package a, the fixes are [foo, foo, bar], |
| 7 |
# and they are resolved as follows: |
| 8 |
# - foo is applied -> [foo] |
| 9 |
# - foo is coalesced -> [foo] |
| 10 |
# - bar is applied -> [foo bar] |
| 11 |
# The result is then formatted to [bar foo]. |
| 12 |
# |
| 13 |
# In package b, the fixes are [foo, bar, foo]: |
| 14 |
# - foo is applied -> [foo] |
| 15 |
# - bar is applied -> [foo bar] |
| 16 |
# - foo is coalesced -> [foo bar] |
| 17 |
# The same result is again formatted to [bar foo]. |
| 18 |
# |
| 19 |
# In more complex examples, the result |
| 20 |
# may be more subtly order-dependent. |
| 21 |
|
| 22 |
checker -marker -fix -v example.com/a example.com/b |
| 23 |
stderr applied 6 fixes, updated 2 files |
| 24 |
exit 0 |
| 25 |
|
| 26 |
-- go.mod -- |
| 27 |
module example.com |
| 28 |
go 1.22 |
| 29 |
|
| 30 |
-- a/a.go -- |
| 31 |
package a |
| 32 |
|
| 33 |
import ( |
| 34 |
//@ fix1("()//", "\"foo\"\n"), fix2("()//", "\"foo\"\n"), fix3("()//", "\"bar\"\n") |
| 35 |
) |
| 36 |
|
| 37 |
-- want/a/a.go -- |
| 38 |
package a |
| 39 |
|
| 40 |
import ( |
| 41 |
"bar" |
| 42 |
"foo" |
| 43 |
// @ fix1("()//", "\"foo\"\n"), fix2("()//", "\"foo\"\n"), fix3("()//", "\"bar\"\n") |
| 44 |
) |
| 45 |
|
| 46 |
-- b/b.go -- |
| 47 |
package b |
| 48 |
|
| 49 |
import ( |
| 50 |
//@ fix1("()//", "\"foo\"\n"), fix2("()//", "\"bar\"\n"), fix3("()//", "\"foo\"\n") |
| 51 |
) |
| 52 |
|
| 53 |
-- want/b/b.go -- |
| 54 |
package b |
| 55 |
|
| 56 |
import ( |
| 57 |
"bar" |
| 58 |
"foo" |
| 59 |
// @ fix1("()//", "\"foo\"\n"), fix2("()//", "\"bar\"\n"), fix3("()//", "\"foo\"\n") |
| 60 |
) |
| 61 |
|