1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import test from "ava";
|
7 | import { Barcode } from "..";
|
8 |
|
9 | test("createFromWASMResult", t => {
|
10 | const wasmResult: any = {
|
11 | symbology: Barcode.Symbology.QR,
|
12 | location: [[0, 0], [1, 0], [1, 1], [0, 1]],
|
13 | compositeFlag: Barcode.CompositeFlag.NONE,
|
14 | isGs1DataCarrier: false,
|
15 | encodingArray: []
|
16 | };
|
17 |
|
18 | wasmResult.rawData = new Uint8Array([]);
|
19 | t.deepEqual(Barcode.createFromWASMResult(wasmResult), {
|
20 | ...wasmResult,
|
21 | location: {
|
22 | topLeft: { x: 0, y: 0 },
|
23 | topRight: { x: 1, y: 0 },
|
24 | bottomRight: { x: 1, y: 1 },
|
25 | bottomLeft: { x: 0, y: 1 }
|
26 | },
|
27 | data: ""
|
28 | });
|
29 | wasmResult.rawData = new Uint8Array([97, 98, 99, 100]);
|
30 | t.deepEqual(Barcode.createFromWASMResult(wasmResult), {
|
31 | ...wasmResult,
|
32 | location: {
|
33 | topLeft: { x: 0, y: 0 },
|
34 | topRight: { x: 1, y: 0 },
|
35 | bottomRight: { x: 1, y: 1 },
|
36 | bottomLeft: { x: 0, y: 1 }
|
37 | },
|
38 | data: "abcd"
|
39 | });
|
40 | wasmResult.rawData = new Uint8Array([195, 164, 195, 182, 194, 181, 195, 159]);
|
41 | t.deepEqual(Barcode.createFromWASMResult(wasmResult), {
|
42 | ...wasmResult,
|
43 | location: {
|
44 | topLeft: { x: 0, y: 0 },
|
45 | topRight: { x: 1, y: 0 },
|
46 | bottomRight: { x: 1, y: 1 },
|
47 | bottomLeft: { x: 0, y: 1 }
|
48 | },
|
49 | data: "äöµß"
|
50 | });
|
51 | wasmResult.rawData = new Uint8Array([253, 254, 255]);
|
52 | t.deepEqual(Barcode.createFromWASMResult(wasmResult), {
|
53 | ...wasmResult,
|
54 | location: {
|
55 | topLeft: { x: 0, y: 0 },
|
56 | topRight: { x: 1, y: 0 },
|
57 | bottomRight: { x: 1, y: 1 },
|
58 | bottomLeft: { x: 0, y: 1 }
|
59 | },
|
60 | data: ""
|
61 | });
|
62 | });
|
63 |
|
64 | test("Symbology.toHumanizedName", t => {
|
65 | Object.values(Barcode.Symbology)
|
66 | .filter(s => {
|
67 | return typeof s === "string";
|
68 | })
|
69 | .forEach(symbology => {
|
70 | t.truthy(Barcode.Symbology.toHumanizedName(symbology));
|
71 | t.notDeepEqual(Barcode.Symbology.toHumanizedName(symbology), "Unknown");
|
72 | });
|
73 | t.deepEqual(Barcode.Symbology.toHumanizedName(<Barcode.Symbology>"i_dont_exist"), "Unknown");
|
74 | });
|
75 |
|
76 | test("Symbology.toJSONName", t => {
|
77 | Object.values(Barcode.Symbology)
|
78 | .filter(s => {
|
79 | return typeof s === "string";
|
80 | })
|
81 | .forEach(symbology => {
|
82 | t.truthy(Barcode.Symbology.toJSONName(symbology));
|
83 | t.notDeepEqual(Barcode.Symbology.toJSONName(symbology), "unknown");
|
84 | });
|
85 | t.deepEqual(Barcode.Symbology.toJSONName(<Barcode.Symbology>"i_dont_exist"), "unknown");
|
86 | });
|