github.com/hashicorp/hcl/v2@v2.20.0/hclsyntax/didyoumean_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package hclsyntax 5 6 import "testing" 7 8 func TestNameSuggestion(t *testing.T) { 9 var keywords = []string{"false", "true", "null"} 10 11 tests := []struct { 12 Input, Want string 13 }{ 14 {"true", "true"}, 15 {"false", "false"}, 16 {"null", "null"}, 17 {"bananas", ""}, 18 {"NaN", ""}, 19 {"Inf", ""}, 20 {"Infinity", ""}, 21 {"void", ""}, 22 {"undefined", ""}, 23 24 {"ture", "true"}, 25 {"tru", "true"}, 26 {"tre", "true"}, 27 {"treu", "true"}, 28 {"rtue", "true"}, 29 30 {"flase", "false"}, 31 {"fales", "false"}, 32 {"flse", "false"}, 33 {"fasle", "false"}, 34 {"fasel", "false"}, 35 {"flue", "false"}, 36 37 {"nil", "null"}, 38 {"nul", "null"}, 39 {"unll", "null"}, 40 {"nll", "null"}, 41 } 42 43 for _, test := range tests { 44 t.Run(test.Input, func(t *testing.T) { 45 got := nameSuggestion(test.Input, keywords) 46 if got != test.Want { 47 t.Errorf( 48 "wrong result\ninput: %q\ngot: %q\nwant: %q", 49 test.Input, got, test.Want, 50 ) 51 } 52 }) 53 } 54 }