-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathean_test.ts
More file actions
54 lines (50 loc) · 1.67 KB
/
ean_test.ts
File metadata and controls
54 lines (50 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Test our EAN methods
//
import { assertEquals, assertNotEquals } from "@std/assert";
import { normalizeEAN, validateEAN } from "./ean.ts";
Deno.test("Deno test valid ean", () => {
const varified_ids: string[] = [
"9780201544282",
];
for (const id of varified_ids) {
// Normalize
const expected = id;
const normalized = normalizeEAN(id);
assertEquals(
normalized,
expected,
`expected normalizeEAN(${id}) to be "${expected}", got "${normalized}"`,
);
//console.log(`Normalized EAN: ${normalized}`);
// Validate
assertEquals(validateEAN(id), true);
// NOTE: To verify the EAN you need an account on ean-search.org or other database.
// You're best bet would be to treat the EAN as an ISBN and verify against a public resource
// like Open Library or OCLC if you have access there.
}
const invalid_ids: string[] = [
"xx000222jwwheeot",
];
for (const id of invalid_ids) {
// Normalize
const expected = id.replaceAll(/[a-z]/g, "");
const normalized = normalizeEAN(id);
assertEquals(
normalized,
expected,
`expected normalizeEAN(${id}) to be "${expected}", got "${normalized}"`,
);
assertNotEquals(
normalized,
id,
`expected normalizeEAN(${id}) not to be equal to id "${id}", got "${normalized}"`,
);
//console.log(`Normalized EAN: ${normalized}`);
// Validate
assertEquals(validateEAN(id), false);
// NOTE: To verify the EAN you need an account on ean-search.org or other database.
// You're best bet would be to treat the EAN as an ISBN and verify against a public resource
// like Open Library or OCLC if you have access there.
}
});