How to use String method of main Package

Best Syzkaller code snippet using main.String

rename_test.go

Source:rename_test.go Github

copy

Full Screen

...30 }{31 // init() checks32 {33 ctxt: fakeContext(map[string][]string{34 "fmt": {`package fmt; type Stringer interface { String() }`},35 "main": {`36package main37import foo "fmt"38var v foo.Stringer39func f() { v.String(); f() }40`,41 `package main; var w int`},42 }),43 from: "main.v", to: "init",44 want: `you cannot have a var at package level named "init"`,45 },46 {47 from: "main.f", to: "init",48 want: `renaming this func "f" to "init" would make it a package initializer.*` +49 `but references to it exist`,50 },51 {52 from: "/go/src/main/0.go::foo", to: "init",53 want: `"init" is not a valid imported package name`,54 },55 // Export checks56 {57 from: "fmt.Stringer", to: "stringer",58 want: `renaming this type "Stringer" to "stringer" would make it unexported.*` +59 `breaking references from packages such as "main"`,60 },61 {62 from: "(fmt.Stringer).String", to: "string",63 want: `renaming this method "String" to "string" would make it unexported.*` +64 `breaking references from packages such as "main"`,65 },66 // Lexical scope checks67 {68 // file/package conflict, same file69 from: "main.v", to: "foo",70 want: `renaming this var "v" to "foo" would conflict.*` +71 `with this imported package name`,72 },73 {74 // file/package conflict, same file75 from: "main::foo", to: "v",76 want: `renaming this imported package name "foo" to "v" would conflict.*` +77 `with this package member var`,78 },79 {80 // file/package conflict, different files81 from: "main.w", to: "foo",82 want: `renaming this var "w" to "foo" would conflict.*` +83 `with this imported package name`,84 },85 {86 // file/package conflict, different files87 from: "main::foo", to: "w",88 want: `renaming this imported package name "foo" to "w" would conflict.*` +89 `with this package member var`,90 },91 {92 ctxt: main(`93package main94var x, z int95func f(y int) {96 print(x)97 print(y)98}99func g(w int) {100 print(x)101 x := 1102 print(x)103}`),104 from: "main.x", to: "y",105 want: `renaming this var "x" to "y".*` +106 `would cause this reference to become shadowed.*` +107 `by this intervening var definition`,108 },109 {110 from: "main.g::x", to: "w",111 want: `renaming this var "x" to "w".*` +112 `conflicts with var in same block`,113 },114 {115 from: "main.f::y", to: "x",116 want: `renaming this var "y" to "x".*` +117 `would shadow this reference.*` +118 `to the var declared here`,119 },120 {121 from: "main.g::w", to: "x",122 want: `renaming this var "w" to "x".*` +123 `conflicts with var in same block`,124 },125 {126 from: "main.z", to: "y", want: "OK",127 },128 // Label checks129 {130 ctxt: main(`131package main132func f() {133foo:134 goto foo135bar:136 goto bar137 func(x int) {138 wiz:139 goto wiz140 }(0)141}142`),143 from: "main.f::foo", to: "bar",144 want: `renaming this label "foo" to "bar".*` +145 `would conflict with this one`,146 },147 {148 from: "main.f::foo", to: "wiz", want: "OK",149 },150 {151 from: "main.f::wiz", to: "x", want: "OK",152 },153 {154 from: "main.f::x", to: "wiz", want: "OK",155 },156 {157 from: "main.f::wiz", to: "foo", want: "OK",158 },159 // Struct fields160 {161 ctxt: main(`162package main163type U struct { u int }164type V struct { v int }165func (V) x() {}166type W (struct {167 U168 V169 w int170})171func f() {172 var w W173 print(w.u) // NB: there is no selection of w.v174 var _ struct { yy, zz int }175}176`),177 // field/field conflict in named struct declaration178 from: "(main.W).U", to: "w",179 want: `renaming this field "U" to "w".*` +180 `would conflict with this field`,181 },182 {183 // rename type used as embedded field184 // => rename field185 // => field/field conflict186 // This is an entailed renaming;187 // it would be nice if we checked source positions.188 from: "main.U", to: "w",189 want: `renaming this field "U" to "w".*` +190 `would conflict with this field`,191 },192 {193 // field/field conflict in unnamed struct declaration194 from: "main.f::zz", to: "yy",195 want: `renaming this field "zz" to "yy".*` +196 `would conflict with this field`,197 },198 // Now we test both directions of (u,v) (u,w) (v,w) (u,x) (v,x).199 // Too bad we don't test position info...200 {201 // field/field ambiguity at same promotion level ('from' selection)202 from: "(main.U).u", to: "v",203 want: `renaming this field "u" to "v".*` +204 `would make this reference ambiguous.*` +205 `with this field`,206 },207 {208 // field/field ambiguity at same promotion level ('to' selection)209 from: "(main.V).v", to: "u",210 want: `renaming this field "v" to "u".*` +211 `would make this reference ambiguous.*` +212 `with this field`,213 },214 {215 // field/method conflict at different promotion level ('from' selection)216 from: "(main.U).u", to: "w",217 want: `renaming this field "u" to "w".*` +218 `would change the referent of this selection.*` +219 `of this field`,220 },221 {222 // field/field shadowing at different promotion levels ('to' selection)223 from: "(main.W).w", to: "u",224 want: `renaming this field "w" to "u".*` +225 `would shadow this selection.*` +226 `of the field declared here`,227 },228 {229 from: "(main.V).v", to: "w",230 want: "OK", // since no selections are made ambiguous231 },232 {233 from: "(main.W).w", to: "v",234 want: "OK", // since no selections are made ambiguous235 },236 {237 // field/method ambiguity at same promotion level ('from' selection)238 from: "(main.U).u", to: "x",239 want: `renaming this field "u" to "x".*` +240 `would make this reference ambiguous.*` +241 `with this method`,242 },243 {244 // field/field ambiguity at same promotion level ('to' selection)245 from: "(main.V).x", to: "u",246 want: `renaming this method "x" to "u".*` +247 `would make this reference ambiguous.*` +248 `with this field`,249 },250 {251 // field/method conflict at named struct declaration252 from: "(main.V).v", to: "x",253 want: `renaming this field "v" to "x".*` +254 `would conflict with this method`,255 },256 {257 // field/method conflict at named struct declaration258 from: "(main.V).x", to: "v",259 want: `renaming this method "x" to "v".*` +260 `would conflict with this field`,261 },262 // Methods263 {264 ctxt: main(`265package main266type C int267func (C) f()268func (C) g()269type D int270func (*D) f()271func (*D) g()272type I interface { f(); g() }273type J interface { I; h() }274var _ I = new(D)275var _ interface {f()} = C(0)276`),277 from: "(main.I).f", to: "g",278 want: `renaming this interface method "f" to "g".*` +279 `would conflict with this method`,280 },281 {282 from: `("main".I).f`, to: "h", // NB: exercises quoted import paths too283 want: `renaming this interface method "f" to "h".*` +284 `would conflict with this method.*` +285 `in named interface type "J"`,286 },287 {288 // type J interface { h; h() } is not a conflict, amusingly.289 from: "main.I", to: "h",290 want: `OK`,291 },292 {293 from: "(main.J).h", to: "f",294 want: `renaming this interface method "h" to "f".*` +295 `would conflict with this method`,296 },297 {298 from: "(main.C).f", to: "e",299 want: `renaming this method "f" to "e".*` +300 `would make main.C no longer assignable to interface{f..}.*` +301 `(rename interface{f..}.f if you intend to change both types)`,302 },303 {304 from: "(main.D).g", to: "e",305 want: `renaming this method "g" to "e".*` +306 `would make \*main.D no longer assignable to interface I.*` +307 `(rename main.I.g if you intend to change both types)`,308 },309 {310 from: "(main.I).f", to: "e",311 want: `OK`,312 },313 // Indirect C/I method coupling via another concrete type D.314 {315 ctxt: main(`316package main317type I interface { f() }318type C int319func (C) f()320type D struct{C}321var _ I = D{}322`),323 from: "(main.C).f", to: "F",324 want: `renaming this method "f" to "F".*` +325 `would make main.D no longer assignable to interface I.*` +326 `(rename main.I.f if you intend to change both types)`,327 },328 // Renaming causes promoted method to become shadowed; C no longer satisfies I.329 {330 ctxt: main(`331package main332type I interface { f() }333type C struct { I }334func (C) g() int335var _ I = C{}336`),337 from: "main.I.f", to: "g",338 want: `renaming this method "f" to "g".*` +339 `would change the g method of main.C invoked via interface main.I.*` +340 `from \(main.I\).g.*` +341 `to \(main.C\).g`,342 },343 // Renaming causes promoted method to become ambiguous; C no longer satisfies I.344 {345 ctxt: main(`346package main347type I interface{f()}348type C int349func (C) f()350type D int351func (D) g()352type E struct{C;D}353var _ I = E{}354`),355 from: "main.I.f", to: "g",356 want: `renaming this method "f" to "g".*` +357 `would make the g method of main.E invoked via interface main.I ambiguous.*` +358 `with \(main.D\).g`,359 },360 } {361 var conflicts []string362 reportError = func(posn token.Position, message string) {363 conflicts = append(conflicts, message)364 }365 if test.ctxt != nil {366 ctxt = test.ctxt367 }368 err := Main(ctxt, test.offset, test.from, test.to)369 var prefix string370 if test.offset == "" {371 prefix = fmt.Sprintf("-from %q -to %q", test.from, test.to)372 } else {373 prefix = fmt.Sprintf("-offset %q -to %q", test.offset, test.to)374 }375 if err == ConflictError {376 got := strings.Join(conflicts, "\n")377 if false {378 t.Logf("%s: %s", prefix, got)379 }380 pattern := "(?s:" + test.want + ")" // enable multi-line matching381 if !regexp.MustCompile(pattern).MatchString(got) {382 t.Errorf("%s: conflict does not match pattern:\n"+383 "Conflict:\t%s\n"+384 "Pattern: %s",385 prefix, got, test.want)386 }387 } else if err != nil {388 t.Errorf("%s: unexpected error: %s", prefix, err)389 } else if test.want != "OK" {390 t.Errorf("%s: unexpected success, want conflicts matching:\n%s",391 prefix, test.want)392 }393 }394}395func TestInvalidIdentifiers(t *testing.T) {396 ctxt := fakeContext(map[string][]string{397 "main": {`398package main399func f() { }400`}})401 for _, test := range []struct {402 from, to string // values of the -offset/-from and -to flags403 want string // expected error message404 }{405 {406 from: "main.f", to: "_",407 want: `-to "_": not a valid identifier`,408 },409 {410 from: "main.f", to: "123",411 want: `-to "123": not a valid identifier`,412 },413 {414 from: "main.f", to: "for",415 want: `-to "for": not a valid identifier`,416 },417 {418 from: "switch", to: "v",419 want: `-from "switch": invalid expression`,420 },421 } {422 err := Main(ctxt, "", test.from, test.to)423 prefix := fmt.Sprintf("-from %q -to %q", test.from, test.to)424 if err == nil {425 t.Errorf("%s: expected error %q", prefix, test.want)426 } else if err.Error() != test.want {427 t.Errorf("%s: unexpected error\nwant: %s\n got: %s", prefix, test.want, err.Error())428 }429 }430}431func TestRewrites(t *testing.T) {432 defer func(savedWriteFile func(string, []byte) error) {433 writeFile = savedWriteFile434 }(writeFile)435 var ctxt *build.Context436 for _, test := range []struct {437 ctxt *build.Context // nil => use previous438 offset, from, to string // values of the -from/-offset and -to flags439 want map[string]string // contents of updated files440 }{441 // Elimination of renaming import.442 {443 ctxt: fakeContext(map[string][]string{444 "foo": {`package foo; type T int`},445 "main": {`package main446import foo2 "foo"447var _ foo2.T448`},449 }),450 from: "main::foo2", to: "foo",451 want: map[string]string{452 "/go/src/main/0.go": `package main453import "foo"454var _ foo.T455`,456 },457 },458 // Introduction of renaming import.459 {460 ctxt: fakeContext(map[string][]string{461 "foo": {`package foo; type T int`},462 "main": {`package main463import "foo"464var _ foo.T465`},466 }),467 offset: "/go/src/main/0.go:#36", to: "foo2", // the "foo" in foo.T468 want: map[string]string{469 "/go/src/main/0.go": `package main470import foo2 "foo"471var _ foo2.T472`,473 },474 },475 // Renaming of package-level member.476 {477 from: "foo.T", to: "U",478 want: map[string]string{479 "/go/src/main/0.go": `package main480import "foo"481var _ foo.U482`,483 "/go/src/foo/0.go": `package foo484type U int485`,486 },487 },488 // Rename package-level func plus doc489 {490 ctxt: main(`package main491// Foo is a no-op.492// Calling Foo does nothing.493func Foo() {494}495`),496 from: "main.Foo", to: "FooBar",497 want: map[string]string{498 "/go/src/main/0.go": `package main499// FooBar is a no-op.500// Calling FooBar does nothing.501func FooBar() {502}503`,504 },505 },506 // Rename method plus doc507 {508 ctxt: main(`package main509type Foo struct{}510// Bar does nothing.511func (Foo) Bar() {512}513`),514 from: "main.Foo.Bar", to: "Baz",515 want: map[string]string{516 "/go/src/main/0.go": `package main517type Foo struct{}518// Baz does nothing.519func (Foo) Baz() {520}521`,522 },523 },524 // Rename type spec plus doc525 {526 ctxt: main(`package main527type (528 // Test but not Testing.529 Test struct{}530)531`),532 from: "main.Test", to: "Type",533 want: map[string]string{534 "/go/src/main/0.go": `package main535type (536 // Type but not Testing.537 Type struct{}538)539`,540 },541 },542 // Rename type in gen decl plus doc543 {544 ctxt: main(`package main545// T is a test type.546type T struct{}547`),548 from: "main.T", to: "Type",549 want: map[string]string{550 "/go/src/main/0.go": `package main551// Type is a test type.552type Type struct{}553`,554 },555 },556 // Rename value spec with doc557 {558 ctxt: main(`package main559const (560 // C is the speed of light.561 C = 2.998e8562)563`),564 from: "main.C", to: "Lightspeed",565 want: map[string]string{566 "/go/src/main/0.go": `package main567const (568 // Lightspeed is the speed of light.569 Lightspeed = 2.998e8570)571`,572 },573 },574 // Rename value inside gen decl with doc575 {576 ctxt: main(`package main577var out *string578`),579 from: "main.out", to: "discard",580 want: map[string]string{581 "/go/src/main/0.go": `package main582var discard *string583`,584 },585 },586 // Rename field plus doc587 {588 ctxt: main(`package main589type Struct struct {590 // Field is a struct field.591 Field string592}593`),594 from: "main.Struct.Field", to: "Foo",595 want: map[string]string{596 "/go/src/main/0.go": `package main597type Struct struct {598 // Foo is a struct field.599 Foo string600}601`,602 },603 },604 // Label renamings.605 {606 ctxt: main(`package main607func f() {608loop:609 loop := 0610 go func() {611 loop:612 goto loop613 }()614 loop++615 goto loop616}617`),618 offset: "/go/src/main/0.go:#25", to: "loop2", // def of outer label "loop"619 want: map[string]string{620 "/go/src/main/0.go": `package main621func f() {622loop2:623 loop := 0624 go func() {625 loop:626 goto loop627 }()628 loop++629 goto loop2630}631`,632 },633 },634 {635 offset: "/go/src/main/0.go:#70", to: "loop2", // ref to inner label "loop"636 want: map[string]string{637 "/go/src/main/0.go": `package main638func f() {639loop:640 loop := 0641 go func() {642 loop2:643 goto loop2644 }()645 loop++646 goto loop647}648`,649 },650 },651 // Renaming of type used as embedded field.652 {653 ctxt: main(`package main654type T int655type U struct { T }656var _ = U{}.T657`),658 from: "main.T", to: "T2",659 want: map[string]string{660 "/go/src/main/0.go": `package main661type T2 int662type U struct{ T2 }663var _ = U{}.T2664`,665 },666 },667 // Renaming of embedded field.668 {669 ctxt: main(`package main670type T int671type U struct { T }672var _ = U{}.T673`),674 offset: "/go/src/main/0.go:#58", to: "T2", // T in "U{}.T"675 want: map[string]string{676 "/go/src/main/0.go": `package main677type T2 int678type U struct{ T2 }679var _ = U{}.T2680`,681 },682 },683 // Renaming of pointer embedded field.684 {685 ctxt: main(`package main686type T int687type U struct { *T }688var _ = U{}.T689`),690 offset: "/go/src/main/0.go:#59", to: "T2", // T in "U{}.T"691 want: map[string]string{692 "/go/src/main/0.go": `package main693type T2 int694type U struct{ *T2 }695var _ = U{}.T2696`,697 },698 },699 // Lexical scope tests.700 {701 ctxt: main(`package main702var y int703func f() {704 print(y)705 y := ""706 print(y)707}708`),709 from: "main.y", to: "x",710 want: map[string]string{711 "/go/src/main/0.go": `package main712var x int713func f() {714 print(x)715 y := ""716 print(y)717}718`,719 },720 },721 {722 from: "main.f::y", to: "x",723 want: map[string]string{724 "/go/src/main/0.go": `package main725var y int726func f() {727 print(y)728 x := ""729 print(x)730}731`,732 },733 },734 // Renaming of typeswitch vars (a corner case).735 {736 ctxt: main(`package main737func f(z interface{}) {738 switch y := z.(type) {739 case int:740 print(y)741 default:742 print(y)743 }744}745`),746 offset: "/go/src/main/0.go:#46", to: "x", // def of y747 want: map[string]string{748 "/go/src/main/0.go": `package main749func f(z interface{}) {750 switch x := z.(type) {751 case int:752 print(x)753 default:754 print(x)755 }756}757`},758 },759 {760 offset: "/go/src/main/0.go:#81", to: "x", // ref of y in case int761 want: map[string]string{762 "/go/src/main/0.go": `package main763func f(z interface{}) {764 switch x := z.(type) {765 case int:766 print(x)767 default:768 print(x)769 }770}771`},772 },773 {774 offset: "/go/src/main/0.go:#102", to: "x", // ref of y in default case775 want: map[string]string{776 "/go/src/main/0.go": `package main777func f(z interface{}) {778 switch x := z.(type) {779 case int:780 print(x)781 default:782 print(x)783 }784}785`},786 },787 // Renaming of embedded field that is a qualified reference.788 // (Regression test for bug 8924.)789 {790 ctxt: fakeContext(map[string][]string{791 "foo": {`package foo; type T int`},792 "main": {`package main793import "foo"794type _ struct{ *foo.T }795`},796 }),797 offset: "/go/src/main/0.go:#48", to: "U", // the "T" in *foo.T798 want: map[string]string{799 "/go/src/foo/0.go": `package foo800type U int801`,802 "/go/src/main/0.go": `package main803import "foo"804type _ struct{ *foo.U }805`,806 },807 },808 // Renaming of embedded field that is a qualified reference with the '-from' flag.809 // (Regression test for bug 12038.)810 {811 ctxt: fakeContext(map[string][]string{812 "foo": {`package foo; type T int`},813 "main": {`package main814import "foo"815type V struct{ *foo.T }816`},817 }),818 from: "(main.V).T", to: "U", // the "T" in *foo.T819 want: map[string]string{820 "/go/src/foo/0.go": `package foo821type U int822`,823 "/go/src/main/0.go": `package main824import "foo"825type V struct{ *foo.U }826`,827 },828 },829 {830 ctxt: fakeContext(map[string][]string{831 "foo": {`package foo; type T int`},832 "main": {`package main833import "foo"834type V struct{ foo.T }835`},836 }),837 from: "(main.V).T", to: "U", // the "T" in *foo.T838 want: map[string]string{839 "/go/src/foo/0.go": `package foo840type U int841`,842 "/go/src/main/0.go": `package main843import "foo"844type V struct{ foo.U }845`,846 },847 },848 // Interface method renaming.849 {850 ctxt: fakeContext(map[string][]string{851 "main": {`852package main853type I interface {854 f()855}856type J interface { f(); g() }857type A int858func (A) f()859type B int860func (B) f()861func (B) g()862type C int863func (C) f()864func (C) g()865var _, _ I = A(0), B(0)866var _, _ J = B(0), C(0)867`,868 },869 }),870 offset: "/go/src/main/0.go:#34", to: "F", // abstract method I.f871 want: map[string]string{872 "/go/src/main/0.go": `package main873type I interface {874 F()875}876type J interface {877 F()878 g()879}880type A int881func (A) F()882type B int883func (B) F()884func (B) g()885type C int886func (C) F()887func (C) g()888var _, _ I = A(0), B(0)889var _, _ J = B(0), C(0)890`,891 },892 },893 {894 offset: "/go/src/main/0.go:#59", to: "F", // abstract method J.f895 want: map[string]string{896 "/go/src/main/0.go": `package main897type I interface {898 F()899}900type J interface {901 F()902 g()903}904type A int905func (A) F()906type B int907func (B) F()908func (B) g()909type C int910func (C) F()911func (C) g()912var _, _ I = A(0), B(0)913var _, _ J = B(0), C(0)914`,915 },916 },917 {918 offset: "/go/src/main/0.go:#64", to: "G", // abstract method J.g919 want: map[string]string{920 "/go/src/main/0.go": `package main921type I interface {922 f()923}924type J interface {925 f()926 G()927}928type A int929func (A) f()930type B int931func (B) f()932func (B) G()933type C int934func (C) f()935func (C) G()936var _, _ I = A(0), B(0)937var _, _ J = B(0), C(0)938`,939 },940 },941 // Indirect coupling of I.f to C.f from D->I assignment and anonymous field of D.942 {943 ctxt: fakeContext(map[string][]string{944 "main": {`945package main946type I interface {947 f()948}949type C int950func (C) f()951type D struct{C}952var _ I = D{}953`,954 },955 }),956 offset: "/go/src/main/0.go:#34", to: "F", // abstract method I.f957 want: map[string]string{958 "/go/src/main/0.go": `package main959type I interface {960 F()961}962type C int963func (C) F()964type D struct{ C }965var _ I = D{}966`,967 },968 },969 // Interface embedded in struct. No conflict if C need not satisfy I.970 {971 ctxt: fakeContext(map[string][]string{972 "main": {`973package main974type I interface {975 f()976}977type C struct{I}978func (C) g() int979var _ int = C{}.g()980`,981 },982 }),983 offset: "/go/src/main/0.go:#34", to: "g", // abstract method I.f984 want: map[string]string{985 "/go/src/main/0.go": `package main986type I interface {987 g()988}989type C struct{ I }990func (C) g() int991var _ int = C{}.g()992`,993 },994 },995 // A type assertion causes method coupling iff signatures match.996 {997 ctxt: fakeContext(map[string][]string{998 "main": {`package main999type I interface{1000 f()1001}1002type J interface{1003 f()1004}1005var _ = I(nil).(J)1006`,1007 },1008 }),1009 offset: "/go/src/main/0.go:#32", to: "g", // abstract method I.f1010 want: map[string]string{1011 "/go/src/main/0.go": `package main1012type I interface {1013 g()1014}1015type J interface {1016 g()1017}1018var _ = I(nil).(J)1019`,1020 },1021 },1022 // Impossible type assertion: no method coupling.1023 {1024 ctxt: fakeContext(map[string][]string{1025 "main": {`package main1026type I interface{1027 f()1028}1029type J interface{1030 f()int1031}1032var _ = I(nil).(J)1033`,1034 },1035 }),1036 offset: "/go/src/main/0.go:#32", to: "g", // abstract method I.f1037 want: map[string]string{1038 "/go/src/main/0.go": `package main1039type I interface {1040 g()1041}1042type J interface {1043 f() int1044}1045var _ = I(nil).(J)1046`,1047 },1048 },1049 // Impossible type assertion: no method coupling C.f<->J.f.1050 {1051 ctxt: fakeContext(map[string][]string{1052 "main": {`package main1053type I interface{1054 f()1055}1056type C int1057func (C) f()1058type J interface{1059 f()int1060}1061var _ = I(C(0)).(J)1062`,1063 },1064 }),1065 offset: "/go/src/main/0.go:#32", to: "g", // abstract method I.f1066 want: map[string]string{1067 "/go/src/main/0.go": `package main1068type I interface {1069 g()1070}1071type C int1072func (C) g()1073type J interface {1074 f() int1075}1076var _ = I(C(0)).(J)1077`,1078 },1079 },1080 // Progress after "soft" type errors (Go issue 14596).1081 {1082 ctxt: fakeContext(map[string][]string{1083 "main": {`package main1084func main() {1085 var unused, x int1086 print(x)1087}1088`,1089 },1090 }),1091 offset: "/go/src/main/0.go:#54", to: "y", // var x1092 want: map[string]string{1093 "/go/src/main/0.go": `package main1094func main() {1095 var unused, y int1096 print(y)1097}1098`,1099 },1100 },1101 } {1102 if test.ctxt != nil {1103 ctxt = test.ctxt1104 }1105 got := make(map[string]string)1106 writeFile = func(filename string, content []byte) error {1107 got[filepath.ToSlash(filename)] = string(content)1108 return nil1109 }1110 err := Main(ctxt, test.offset, test.from, test.to)1111 var prefix string1112 if test.offset == "" {1113 prefix = fmt.Sprintf("-from %q -to %q", test.from, test.to)1114 } else {1115 prefix = fmt.Sprintf("-offset %q -to %q", test.offset, test.to)1116 }1117 if err != nil {1118 t.Errorf("%s: unexpected error: %s", prefix, err)1119 continue1120 }1121 for file, wantContent := range test.want {1122 gotContent, ok := got[file]1123 delete(got, file)1124 if !ok {1125 t.Errorf("%s: file %s not rewritten", prefix, file)1126 continue1127 }1128 if gotContent != wantContent {1129 t.Errorf("%s: rewritten file %s does not match expectation; got <<<%s>>>\n"+1130 "want <<<%s>>>", prefix, file, gotContent, wantContent)1131 }1132 }1133 // got should now be empty1134 for file := range got {1135 t.Errorf("%s: unexpected rewrite of file %s", prefix, file)1136 }1137 }1138}1139func TestDiff(t *testing.T) {1140 if runtime.GOOS == "windows" {1141 t.Skipf("diff tool non-existent for windows on builders")1142 }1143 if runtime.GOOS == "plan9" {1144 t.Skipf("plan9 diff tool doesn't support -u flag")1145 }1146 defer func() {1147 Diff = false1148 stdout = os.Stdout1149 }()1150 Diff = true1151 stdout = new(bytes.Buffer)1152 if err := Main(&build.Default, "", `"golang.org/x/tools/refactor/rename".justHereForTestingDiff`, "Foo"); err != nil {1153 t.Fatal(err)1154 }1155 // NB: there are tabs in the string literal!1156 if !strings.Contains(stdout.(fmt.Stringer).String(), `1157-func justHereForTestingDiff() {1158- justHereForTestingDiff()1159+func Foo() {1160+ Foo()1161 }1162`) {1163 t.Errorf("unexpected diff:\n<<%s>>", stdout)1164 }1165}1166func justHereForTestingDiff() {1167 justHereForTestingDiff()1168}1169// ---------------------------------------------------------------------1170// Simplifying wrapper around buildutil.FakeContext for packages whose...

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(a, b)4}5import (6func main() {7 fmt.Println(a, b)8}9import (10func main() {11 fmt.Println(a, b)12}13import (14func main() {15 fmt.Println(a, b)16}17import (18func main() {19 fmt.Println(a, b)20}21import (22func main() {23 fmt.Println(a, b)24}25import (26func main() {27 fmt.Println(a, b)28}29import (30func main() {31 fmt.Println(a, b)32}33import (34func main() {35 fmt.Println(a, b)36}37import (38func main() {39 fmt.Println(a, b)40}41import (

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var a = new(Student)4 fmt.Println(a)5}6&{Jack 21}7import "fmt"8type Student struct {9}10func (s *Student) String() string {11 return fmt.Sprintf("Name: %s, Age: %d", s.Name, s.Age)12}13func main() {14 var a = new(Student)15 fmt.Println(a)16}

Full Screen

Full Screen

String

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 var s1 = mainStruct{"abc", 123}4 fmt.Println(s1.String())5}6import "fmt"7func main() {8 var s1 = mainStruct{"abc", 123}9 fmt.Println(s1)10}11The String() method is called when the object is passed to Println()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful