|
1 | 1 | import { describe, expect, it } from 'vitest' |
| 2 | +import { splitForCode128, genCode128forXprinter } from '../src/utils'; |
2 | 3 |
|
3 | 4 | describe('should', () => { |
4 | 5 | it('exported', () => { |
5 | 6 | expect(1).toEqual(1) |
6 | | - }) |
| 7 | + }); |
| 8 | + |
| 9 | + it('Split string to optimized blocks for CODE128 barcode', () => { |
| 10 | + const inputs: string[] = []; |
| 11 | + const expected: string[][] = []; |
| 12 | + |
| 13 | + inputs.push("12"); |
| 14 | + expected.push(["12"]); |
| 15 | + |
| 16 | + inputs.push("123"); |
| 17 | + expected.push(["123"]); |
| 18 | + |
| 19 | + inputs.push("1234"); |
| 20 | + expected.push(["1234"]); |
| 21 | + |
| 22 | + inputs.push("12345"); |
| 23 | + expected.push(["1234", '5']); |
| 24 | + |
| 25 | + inputs.push("123456789"); |
| 26 | + expected.push(["12345678","9"]); |
| 27 | + |
| 28 | + inputs.push("123A4567C"); |
| 29 | + expected.push(["123A4567C"]); |
| 30 | + |
| 31 | + inputs.push("1234A4567C"); |
| 32 | + expected.push(["1234","A4567C"]); |
| 33 | + |
| 34 | + inputs.push("AAA1234"); |
| 35 | + expected.push(["AAA","1234"]); |
| 36 | + |
| 37 | + inputs.push("AAA12345"); |
| 38 | + expected.push(["AAA1","2345"]); |
| 39 | + |
| 40 | + inputs.push("4321AAA1234"); |
| 41 | + expected.push(["4321","AAA","1234"]); |
| 42 | + |
| 43 | + inputs.push("AAA123456BBB"); |
| 44 | + expected.push(["AAA","123456","BBB"]); |
| 45 | + |
| 46 | + inputs.push("12345ABC2345678BCD3456789CDE98765"); |
| 47 | + expected.push(["1234","5ABC","234567","8BCD","345678","9CDE9","8765"]); |
| 48 | + |
| 49 | + inputs.forEach((input,index) => { |
| 50 | + expect(splitForCode128(input)).toEqual(expected[index]); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + it('generate CODE128 barcode printing control code for Xprinter', () => { |
| 55 | + const inputs: string[] = []; |
| 56 | + const expected: string[] = []; |
| 57 | + |
| 58 | + inputs.push("AB"); |
| 59 | + expected.push("\x04{BAB"); |
| 60 | + |
| 61 | + inputs.push("12"); |
| 62 | + expected.push("\x03{C\x0c"); |
| 63 | + |
| 64 | + inputs.push("123456789"); |
| 65 | + expected.push("\x09{C\x0c\x22\x38\x4e{B9"); |
| 66 | + |
| 67 | + inputs.push("1234ABC"); |
| 68 | + expected.push("\x09{C\x0c\x22{BABC"); |
| 69 | + |
| 70 | + inputs.push("ABC1234"); |
| 71 | + expected.push("\x09{BABC{C\x0c\x22"); |
| 72 | + |
| 73 | + inputs.push("AAA123456BBB"); |
| 74 | + expected.push("\x0f{BAAA{C\x0c\x22\x38{BBBB"); |
| 75 | + |
| 76 | + inputs.push("12345ABC2345678BCD3456789CDE98765"); |
| 77 | + expected.push("\x25{C\x0c\x22{B5ABC{C\x17\x2d\x43{B8BCD{C\x22\x38\x4e{B9CDE9{C\x57\x41"); |
| 78 | + |
| 79 | + inputs.forEach((input,index) => { |
| 80 | + expect(genCode128forXprinter(input)).toEqual(expected[index]); |
| 81 | + }); |
| 82 | + |
| 83 | + }); |
7 | 84 | }) |
| 85 | + |
0 commit comments