decred.org/dcrdex@v1.0.5/client/webserver/locales/parse_test.go (about) 1 package locales 2 3 import ( 4 "reflect" 5 "sort" 6 "testing" 7 ) 8 9 func TestTokens(t *testing.T) { 10 tmplFile := []byte(` 11 {{define "settings"}} 12 {{template "top" .}} 13 <div id="main" data-handler="settings" class="text-center py-5 overflow-y-auto"> 14 <div class="settings"> 15 <div class="form-check"> 16 <input class="form-check-input" type="checkbox" value="" id="showPokes" checked> 17 <label class="form-check-label" for="showPokes"> 18 [[[Show pop-up notifications]]] 19 </label> 20 </div> 21 <div id="fiatRateSources" {{if not .UserInfo.Authed}} class="d-hide"{{end}}> 22 <span class="mb-2" data-tooltip="[[[fiat_exchange_rate_msg]]]"> 23 [[[fiat_exchange_rate_sources]]]: 24 <span class="ico-info"></span> 25 </span> 26 <div> 27 <br> 28 <div {{if not .UserInfo.Authed}} class="d-hide"{{end}}> 29 <p> 30 [[[simultaneous_servers_msg]]] 31 </p> 32 <button id="addADex" class="bg2 selected">[[[Add a DEX]]]</button> 33 <button id="importAccount" class="bg2 selected ms-2">[[[Import Account]]]</button> 34 </div> 35 </div> 36 </div> 37 {{template "bottom"}} 38 {{end}} 39 [[[ and Lets tRy: a_different _HARDER_ .pattern. ::.-_-. ]]] 40 [[[this shouldn't be included because of this number here: 1]]] 41 `) 42 wantTokens := []string{ 43 "[[[Show pop-up notifications]]]", 44 "[[[fiat_exchange_rate_msg]]]", 45 "[[[fiat_exchange_rate_sources]]]", 46 "[[[simultaneous_servers_msg]]]", 47 "[[[Add a DEX]]]", 48 "[[[Import Account]]]", 49 "[[[ and Lets tRy: a_different _HARDER_ .pattern. ::.-_-. ]]]", 50 } 51 sort.Slice(wantTokens, func(i, j int) bool { 52 return wantTokens[i] < wantTokens[j] 53 }) 54 wantKeys := []string{ 55 "Show pop-up notifications", 56 "fiat_exchange_rate_msg", 57 "fiat_exchange_rate_sources", 58 "simultaneous_servers_msg", 59 "Add a DEX", 60 "Import Account", 61 " and Lets tRy: a_different _HARDER_ .pattern. ::.-_-. ", 62 } 63 sort.Slice(wantKeys, func(i, j int) bool { 64 return wantKeys[i] < wantKeys[j] 65 }) 66 67 got := Tokens(tmplFile) 68 var ( 69 gotTokens []string 70 gotKeys []string 71 ) 72 for _, matchGroup := range got { 73 if len(matchGroup) != 2 { 74 t.Fatalf("can't parse match group: %v", matchGroup) 75 } 76 token, key := string(matchGroup[0]), string(matchGroup[1]) 77 gotTokens = append(gotTokens, token) 78 gotKeys = append(gotKeys, key) 79 } 80 sort.Slice(gotTokens, func(i, j int) bool { 81 return gotTokens[i] < gotTokens[j] 82 }) 83 sort.Slice(gotKeys, func(i, j int) bool { 84 return gotKeys[i] < gotKeys[j] 85 }) 86 87 if !reflect.DeepEqual(wantTokens, gotTokens) { 88 t.Fatalf("expected tokens: %+v, got: %+v", wantTokens, gotTokens) 89 } 90 if !reflect.DeepEqual(wantKeys, gotKeys) { 91 t.Fatalf("expected keys: %+v, got: %+v", wantKeys, gotKeys) 92 } 93 }