github.com/klaytn/klaytn@v1.10.2/console/jsre/completion_test.go (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2016 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from internal/jsre/completion_test.go (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 package jsre 22 23 import ( 24 "os" 25 "reflect" 26 "testing" 27 ) 28 29 func TestCompleteKeywords(t *testing.T) { 30 re := New("", os.Stdout) 31 re.Run(` 32 function theClass() { 33 this.foo = 3; 34 this.gazonk = {xyz: 4}; 35 } 36 theClass.prototype.someMethod = function () {}; 37 var x = new theClass(); 38 var y = new theClass(); 39 y.someMethod = function override() {}; 40 `) 41 42 tests := []struct { 43 input string 44 want []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 }