All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m31s
247 lines
5.9 KiB
Go
247 lines
5.9 KiB
Go
package langext
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestDecodeBase64Any_StandardPadded(t *testing.T) {
|
|
input := "SGVsbG8gV29ybGQ=" // "Hello World" in standard Base64 (padded)
|
|
expected := "Hello World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_StandardUnpadded(t *testing.T) {
|
|
input := "SGVsbG8gV29ybGQ" // "Hello World" in standard Base64 (unpadded)
|
|
expected := "Hello World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_URLPadded(t *testing.T) {
|
|
input := "SGVsbG8tV29ybGQ=" // "Hello-World" in Base64 URL (padded)
|
|
expected := "Hello-World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_URLUnpadded(t *testing.T) {
|
|
input := "SGVsbG8tV29ybGQ" // "Hello-World" in Base64 URL (unpadded)
|
|
expected := "Hello-World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_IMAPPadded(t *testing.T) {
|
|
input := "SGVsbG8,V29ybGQ=" // "Hello/World" in Base64 IMAP (padded)
|
|
expected := "Hello?World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_IMAPUnpadded(t *testing.T) {
|
|
input := "SGVsbG8,V29ybGQ" // "Hello/World" in Base64 IMAP (unpadded)
|
|
expected := "Hello?World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_InvalidInput(t *testing.T) {
|
|
input := "Invalid@@Base64" // Invalid Base64 input
|
|
|
|
_, err := DecodeBase64Any(input)
|
|
if err == nil {
|
|
t.Fatal("expected an error, but got none")
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_EmptyInput(t *testing.T) {
|
|
input := "" // Empty input
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if len(result) != 0 {
|
|
t.Errorf("expected empty result, got %q", string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_WhitespaceInput(t *testing.T) {
|
|
input := " SGVsbG8gV29ybGQ= " // Input with leading and trailing spaces
|
|
expected := "Hello World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_LineBreaksInput(t *testing.T) {
|
|
input := "SGVs\nbG8g\nV29y\nbGQ=" // Input with line breaks
|
|
expected := "Hello World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_TabCharactersInput(t *testing.T) {
|
|
input := "SGVsbG8g\tV29ybGQ=" // Input with tab characters
|
|
expected := "Hello World"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_SpecialCharactersIgnored(t *testing.T) {
|
|
input := "SGVsbG8gV29ybGQ=!!" // Input with ignored special characters
|
|
|
|
_, err := DecodeBase64Any(input)
|
|
if err == nil {
|
|
t.Fatal("expected an error, but got none")
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_SingleCharacterInput(t *testing.T) {
|
|
input := "QQ==" // "A" in Base64
|
|
expected := "A"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_LongInput(t *testing.T) {
|
|
input := "U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIHdpdGggbXVsdGlwbGUgbGluZXMgYW5kIHNwYWNlcy4=" // Long Base64 string
|
|
expected := "Some very long string with multiple lines and spaces."
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_Standard63And64(t *testing.T) {
|
|
input := "Pz8/Pw==" // "???" in standard Base64 (63 = '+', 64 = '/')
|
|
expected := "????"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_Standard63And64_NoPad(t *testing.T) {
|
|
input := "Pz8/Pw" // "???" in standard Base64 (63 = '+', 64 = '/')
|
|
expected := "????"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_URL63And64(t *testing.T) {
|
|
input := "Pz8_Pw==" // "???" in Base64 URL-safe (63 = '_', 64 = '-')
|
|
expected := "????"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|
|
|
|
func TestDecodeBase64Any_URL63And64_NoPad(t *testing.T) {
|
|
input := "Pz8_Pw==" // "???" in Base64 URL-safe (63 = '_', 64 = '-')
|
|
expected := "????"
|
|
|
|
result, err := DecodeBase64Any(input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if string(result) != expected {
|
|
t.Errorf("expected %q, got %q", expected, string(result))
|
|
}
|
|
}
|