gitee.com/liu-zhao234568/cntest@v1.0.0/internal/jsre/completion_test.go (about) 1 // Copyright 2016 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package jsre 18 19 import ( 20 "os" 21 "reflect" 22 "testing" 23 ) 24 25 func TestCompleteKeywords(t *testing.T) { 26 re := New("", os.Stdout) 27 re.Run(` 28 function theClass() { 29 this.foo = 3; 30 this.gazonk = {xyz: 4}; 31 } 32 theClass.prototype.someMethod = function () {}; 33 var x = new theClass(); 34 var y = new theClass(); 35 y.someMethod = function override() {}; 36 `) 37 38 var tests = []struct { 39 input string 40 want []string 41 }{ 42 { 43 input: "St", 44 want: []string{"String"}, 45 }, 46 { 47 input: "x", 48 want: []string{"x."}, 49 }, 50 { 51 input: "x.someMethod", 52 want: []string{"x.someMethod("}, 53 }, 54 { 55 input: "x.", 56 want: []string{ 57 "x.constructor", 58 "x.foo", 59 "x.gazonk", 60 "x.someMethod", 61 }, 62 }, 63 { 64 input: "y.", 65 want: []string{ 66 "y.constructor", 67 "y.foo", 68 "y.gazonk", 69 "y.someMethod", 70 }, 71 }, 72 { 73 input: "x.gazonk.", 74 want: []string{ 75 "x.gazonk.constructor", 76 "x.gazonk.hasOwnProperty", 77 "x.gazonk.isPrototypeOf", 78 "x.gazonk.propertyIsEnumerable", 79 "x.gazonk.toLocaleString", 80 "x.gazonk.toString", 81 "x.gazonk.valueOf", 82 "x.gazonk.xyz", 83 }, 84 }, 85 } 86 for _, test := range tests { 87 cs := re.CompleteKeywords(test.input) 88 if !reflect.DeepEqual(cs, test.want) { 89 t.Errorf("wrong completions for %q\ngot %v\nwant %v", test.input, cs, test.want) 90 } 91 } 92 }