github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/nodejs/utilities_test.go (about) 1 // nolint: lll 2 package nodejs 3 4 import ( 5 "testing" 6 ) 7 8 func TestMakeSafeEnumName(t *testing.T) { 9 t.Parallel() 10 11 tests := []struct { 12 input string 13 expected string 14 wantErr bool 15 }{ 16 {"red", "Red", false}, 17 {"snake_cased_name", "Snake_cased_name", false}, 18 {"+", "", true}, 19 {"*", "Asterisk", false}, 20 {"0", "Zero", false}, 21 {"8.3", "TypeName_8_3", false}, 22 {"11", "TypeName_11", false}, 23 {"Microsoft-Windows-Shell-Startup", "Microsoft_Windows_Shell_Startup", false}, 24 {"Microsoft.Batch", "Microsoft_Batch", false}, 25 {"readonly", "Readonly", false}, 26 {"SystemAssigned, UserAssigned", "SystemAssigned_UserAssigned", false}, 27 {"Dev(NoSLA)_Standard_D11_v2", "Dev_NoSLA_Standard_D11_v2", false}, 28 {"Standard_E8as_v4+1TB_PS", "Standard_E8as_v4_1TB_PS", false}, 29 } 30 for _, tt := range tests { 31 tt := tt 32 t.Run(tt.input, func(t *testing.T) { 33 t.Parallel() 34 35 got, err := makeSafeEnumName(tt.input, "TypeName") 36 if (err != nil) != tt.wantErr { 37 t.Errorf("makeSafeEnumName() error = %v, wantErr %v", err, tt.wantErr) 38 return 39 } 40 if got != tt.expected { 41 t.Errorf("makeSafeEnumName() got = %v, want %v", got, tt.expected) 42 } 43 }) 44 } 45 } 46 47 func TestEscape(t *testing.T) { 48 t.Parallel() 49 tests := []struct { 50 input string 51 expected string 52 }{ 53 {"test", "test"}, 54 {"sub\"string\"", "sub\\\"string\\\""}, 55 {"slash\\s", "slash\\\\s"}, 56 {"N\\A \"bad data\"", "N\\\\A \\\"bad data\\\""}, 57 } 58 for _, tt := range tests { 59 tt := tt 60 t.Run(tt.input, func(t *testing.T) { 61 t.Parallel() 62 63 got := escape(tt.input) 64 if tt.expected != got { 65 t.Errorf("escape(%s) was %s want %s", tt.input, got, tt.expected) 66 } 67 }) 68 } 69 }