Example #1
0
func TestTotalCoverage(t *testing.T) {

	for i, str := range anyStr {

		strStd := base64.StdEncoding.EncodeToString(str.strByte)
		if strStd != str.strEncodedStd {
			t.Error("#%d Expected string '%s' got %s", i, str.strEncodedStd, strStd)
		}

		strUrl := gotogen.ToBase64Url(str.strEncodedStd)
		if strUrl != str.strEncodedUrl {
			t.Error("#%d Expected string '%s' got %s", i, str.strEncodedUrl, strUrl)
		}

		strStd2 := gotogen.ToBase64Std(str.strEncodedUrl)
		if strStd2 != str.strEncodedStd {
			t.Error("#%d Expected string '%s' got %s", i, str.strEncodedStd, strStd2)
		}

		strByte, _ := base64.StdEncoding.DecodeString(str.strEncodedStd)
		if string(strByte) != string(str.strByte) {
			t.Error("#%d Expected []byte '%q' got %q", i, str.strByte, strByte)
		}
	}

}
Example #2
0
func TestBase64Std(t *testing.T) {
	data := []byte("some data with \x00 and \ufeff")
	str := base64.StdEncoding.EncodeToString(data)

	if str != "c29tZSBkYXRhIHdpdGggACBhbmQg77u/" {
		t.Error("Expected string 'c29tZSBkYXRhIHdpdGggACBhbmQg77u/' , got ", str)
	}

	base64url := gotogen.ToBase64Url(str)

	if base64url != "c29tZSBkYXRhIHdpdGggACBhbmQg77u_" {
		t.Error("Expected string 'c29tZSBkYXRhIHdpdGggACBhbmQg77u_' , got ", base64url)
	}

	base64std := gotogen.ToBase64Std(base64url)

	if base64std != "c29tZSBkYXRhIHdpdGggACBhbmQg77u/" {
		t.Error("Expected string std c29tZSBkYXRhIHdpdGggACBhbmQg77u/ , got ", base64std)
	}

	dataOrg, _ := base64.StdEncoding.DecodeString(base64std)

	if string(dataOrg) != "some data with \x00 and \ufeff" {
		t.Error("Expected string 'some data with \x00 and \ufeff' , got ", dataOrg)
	}

	data2 := []byte("any + old & data")
	str2 := base64.StdEncoding.EncodeToString(data2)

	if str2 != "YW55ICsgb2xkICYgZGF0YQ==" {
		t.Error("Expected string 'YW55ICsgb2xkICYgZGF0YQ==' , got ", str2)
	}

	base64url2 := gotogen.ToBase64Url(str2)

	if base64url2 != "YW55ICsgb2xkICYgZGF0YQ" {
		t.Error("Expected string 'YW55ICsgb2xkICYgZGF0YQ' , got ", base64url2)
	}
}