package encoding_test

import "seekia/internal/encoding"

import "testing"

func TestEncoding(t *testing.T){

	isBase32, _ := encoding.VerifyStringContainsOnlyBase32Charset("abcd")
	if (isBase32 == false){
		t.Fatal("VerifyStringContainsOnlyBase32Charset failed test 1.")
	}

	isBase32, invalidCharacter := encoding.VerifyStringContainsOnlyBase32Charset("1234")
	if (isBase32 == true){
		t.Fatal("VerifyStringContainsOnlyBase32Charset failed test 2.")
	}
	if (invalidCharacter != "1"){
		t.Fatal("VerifyStringContainsOnlyBase32Charset failed test 3.")
	}

	isBase32, _ = encoding.VerifyStringContainsOnlyBase32Charset("abcdefghijklmnopqrstuvwxyz234567")
	if (isBase32 == false){
		t.Fatal("VerifyStringContainsOnlyBase32Charset failed test 4.")
	}

	isBase32, invalidCharacter = encoding.VerifyStringContainsOnlyBase32Charset("abcdefghijklmnopqrstuvwxyz1234567890")
	if (isBase32 == true){
		t.Fatal("VerifyStringContainsOnlyBase32Charset failed test 5.")
	}
	if (invalidCharacter != "1"){
		t.Fatal("VerifyStringContainsOnlyBase32Charset failed test 6.")
	}

	testString1 := "abcdefghijklmnopqrstuvwxyz234567\r"

	_, err := encoding.DecodeBase32StringToBytes(testString1)
	if (err == nil){
		t.Fatal(`DecodeBase32StringToBytes allowing \r.`)
	}

	testString2 := "abcdefghijklmnopqrstuvwxyz234567\n"

	_, err = encoding.DecodeBase32StringToBytes(testString2)
	if (err == nil){
		t.Fatal(`DecodeBase32StringToBytes allowing \n.`)
	}

	testString3 := "abcdefghijklmnopqrstuvwxyz234567"

	isValid, badCharacter := encoding.VerifyStringContainsOnlyBase32Charset(testString3)
	if (isValid == false){
		t.Fatal("VerifyStringContainsOnlyBase32Charset claims testString3 is invalid: " + badCharacter)
	}

	resultBytes, err := encoding.DecodeBase32StringToBytes(testString3)
	if (err != nil){
		t.Fatal("DecodeBase32StringToBytes failed to read testString3: " + err.Error())
	}

	hexEncoded := encoding.EncodeBytesToHexString(resultBytes)
	if (hexEncoded != "00443214c74254b635cf84653a56d7c675be77df"){
		t.Fatal("EncodeBytesToHexString result does not match expected result: " + hexEncoded)
	}

	base64Encoded := encoding.EncodeBytesToBase64String(resultBytes)
	if (base64Encoded != "AEQyFMdCVLY1z4RlOlbXxnW-d98="){
		t.Fatal("EncodeBytesToBase64String result does not match expected result: " + base64Encoded)
	}
}

