1// Copyright 2020 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package proptools 16 17import "testing" 18 19func TestPropertyNameForField(t *testing.T) { 20 tests := []struct { 21 name string 22 input string 23 want string 24 }{ 25 { 26 name: "short", 27 input: "S", 28 want: "s", 29 }, 30 { 31 name: "long", 32 input: "String", 33 want: "string", 34 }, 35 { 36 name: "uppercase", 37 input: "STRING", 38 want: "STRING", 39 }, 40 { 41 name: "mixed", 42 input: "StRiNg", 43 want: "stRiNg", 44 }, 45 { 46 name: "underscore", 47 input: "Under_score", 48 want: "under_score", 49 }, 50 { 51 name: "uppercase underscore", 52 input: "UNDER_SCORE", 53 want: "UNDER_SCORE", 54 }, 55 { 56 name: "x86", 57 input: "X86", 58 want: "x86", 59 }, 60 { 61 name: "x86_64", 62 input: "X86_64", 63 want: "x86_64", 64 }, 65 } 66 for _, tt := range tests { 67 t.Run(tt.name, func(t *testing.T) { 68 if got := PropertyNameForField(tt.input); got != tt.want { 69 t.Errorf("PropertyNameForField(%v) = %v, want %v", tt.input, got, tt.want) 70 } 71 }) 72 } 73} 74 75func TestFieldNameForProperty(t *testing.T) { 76 tests := []struct { 77 name string 78 input string 79 want string 80 }{ 81 { 82 name: "short lowercase", 83 input: "s", 84 want: "S", 85 }, 86 { 87 name: "short uppercase", 88 input: "S", 89 want: "S", 90 }, 91 { 92 name: "long lowercase", 93 input: "string", 94 want: "String", 95 }, 96 { 97 name: "long uppercase", 98 input: "STRING", 99 want: "STRING", 100 }, 101 { 102 name: "mixed", 103 input: "StRiNg", 104 want: "StRiNg", 105 }, 106 } 107 for _, tt := range tests { 108 t.Run(tt.name, func(t *testing.T) { 109 if got := FieldNameForProperty(tt.input); got != tt.want { 110 t.Errorf("FieldNameForProperty(%v) = %v, want %v", tt.input, got, tt.want) 111 } 112 }) 113 } 114} 115