fixes shouldUseCTable
depending on the position of FNC1 the results should be different...
This commit is contained in:
parent
f8b9e11d84
commit
3e02de6fc1
|
@ -30,6 +30,10 @@ func shouldUseCTable(nextRunes []rune, curEncoding byte) bool {
|
||||||
}
|
}
|
||||||
for i := 0; i < requiredDigits; i++ {
|
for i := 0; i < requiredDigits; i++ {
|
||||||
if i%2 == 0 && nextRunes[i] == FNC1 {
|
if i%2 == 0 && nextRunes[i] == FNC1 {
|
||||||
|
requiredDigits++
|
||||||
|
if len(nextRunes) < requiredDigits {
|
||||||
|
return false
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if nextRunes[i] < '0' || nextRunes[i] > '9' {
|
if nextRunes[i] < '0' || nextRunes[i] > '9' {
|
||||||
|
|
|
@ -70,3 +70,21 @@ func Test_EncodeCTable(t *testing.T) {
|
||||||
"11101001100"+ // CheckSum == 24
|
"11101001100"+ // CheckSum == 24
|
||||||
"1100011101011") // Stop
|
"1100011101011") // Stop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_shouldUseCTable(t *testing.T) {
|
||||||
|
if !shouldUseCTable([]rune{FNC1, '1', '2'}, startCSymbol) {
|
||||||
|
t.Error("[FNC1]12 failed")
|
||||||
|
}
|
||||||
|
if shouldUseCTable([]rune{FNC1, '1'}, startCSymbol) {
|
||||||
|
t.Error("[FNC1]1 failed")
|
||||||
|
}
|
||||||
|
if shouldUseCTable([]rune{'0', FNC1, '1'}, startCSymbol) {
|
||||||
|
t.Error("0[FNC1]1 failed")
|
||||||
|
}
|
||||||
|
if !shouldUseCTable([]rune{'0', '1', FNC1, '2', '3'}, startBSymbol) {
|
||||||
|
t.Error("01[FNC1]23 failed")
|
||||||
|
}
|
||||||
|
if shouldUseCTable([]rune{'0', '1', FNC1}, startBSymbol) {
|
||||||
|
t.Error("01[FNC1] failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue