github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/internal/jsre/completion_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:38</date> 10 //</624450092425809920> 11 12 13 package jsre 14 15 import ( 16 "os" 17 "reflect" 18 "testing" 19 ) 20 21 func TestCompleteKeywords(t *testing.T) { 22 re := New("", os.Stdout) 23 re.Run(` 24 function theClass() { 25 this.foo = 3; 26 this.gazonk = {xyz: 4}; 27 } 28 theClass.prototype.someMethod = function () {}; 29 var x = new theClass(); 30 var y = new theClass(); 31 y.someMethod = function override() {}; 32 `) 33 34 var tests = []struct { 35 input string 36 want []string 37 }{ 38 { 39 input: "x", 40 want: []string{"x."}, 41 }, 42 { 43 input: "x.someMethod", 44 want: []string{"x.someMethod("}, 45 }, 46 { 47 input: "x.", 48 want: []string{ 49 "x.constructor", 50 "x.foo", 51 "x.gazonk", 52 "x.someMethod", 53 }, 54 }, 55 { 56 input: "y.", 57 want: []string{ 58 "y.constructor", 59 "y.foo", 60 "y.gazonk", 61 "y.someMethod", 62 }, 63 }, 64 { 65 input: "x.gazonk.", 66 want: []string{ 67 "x.gazonk.constructor", 68 "x.gazonk.hasOwnProperty", 69 "x.gazonk.isPrototypeOf", 70 "x.gazonk.propertyIsEnumerable", 71 "x.gazonk.toLocaleString", 72 "x.gazonk.toString", 73 "x.gazonk.valueOf", 74 "x.gazonk.xyz", 75 }, 76 }, 77 } 78 for _, test := range tests { 79 cs := re.CompleteKeywords(test.input) 80 if !reflect.DeepEqual(cs, test.want) { 81 t.Errorf("wrong completions for %q\ngot %v\nwant %v", test.input, cs, test.want) 82 } 83 } 84 } 85