barcodes/validation/validate_test.go

78 lines
1.6 KiB
Go
Raw Permalink Normal View History

2023-09-05 12:35:52 +01:00
package validation
import (
"fmt"
"testing"
"git.fjla.uk/fred.boniface/barcodes/generation"
)
const unicodeString string = "Hello, 你好, नमस्ते, こんにちは, 😃🌍🚀🎉~!@#$%^&*()_+-=[]{}|;:'\",.<>?/\\±§©µ¿¡®¬°¹²³½¾¼×÷≤≥∞∑∫√∂∆∏∃∀Ω≈≠¬≡≣∀∂∃Ω℧℁ℝℂℍℤℚ"
const asciiString string = "!7^%&3#(1@!9)6*8_:;4<~2`5-+0|{/.,?]'\"~"
func TestValidation(t *testing.T) {
testCases := []struct {
input generation.Parameters
expected bool
}{
{
input: generation.Parameters{
Format: "aztec",
ECCLevel: 4,
Content: unicodeString,
},
expected: true,
},
{
input: generation.Parameters{
Format: "codabar",
ECCLevel: 4,
Content: "ABCD",
},
expected: false,
},
{
input: generation.Parameters{
Format: "codabar",
ECCLevel: 4,
Content: "2342-943$",
},
expected: true,
},
{
input: generation.Parameters{
Format: "datamatrix",
ECCLevel: 4,
Content: unicodeString,
},
expected: true,
},
{
input: generation.Parameters{
Format: "qr",
ECCLevel: 4,
Content: unicodeString,
},
expected: true,
},
{
input: generation.Parameters{
Format: "code39",
ECCLevel: 4,
Content: asciiString,
},
expected: true,
},
}
for _, testCase := range testCases {
result := Validate(testCase.input)
if result != testCase.expected {
inputStr := fmt.Sprintf("%+v", testCase.input) // Convert struct to string representation
t.Errorf("Input: \n%s\n\nExpected: %t\n\n Got: %t", inputStr, testCase.expected, result)
}
}
}