github.com/klaytn/klaytn@v1.12.1/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: "St", 48 want: []string{"String"}, 49 }, 50 { 51 input: "x", 52 want: []string{"x."}, 53 }, 54 { 55 input: "x.someMethod", 56 want: []string{"x.someMethod("}, 57 }, 58 { 59 input: "x.", 60 want: []string{ 61 "x.constructor", 62 "x.foo", 63 "x.gazonk", 64 "x.someMethod", 65 }, 66 }, 67 { 68 input: "y.", 69 want: []string{ 70 "y.constructor", 71 "y.foo", 72 "y.gazonk", 73 "y.someMethod", 74 }, 75 }, 76 { 77 input: "x.gazonk.", 78 want: []string{ 79 "x.gazonk.__proto__", 80 "x.gazonk.constructor", 81 "x.gazonk.hasOwnProperty", 82 "x.gazonk.isPrototypeOf", 83 "x.gazonk.propertyIsEnumerable", 84 "x.gazonk.toLocaleString", 85 "x.gazonk.toString", 86 "x.gazonk.valueOf", 87 "x.gazonk.xyz", 88 }, 89 }, 90 } 91 for _, test := range tests { 92 cs := re.CompleteKeywords(test.input) 93 if !reflect.DeepEqual(cs, test.want) { 94 t.Errorf("wrong completions for %q\ngot %v\nwant %v", test.input, cs, test.want) 95 } 96 } 97 }