@keymanapp/common-types 17.0.85-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/build/src/consts/virtual-key-constants.d.ts +131 -0
  2. package/build/src/consts/virtual-key-constants.d.ts.map +1 -0
  3. package/build/src/consts/virtual-key-constants.js +245 -0
  4. package/build/src/consts/virtual-key-constants.js.map +1 -0
  5. package/build/src/import/techpreview/cldr_info.json +5 -0
  6. package/build/src/import/techpreview/keys-Latn-implied.xml +80 -0
  7. package/build/src/import/techpreview/keys-Zyyy-currency.xml +22 -0
  8. package/build/src/import/techpreview/keys-Zyyy-punctuation.xml +46 -0
  9. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts +7 -0
  10. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.d.ts.map +1 -0
  11. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js +74 -0
  12. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js.map +1 -0
  13. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts +24 -0
  14. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.d.ts.map +1 -0
  15. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js +75 -0
  16. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js.map +1 -0
  17. package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts +76 -0
  18. package/build/src/keyman-touch-layout/keyman-touch-layout-file.d.ts.map +1 -0
  19. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js +26 -0
  20. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js.map +1 -0
  21. package/build/src/keyman-touch-layout.clean.spec.json +170 -0
  22. package/build/src/kmx/element-string.d.ts +19 -0
  23. package/build/src/kmx/element-string.d.ts.map +1 -0
  24. package/build/src/kmx/element-string.js +72 -0
  25. package/build/src/kmx/element-string.js.map +1 -0
  26. package/build/src/kmx/kmx-builder.d.ts +77 -0
  27. package/build/src/kmx/kmx-builder.d.ts.map +1 -0
  28. package/build/src/kmx/kmx-builder.js +193 -0
  29. package/build/src/kmx/kmx-builder.js.map +1 -0
  30. package/build/src/kmx/kmx-plus-builder/build-disp.d.ts +18 -0
  31. package/build/src/kmx/kmx-plus-builder/build-disp.d.ts.map +1 -0
  32. package/build/src/kmx/kmx-plus-builder/build-disp.js +25 -0
  33. package/build/src/kmx/kmx-plus-builder/build-disp.js.map +1 -0
  34. package/build/src/kmx/kmx-plus-builder/build-elem.d.ts +26 -0
  35. package/build/src/kmx/kmx-plus-builder/build-elem.d.ts.map +1 -0
  36. package/build/src/kmx/kmx-plus-builder/build-elem.js +78 -0
  37. package/build/src/kmx/kmx-plus-builder/build-elem.js.map +1 -0
  38. package/build/src/kmx/kmx-plus-builder/build-keys.d.ts +60 -0
  39. package/build/src/kmx/kmx-plus-builder/build-keys.d.ts.map +1 -0
  40. package/build/src/kmx/kmx-plus-builder/build-keys.js +107 -0
  41. package/build/src/kmx/kmx-plus-builder/build-keys.js.map +1 -0
  42. package/build/src/kmx/kmx-plus-builder/build-layr.d.ts +54 -0
  43. package/build/src/kmx/kmx-plus-builder/build-layr.d.ts.map +1 -0
  44. package/build/src/kmx/kmx-plus-builder/build-layr.js +99 -0
  45. package/build/src/kmx/kmx-plus-builder/build-layr.js.map +1 -0
  46. package/build/src/kmx/kmx-plus-builder/build-list.d.ts +34 -0
  47. package/build/src/kmx/kmx-plus-builder/build-list.d.ts.map +1 -0
  48. package/build/src/kmx/kmx-plus-builder/build-list.js +62 -0
  49. package/build/src/kmx/kmx-plus-builder/build-list.js.map +1 -0
  50. package/build/src/kmx/kmx-plus-builder/build-loca.d.ts +12 -0
  51. package/build/src/kmx/kmx-plus-builder/build-loca.d.ts.map +1 -0
  52. package/build/src/kmx/kmx-plus-builder/build-loca.js +20 -0
  53. package/build/src/kmx/kmx-plus-builder/build-loca.js.map +1 -0
  54. package/build/src/kmx/kmx-plus-builder/build-meta.d.ts +17 -0
  55. package/build/src/kmx/kmx-plus-builder/build-meta.d.ts.map +1 -0
  56. package/build/src/kmx/kmx-plus-builder/build-meta.js +21 -0
  57. package/build/src/kmx/kmx-plus-builder/build-meta.js.map +1 -0
  58. package/build/src/kmx/kmx-plus-builder/build-name.d.ts +12 -0
  59. package/build/src/kmx/kmx-plus-builder/build-name.d.ts.map +1 -0
  60. package/build/src/kmx/kmx-plus-builder/build-name.js +23 -0
  61. package/build/src/kmx/kmx-plus-builder/build-name.js.map +1 -0
  62. package/build/src/kmx/kmx-plus-builder/build-ordr.d.ts +18 -0
  63. package/build/src/kmx/kmx-plus-builder/build-ordr.d.ts.map +1 -0
  64. package/build/src/kmx/kmx-plus-builder/build-ordr.js +27 -0
  65. package/build/src/kmx/kmx-plus-builder/build-ordr.js.map +1 -0
  66. package/build/src/kmx/kmx-plus-builder/build-sect.d.ts +16 -0
  67. package/build/src/kmx/kmx-plus-builder/build-sect.d.ts.map +1 -0
  68. package/build/src/kmx/kmx-plus-builder/build-sect.js +14 -0
  69. package/build/src/kmx/kmx-plus-builder/build-sect.js.map +1 -0
  70. package/build/src/kmx/kmx-plus-builder/build-strs.d.ts +18 -0
  71. package/build/src/kmx/kmx-plus-builder/build-strs.d.ts.map +1 -0
  72. package/build/src/kmx/kmx-plus-builder/build-strs.js +34 -0
  73. package/build/src/kmx/kmx-plus-builder/build-strs.js.map +1 -0
  74. package/build/src/kmx/kmx-plus-builder/build-tran.d.ts +20 -0
  75. package/build/src/kmx/kmx-plus-builder/build-tran.d.ts.map +1 -0
  76. package/build/src/kmx/kmx-plus-builder/build-tran.js +30 -0
  77. package/build/src/kmx/kmx-plus-builder/build-tran.js.map +1 -0
  78. package/build/src/kmx/kmx-plus-builder/build-vkey.d.ts +16 -0
  79. package/build/src/kmx/kmx-plus-builder/build-vkey.d.ts.map +1 -0
  80. package/build/src/kmx/kmx-plus-builder/build-vkey.js +23 -0
  81. package/build/src/kmx/kmx-plus-builder/build-vkey.js.map +1 -0
  82. package/build/src/kmx/kmx-plus-builder/builder-section.d.ts +6 -0
  83. package/build/src/kmx/kmx-plus-builder/builder-section.d.ts.map +1 -0
  84. package/build/src/kmx/kmx-plus-builder/builder-section.js +3 -0
  85. package/build/src/kmx/kmx-plus-builder/builder-section.js.map +1 -0
  86. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts +47 -0
  87. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.d.ts.map +1 -0
  88. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js +143 -0
  89. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js.map +1 -0
  90. package/build/src/kmx/kmx-plus.d.ts +259 -0
  91. package/build/src/kmx/kmx-plus.d.ts.map +1 -0
  92. package/build/src/kmx/kmx-plus.js +594 -0
  93. package/build/src/kmx/kmx-plus.js.map +1 -0
  94. package/build/src/kmx/kmx.d.ts +166 -0
  95. package/build/src/kmx/kmx.d.ts.map +1 -0
  96. package/build/src/kmx/kmx.js +271 -0
  97. package/build/src/kmx/kmx.js.map +1 -0
  98. package/build/src/kmx/string-list.d.ts +29 -0
  99. package/build/src/kmx/string-list.d.ts.map +1 -0
  100. package/build/src/kmx/string-list.js +75 -0
  101. package/build/src/kmx/string-list.js.map +1 -0
  102. package/build/src/kpj/keyman-developer-project.d.ts +58 -0
  103. package/build/src/kpj/keyman-developer-project.d.ts.map +1 -0
  104. package/build/src/kpj/keyman-developer-project.js +141 -0
  105. package/build/src/kpj/keyman-developer-project.js.map +1 -0
  106. package/build/src/kpj/kpj-file-reader.d.ts +17 -0
  107. package/build/src/kpj/kpj-file-reader.d.ts.map +1 -0
  108. package/build/src/kpj/kpj-file-reader.js +92 -0
  109. package/build/src/kpj/kpj-file-reader.js.map +1 -0
  110. package/build/src/kpj/kpj-file.d.ts +39 -0
  111. package/build/src/kpj/kpj-file.d.ts.map +1 -0
  112. package/build/src/kpj/kpj-file.js +11 -0
  113. package/build/src/kpj/kpj-file.js.map +1 -0
  114. package/build/src/kpj.schema.json +127 -0
  115. package/build/src/kvk/kvk-file-reader.d.ts +5 -0
  116. package/build/src/kvk/kvk-file-reader.d.ts.map +1 -0
  117. package/build/src/kvk/kvk-file-reader.js +35 -0
  118. package/build/src/kvk/kvk-file-reader.js.map +1 -0
  119. package/build/src/kvk/kvk-file-writer.d.ts +20 -0
  120. package/build/src/kvk/kvk-file-writer.d.ts.map +1 -0
  121. package/build/src/kvk/kvk-file-writer.js +67 -0
  122. package/build/src/kvk/kvk-file-writer.js.map +1 -0
  123. package/build/src/kvk/kvk-file.d.ts +64 -0
  124. package/build/src/kvk/kvk-file.d.ts.map +1 -0
  125. package/build/src/kvk/kvk-file.js +63 -0
  126. package/build/src/kvk/kvk-file.js.map +1 -0
  127. package/build/src/kvk/kvks-file-reader.d.ts +30 -0
  128. package/build/src/kvk/kvks-file-reader.d.ts.map +1 -0
  129. package/build/src/kvk/kvks-file-reader.js +154 -0
  130. package/build/src/kvk/kvks-file-reader.js.map +1 -0
  131. package/build/src/kvk/kvks-file-writer.d.ts +6 -0
  132. package/build/src/kvk/kvks-file-writer.d.ts.map +1 -0
  133. package/build/src/kvk/kvks-file-writer.js +99 -0
  134. package/build/src/kvk/kvks-file-writer.js.map +1 -0
  135. package/build/src/kvk/kvks-file.d.ts +44 -0
  136. package/build/src/kvk/kvks-file.d.ts.map +1 -0
  137. package/build/src/kvk/kvks-file.js +10 -0
  138. package/build/src/kvk/kvks-file.js.map +1 -0
  139. package/build/src/kvk/visual-keyboard.d.ts +35 -0
  140. package/build/src/kvk/visual-keyboard.d.ts.map +1 -0
  141. package/build/src/kvk/visual-keyboard.js +61 -0
  142. package/build/src/kvk/visual-keyboard.js.map +1 -0
  143. package/build/src/kvks.schema.json +182 -0
  144. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts +56 -0
  145. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.d.ts.map +1 -0
  146. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js +20 -0
  147. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js.map +1 -0
  148. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts +91 -0
  149. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.d.ts.map +1 -0
  150. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js +370 -0
  151. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js.map +1 -0
  152. package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts +143 -0
  153. package/build/src/ldml-keyboard/ldml-keyboard-xml.d.ts.map +1 -0
  154. package/build/src/ldml-keyboard/ldml-keyboard-xml.js +34 -0
  155. package/build/src/ldml-keyboard/ldml-keyboard-xml.js.map +1 -0
  156. package/build/src/ldml-keyboard.schema.json +634 -0
  157. package/build/src/ldml-keyboardtest.schema.json +221 -0
  158. package/build/src/main.d.ts +21 -0
  159. package/build/src/main.d.ts.map +1 -0
  160. package/build/src/main.js +20 -0
  161. package/build/src/main.js.map +1 -0
  162. package/build/src/util/common-events.d.ts +49 -0
  163. package/build/src/util/common-events.d.ts.map +1 -0
  164. package/build/src/util/common-events.js +29 -0
  165. package/build/src/util/common-events.js.map +1 -0
  166. package/build/src/util/compiler-interfaces.d.ts +51 -0
  167. package/build/src/util/compiler-interfaces.d.ts.map +1 -0
  168. package/build/src/util/compiler-interfaces.js +33 -0
  169. package/build/src/util/compiler-interfaces.js.map +1 -0
  170. package/build/src/util/util.d.ts +17 -0
  171. package/build/src/util/util.d.ts.map +1 -0
  172. package/build/src/util/util.js +67 -0
  173. package/build/src/util/util.js.map +1 -0
  174. package/build/tsconfig.tsbuildinfo +1 -0
  175. package/build.sh +86 -0
  176. package/package.json +58 -0
  177. package/src/consts/virtual-key-constants.ts +257 -0
  178. package/src/keyman-touch-layout/keyman-touch-layout-file-reader.ts +81 -0
  179. package/src/keyman-touch-layout/keyman-touch-layout-file-writer.ts +84 -0
  180. package/src/keyman-touch-layout/keyman-touch-layout-file.ts +87 -0
  181. package/src/kmx/element-string.ts +79 -0
  182. package/src/kmx/kmx-builder.ts +287 -0
  183. package/src/kmx/kmx-plus-builder/build-disp.ts +46 -0
  184. package/src/kmx/kmx-plus-builder/build-elem.ts +103 -0
  185. package/src/kmx/kmx-plus-builder/build-keys.ts +175 -0
  186. package/src/kmx/kmx-plus-builder/build-layr.ts +154 -0
  187. package/src/kmx/kmx-plus-builder/build-list.ts +95 -0
  188. package/src/kmx/kmx-plus-builder/build-loca.ts +34 -0
  189. package/src/kmx/kmx-plus-builder/build-meta.ts +37 -0
  190. package/src/kmx/kmx-plus-builder/build-name.ts +37 -0
  191. package/src/kmx/kmx-plus-builder/build-ordr.ts +45 -0
  192. package/src/kmx/kmx-plus-builder/build-sect.ts +31 -0
  193. package/src/kmx/kmx-plus-builder/build-strs.ts +58 -0
  194. package/src/kmx/kmx-plus-builder/build-tran.ts +50 -0
  195. package/src/kmx/kmx-plus-builder/build-vkey.ts +43 -0
  196. package/src/kmx/kmx-plus-builder/builder-section.ts +6 -0
  197. package/src/kmx/kmx-plus-builder/kmx-plus-builder.ts +190 -0
  198. package/src/kmx/kmx-plus.ts +692 -0
  199. package/src/kmx/kmx.ts +360 -0
  200. package/src/kmx/string-list.ts +74 -0
  201. package/src/kpj/keyman-developer-project.ts +155 -0
  202. package/src/kpj/kpj-file-reader.ts +103 -0
  203. package/src/kpj/kpj-file.ts +52 -0
  204. package/src/kvk/kvk-file-reader.ts +34 -0
  205. package/src/kvk/kvk-file-writer.ts +72 -0
  206. package/src/kvk/kvk-file.ts +122 -0
  207. package/src/kvk/kvks-file-reader.ts +164 -0
  208. package/src/kvk/kvks-file-writer.ts +113 -0
  209. package/src/kvk/kvks-file.ts +53 -0
  210. package/src/kvk/visual-keyboard.ts +80 -0
  211. package/src/ldml-keyboard/ldml-keyboard-testdata-xml.ts +74 -0
  212. package/src/ldml-keyboard/ldml-keyboard-xml-reader.ts +387 -0
  213. package/src/ldml-keyboard/ldml-keyboard-xml.ts +177 -0
  214. package/src/main.ts +27 -0
  215. package/src/restructure.d.ts +2 -0
  216. package/src/util/common-events.ts +50 -0
  217. package/src/util/compiler-interfaces.ts +54 -0
  218. package/src/util/util.ts +68 -0
  219. package/test/fixtures/import-minimal.xml +8 -0
  220. package/test/fixtures/import-minimal1.xml +11 -0
  221. package/test/fixtures/import-minimal2.xml +11 -0
  222. package/test/fixtures/import-symbols.xml +13 -0
  223. package/test/fixtures/invalid-conforms-to.xml +19 -0
  224. package/test/fixtures/invalid-import-base.xml +16 -0
  225. package/test/fixtures/invalid-import-path.xml +16 -0
  226. package/test/fixtures/invalid-import-readfail.xml +16 -0
  227. package/test/fixtures/invalid-import-wrongroot.xml +16 -0
  228. package/test/fixtures/invalid-structure-per-dtd.xml +8 -0
  229. package/test/fixtures/keyman-touch-layout/khmer_angkor.keyman-touch-layout +1950 -0
  230. package/test/fixtures/keyman-touch-layout/legacy.keyman-touch-layout +36 -0
  231. package/test/fixtures/kpj/khmer_angkor.kpj +187 -0
  232. package/test/fixtures/kvk/khmer_angkor.kvk +0 -0
  233. package/test/fixtures/kvk/khmer_angkor.kvks +206 -0
  234. package/test/fixtures/test-fr.xml +22 -0
  235. package/test/helpers/index.ts +39 -0
  236. package/test/helpers/reader-callback-test.ts +199 -0
  237. package/test/keyman-touch-layout/test-keyman-touch-layout-file-reader.ts +71 -0
  238. package/test/keyman-touch-layout/test-keyman-touch-layout-round-trip.ts +35 -0
  239. package/test/kpj/test-kpj-file-reader.ts +123 -0
  240. package/test/kvk/test-kvk-file.ts +15 -0
  241. package/test/kvk/test-kvk-round-trip.ts +87 -0
  242. package/test/kvk/test-kvk-utils.ts +24 -0
  243. package/test/kvk/test-kvks-file.ts +45 -0
  244. package/test/ldml-keyboard/test-ldml-keyboard-testdata-reader.ts +51 -0
  245. package/test/ldml-keyboard/test-ldml-keyboard-xml-reader.ts +131 -0
  246. package/test/tsconfig.json +21 -0
  247. package/test/util/test-unescape.ts +38 -0
  248. package/tsconfig.json +17 -0
@@ -0,0 +1,199 @@
1
+ import 'mocha';
2
+ import {assert} from 'chai';
3
+ import {loadLdmlKeyboardSchema, loadFile, makePathToFixture, loadLdmlKeyboardTestDataSchema} from '../helpers/index.js';
4
+ import LDMLKeyboardXMLSourceFileReader from '../../src/ldml-keyboard/ldml-keyboard-xml-reader.js';
5
+ import { CompilerCallbacks, CompilerEvent } from '../../src/util/compiler-interfaces.js';
6
+ import { LDMLKeyboardXMLSourceFile } from '../../src/ldml-keyboard/ldml-keyboard-xml.js';
7
+ import { LDMLKeyboardTestDataXMLSourceFile } from '../ldml-keyboard/ldml-keyboard-testdata-xml.js';
8
+
9
+ // This is related to developer/src/kmc-keyboard/test/helpers/index.ts but has a slightly different API surface
10
+ // as this runs at a lower level than the compiler.
11
+
12
+ /**
13
+ * A CompilerCallbacks implementation for testing
14
+ */
15
+ class TestCompilerCallbacks implements CompilerCallbacks {
16
+ loadKpjJsonSchema(): Buffer {
17
+ throw new Error('loadKpjJsonSchema not implemented.'); // not needed for this test
18
+ }
19
+ loadLdmlKeyboardTestSchema(): Buffer {
20
+ return loadLdmlKeyboardTestDataSchema();
21
+ }
22
+ loadLdmlKeyboardSchema(): Buffer {
23
+ return loadLdmlKeyboardSchema();
24
+ }
25
+ loadKvksJsonSchema(): Buffer {
26
+ throw new Error('loadKvksJsonSchema not implemented.');
27
+ }
28
+ clear() {
29
+ this.messages = [];
30
+ }
31
+ messages: CompilerEvent[] = [];
32
+ loadFile(baseFilename: string, filename: string | URL): Buffer {
33
+ try {
34
+ return loadFile(baseFilename, filename);
35
+ } catch(e) {
36
+ if (e.code === 'ENOENT') {
37
+ return null;
38
+ } else {
39
+ throw e;
40
+ }
41
+ }
42
+ }
43
+ reportMessage(event: CompilerEvent): void {
44
+ // console.log(event.message);
45
+ this.messages.push(event);
46
+ }
47
+ }
48
+
49
+ export interface CompilationCase {
50
+ /**
51
+ * If true, loading (validation) should fail
52
+ */
53
+ loadfail?: boolean;
54
+ /**
55
+ * path to xml, such as 'sections/layr/invalid-case.xml'
56
+ */
57
+ subpath: string;
58
+ /**
59
+ * expected error messages. If falsy, expected to succeed. All must be present to pass.
60
+ */
61
+ errors?: CompilerEvent[];
62
+ /**
63
+ * expected warning messages. All must be present to pass.
64
+ */
65
+ warnings?: CompilerEvent[];
66
+ /**
67
+ * optional callback with the section
68
+ */
69
+ callback?: (data: Buffer, source: LDMLKeyboardXMLSourceFile, subpath: string, callbacks: TestCompilerCallbacks ) => void;
70
+ /**
71
+ * if present, expect compiler to throw (use .* to match all)
72
+ */
73
+ throws?: RegExp;
74
+ }
75
+
76
+
77
+ export interface TestDataCase {
78
+ /**
79
+ * If true, loading (validation) should fail
80
+ */
81
+ loadfail?: boolean;
82
+ /**
83
+ * path to xml, such as 'sections/layr/invalid-case.xml'
84
+ */
85
+ subpath: string;
86
+ /**
87
+ * expected error messages. If falsy, expected to succeed. All must be present to pass.
88
+ */
89
+ errors?: CompilerEvent[];
90
+ /**
91
+ * expected warning messages. All must be present to pass.
92
+ */
93
+ warnings?: CompilerEvent[];
94
+ /**
95
+ * optional callback with the section
96
+ */
97
+ callback?: (data: Buffer, source: LDMLKeyboardTestDataXMLSourceFile, subpath: string, callbacks: TestCompilerCallbacks ) => void;
98
+ /**
99
+ * if present, expect compiler to throw (use .* to match all)
100
+ */
101
+ throws?: RegExp;
102
+ }
103
+
104
+ /**
105
+ * Run a bunch of cases
106
+ * @param cases cases to run
107
+ * @param compiler argument to loadSectionFixture()
108
+ * @param callbacks argument to loadSectionFixture()
109
+ */
110
+ export function testReaderCases(cases : CompilationCase[]) {
111
+ // we need our own callbacks rather than using the global so messages don't get mixed
112
+ const callbacks = new TestCompilerCallbacks();
113
+ const reader = new LDMLKeyboardXMLSourceFileReader(callbacks);
114
+ for (let testcase of cases) {
115
+ const expectFailure = testcase.throws || !!(testcase.errors); // if true, we expect this to fail
116
+ const testHeading = expectFailure ? `should fail to load: ${testcase.subpath}`:
117
+ `should load: ${testcase.subpath}`;
118
+ it(testHeading, function () {
119
+ callbacks.clear();
120
+
121
+ const data = loadFile(testcase.subpath, makePathToFixture(testcase.subpath));
122
+ assert.ok(data, `reading ${testcase.subpath}`);
123
+ const source = reader.load(data);
124
+ if (!testcase.loadfail) {
125
+ assert.ok(source, `loading ${testcase.subpath}`);
126
+ } else {
127
+ assert.notOk(source, `loading ${testcase.subpath} (expected failure)`);
128
+ }
129
+ // special case for an expected exception
130
+ if (testcase.throws) {
131
+ assert.throws(() => reader.validate(source, loadLdmlKeyboardSchema()), testcase.throws);
132
+ } else {
133
+ assert.doesNotThrow(() => reader.validate(source, loadLdmlKeyboardSchema()), `validating ${testcase.subpath}`);
134
+ // if we expected errors or warnings, show them
135
+ if (testcase.errors) {
136
+ assert.includeDeepMembers(callbacks.messages, testcase.errors, 'expected errors to be included');
137
+ }
138
+ if (testcase.warnings) {
139
+ assert.includeDeepMembers(callbacks.messages, testcase.warnings, 'expected warnings to be included');
140
+ } else if (!expectFailure) {
141
+ // no warnings, so expect zero messages
142
+ assert.strictEqual(callbacks.messages.length, 0, 'expected zero messages');
143
+ }
144
+
145
+ // run the user-supplied callback if any
146
+ if (testcase.callback) {
147
+ testcase.callback(data, source, testcase.subpath, callbacks);
148
+ }
149
+ }
150
+ });
151
+ }
152
+ }
153
+
154
+
155
+ /**
156
+ * Run a bunch of cases
157
+ * @param cases cases to run
158
+ * @param compiler argument to loadSectionFixture()
159
+ * @param callbacks argument to loadSectionFixture()
160
+ */
161
+ export function testTestdataReaderCases(cases : TestDataCase[]) {
162
+ // we need our own callbacks rather than using the global so messages don't get mixed
163
+ const callbacks = new TestCompilerCallbacks();
164
+ const reader = new LDMLKeyboardXMLSourceFileReader(callbacks);
165
+ for (let testcase of cases) {
166
+ const expectFailure = testcase.throws || !!(testcase.errors); // if true, we expect this to fail
167
+ const testHeading = expectFailure ? `should fail to load: ${testcase.subpath}`:
168
+ `should load: ${testcase.subpath}`;
169
+ it(testHeading, function () {
170
+ callbacks.clear();
171
+
172
+ const data = loadFile(testcase.subpath, makePathToFixture(testcase.subpath));
173
+ assert.ok(data, `reading ${testcase.subpath}`);
174
+ const source = reader.loadTestData(data);
175
+ if (!testcase.loadfail) {
176
+ assert.ok(source, `loading ${testcase.subpath}`);
177
+ } else {
178
+ assert.notOk(source, `loading ${testcase.subpath} (expected failure)`);
179
+ }
180
+ // special case for an expected exception
181
+ // TODO-LDML: no validation for now.
182
+ // if we expected errors or warnings, show them
183
+ if (testcase.errors) {
184
+ assert.includeDeepMembers(callbacks.messages, testcase.errors, 'expected errors to be included');
185
+ }
186
+ if (testcase.warnings) {
187
+ assert.includeDeepMembers(callbacks.messages, testcase.warnings, 'expected warnings to be included');
188
+ } else if (!expectFailure) {
189
+ // no warnings, so expect zero messages
190
+ assert.strictEqual(callbacks.messages.length, 0, 'expected zero messages but got ' +callbacks.messages.map(e => e.message).join(' ') );
191
+ }
192
+
193
+ // run the user-supplied callback if any
194
+ if (testcase.callback) {
195
+ testcase.callback(data, source, testcase.subpath, callbacks);
196
+ }
197
+ });
198
+ }
199
+ }
@@ -0,0 +1,71 @@
1
+ import * as fs from 'fs';
2
+ import 'mocha';
3
+ import { assert } from 'chai';
4
+ import { loadKeymanTouchLayoutCleanJsonSchema, makePathToFixture } from '../helpers/index.js';
5
+ import { TouchLayoutFileReader } from "../../src/keyman-touch-layout/keyman-touch-layout-file-reader.js";
6
+
7
+ describe('TouchLayoutFileReader', function () {
8
+ it('should read a valid file', function() {
9
+ const path = makePathToFixture('keyman-touch-layout', 'khmer_angkor.keyman-touch-layout');
10
+ const schema = loadKeymanTouchLayoutCleanJsonSchema();
11
+ const input = fs.readFileSync(path);
12
+ const reader = new TouchLayoutFileReader();
13
+ const layout = reader.read(input);
14
+ reader.validate(layout, schema);
15
+
16
+ // We don't really need to validate the JSON parser. We'll do a handful of
17
+ // tests for object integrity and a couple of object members inside the file
18
+ // just as a sanity check
19
+ assert.hasAllKeys(layout, ['tablet', 'phone']);
20
+ assert.hasAllKeys(layout.tablet, ['layer', 'displayUnderlying', 'font', 'fontsize']);
21
+ assert.isFalse(layout.tablet.displayUnderlying);
22
+ assert.strictEqual(layout.tablet.font, 'Khmer Busra Kbd');
23
+ assert.strictEqual(layout.tablet.fontsize, '0.8em');
24
+ assert.isArray(layout.tablet.layer);
25
+ assert.strictEqual(layout.tablet.layer.length, 3);
26
+ assert.strictEqual(layout.tablet.layer[0].id, 'default');
27
+ assert.isArray(layout.tablet.layer[0].row);
28
+ assert.isArray(layout.tablet.layer[0].row);
29
+ assert.strictEqual(layout.tablet.layer[0].row.length, 5);
30
+ assert.strictEqual(layout.tablet.layer[0].row[0].id, 1);
31
+ assert.isArray(layout.tablet.layer[0].row[0].key);
32
+ assert.strictEqual(layout.tablet.layer[0].row[0].key.length, 13);
33
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].id, "K_1");
34
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].text, "១");
35
+ });
36
+
37
+ it('should fixup numeric types in a valid legacy file', function() {
38
+ const path = makePathToFixture('keyman-touch-layout', 'legacy.keyman-touch-layout');
39
+ const schema = loadKeymanTouchLayoutCleanJsonSchema();
40
+ const input = fs.readFileSync(path);
41
+ const reader = new TouchLayoutFileReader();
42
+ const layout = reader.read(input);
43
+ reader.validate(layout, schema);
44
+
45
+ // row.id can be a string in legacy files
46
+ assert.strictEqual(layout.tablet.layer[0].row[0].id, 1);
47
+
48
+ // key pad, width and sp can be a string in legacy files
49
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].pad, 25);
50
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].width, 100);
51
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].sp, 1);
52
+
53
+ // sk pad, width and sp can be a string in legacy files
54
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].sk[0].pad, 10);
55
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].sk[0].width, 25);
56
+ assert.strictEqual(layout.tablet.layer[0].row[0].key[0].sk[0].sp, 8);
57
+ });
58
+
59
+ it('should fixup remove empty arrays in a valid legacy file', function() {
60
+ const path = makePathToFixture('keyman-touch-layout', 'legacy.keyman-touch-layout');
61
+ const schema = loadKeymanTouchLayoutCleanJsonSchema();
62
+ const input = fs.readFileSync(path);
63
+ const reader = new TouchLayoutFileReader();
64
+ const layout = reader.read(input);
65
+ reader.validate(layout, schema);
66
+
67
+ // sk was defined as [] in legacy.keyman-touch-layout but we want to treat
68
+ // it as not present
69
+ assert.isUndefined(layout.tablet.layer[0].row[0].key[1].sk);
70
+ });
71
+ });
@@ -0,0 +1,35 @@
1
+ import * as fs from 'fs';
2
+ import 'mocha';
3
+ import { assert } from 'chai';
4
+ import { makePathToFixture } from '../helpers/index.js';
5
+ import { TouchLayoutFileReader } from "../../src/keyman-touch-layout/keyman-touch-layout-file-reader.js";
6
+ import { TouchLayoutFileWriter } from "../../src/keyman-touch-layout/keyman-touch-layout-file-writer.js";
7
+
8
+ describe('TouchLayoutFile', function () {
9
+ it('should round-trip from TouchLayoutFileReader to TouchLayoutFileWriter', function() {
10
+ const path = makePathToFixture('keyman-touch-layout', 'khmer_angkor.keyman-touch-layout');
11
+ const input = fs.readFileSync(path);
12
+ const reader = new TouchLayoutFileReader();
13
+ const layout = reader.read(input);
14
+ const writer = new TouchLayoutFileWriter();
15
+
16
+ // We don't want to assert equality on formatting differences, or on the
17
+ // fixups that we do on input files (empty arrays, stringified numbers), so
18
+ // we'll re-read the output and compare it
19
+ let output = writer.write(layout);
20
+ let newLayout = reader.read(output);
21
+ assert.deepEqual(layout, newLayout);
22
+
23
+ // And do the same without formatted output
24
+ output = writer.write(layout);
25
+ newLayout = reader.read(output);
26
+ assert.deepEqual(layout, newLayout);
27
+
28
+ // And do the same without any options
29
+ let output2 = writer.write(layout);
30
+ assert.deepEqual(output, output2);
31
+
32
+ newLayout = reader.read(output2);
33
+ assert.deepEqual(layout, newLayout);
34
+ });
35
+ });
@@ -0,0 +1,123 @@
1
+ import * as fs from 'fs';
2
+ import 'mocha';
3
+ import {assert} from 'chai';
4
+ import { loadKpjJsonSchema, makePathToFixture } from '../helpers/index.js';
5
+ import { KPJFileReader } from "../../src/kpj/kpj-file-reader.js";
6
+ import { KeymanDeveloperProjectFile10, KeymanDeveloperProjectType } from '../../src/kpj/keyman-developer-project.js';
7
+
8
+ describe('kpj-file-reader', function () {
9
+ it('kpj-file-reader should read a valid file', function() {
10
+ const kpjPath = 'khmer_angkor.kpj';
11
+ const path = makePathToFixture('kpj', kpjPath);
12
+ const input = fs.readFileSync(path);
13
+ const reader = new KPJFileReader();
14
+ const kpj = reader.read(input);
15
+ console.dir(kpj);
16
+ assert.doesNotThrow(() => {
17
+ reader.validate(kpj, loadKpjJsonSchema());
18
+ });
19
+ assert.equal(kpj.KeymanDeveloperProject.Options.BuildPath, '$PROJECTPATH\\build');
20
+ assert.equal(kpj.KeymanDeveloperProject.Options.CheckFilenameConventions, 'False');
21
+ assert.equal(kpj.KeymanDeveloperProject.Options.CompilerWarningsAsErrors, 'True');
22
+ assert.equal(kpj.KeymanDeveloperProject.Options.ProjectType, 'keyboard');
23
+ assert.equal(kpj.KeymanDeveloperProject.Options.WarnDeprecatedCode, 'True');
24
+ assert.isUndefined(kpj.KeymanDeveloperProject.Options.Version);
25
+
26
+ assert.lengthOf(kpj.KeymanDeveloperProject.Files.File, 21);
27
+
28
+ // Test a representative set of files - kmn, kps, 2 child files
29
+
30
+ let kf = kpj.KeymanDeveloperProject.Files.File[0];
31
+ assert.equal(kf.ID, 'id_f347675c33d2e6b1c705c787fad4941a');
32
+ assert.equal(kf.Filename, 'khmer_angkor.kmn');
33
+ assert.equal(kf.Filepath, 'source\\khmer_angkor.kmn');
34
+ assert.equal(kf.FileVersion, '1.3');
35
+ assert.equal(kf.FileType, '.kmn');
36
+ assert.equal(kf.Details.Name, 'Khmer Angkor');
37
+ assert.equal(kf.Details.Copyright, '© 2015-2022 SIL International');
38
+ assert.equal(kf.Details.Message, 'More than just a Khmer Unicode keyboard.');
39
+
40
+ kf = kpj.KeymanDeveloperProject.Files.File[1];
41
+ assert.equal(kf.ID, 'id_8d4eb765f80c9f2b0f769cf4e4aaa456');
42
+ assert.equal(kf.Filename, 'khmer_angkor.kps');
43
+ assert.equal(kf.Filepath, 'source\\khmer_angkor.kps');
44
+ assert.isEmpty(kf.FileVersion);
45
+ assert.equal(kf.FileType, '.kps');
46
+ assert.equal(kf.Details.Name, 'Khmer Angkor');
47
+ assert.equal(kf.Details.Copyright, '© 2015-2022 SIL International');
48
+
49
+ kf = kpj.KeymanDeveloperProject.Files.File[2];
50
+ assert.equal(kf.ID, 'id_8a1efc7c4ab7cfece8aedd847679ca27');
51
+ assert.equal(kf.Filename, 'khmer_angkor.ico');
52
+ assert.equal(kf.Filepath, 'source\\khmer_angkor.ico');
53
+ assert.isEmpty(kf.FileVersion);
54
+ assert.equal(kf.FileType, '.ico');
55
+ assert.equal(kf.ParentFileID, 'id_f347675c33d2e6b1c705c787fad4941a');
56
+
57
+ kf = kpj.KeymanDeveloperProject.Files.File[3];
58
+ assert.equal(kf.ID, 'id_8dc195db32d1fd0514de0ad51fff5df0');
59
+ assert.equal(kf.Filename, 'khmer_angkor.js');
60
+ assert.equal(kf.Filepath, 'source\\..\\build\\khmer_angkor.js');
61
+ assert.isEmpty(kf.FileVersion);
62
+ assert.equal(kf.FileType, '.js');
63
+ assert.equal(kf.ParentFileID, 'id_8d4eb765f80c9f2b0f769cf4e4aaa456');
64
+
65
+ // Test transform of .kpj into a KeymanDeveloperProject
66
+
67
+ const project = reader.transform(kpjPath, kpj);
68
+
69
+ assert.equal(project.options.buildPath, '$PROJECTPATH/build');
70
+ assert.isFalse(project.options.checkFilenameConventions);
71
+ assert.isTrue(project.options.compilerWarningsAsErrors);
72
+ assert.equal(project.options.projectType, KeymanDeveloperProjectType.Keyboard);
73
+ assert.isTrue(project.options.warnDeprecatedCode);
74
+ assert.equal(project.options.version, '1.0');
75
+
76
+ assert.lengthOf(project.files, 2);
77
+
78
+ let f: KeymanDeveloperProjectFile10 = <KeymanDeveloperProjectFile10>project.files[0];
79
+ console.dir(f);
80
+ assert.equal(f.id, 'id_f347675c33d2e6b1c705c787fad4941a');
81
+ assert.equal(f.filename, 'khmer_angkor.kmn');
82
+ assert.equal(f.filePath, 'source/khmer_angkor.kmn');
83
+ assert.equal(f.fileVersion, '1.3');
84
+ assert.equal(f.fileType, '.kmn');
85
+ assert.equal(f.details.name, 'Khmer Angkor');
86
+ assert.equal(f.details.copyright, '© 2015-2022 SIL International');
87
+ assert.equal(f.details.message, 'More than just a Khmer Unicode keyboard.');
88
+ assert.isUndefined(f.details.version);
89
+ assert.lengthOf(f.childFiles, 1);
90
+
91
+ f = <KeymanDeveloperProjectFile10>project.files[1];
92
+ assert.equal(f.id, 'id_8d4eb765f80c9f2b0f769cf4e4aaa456');
93
+ assert.equal(f.filename, 'khmer_angkor.kps');
94
+ assert.equal(f.filePath, 'source/khmer_angkor.kps');
95
+ assert.equal(f.fileVersion, '');
96
+ assert.equal(f.fileType, '.kps');
97
+ assert.equal(f.details.name, 'Khmer Angkor');
98
+ assert.isUndefined(f.details.message);
99
+ assert.equal(f.details.copyright, '© 2015-2022 SIL International');
100
+ assert.isUndefined(f.details.version);
101
+ assert.lengthOf(f.childFiles, 18);
102
+
103
+ f = <KeymanDeveloperProjectFile10>project.files[0];
104
+ f = <KeymanDeveloperProjectFile10>f.childFiles[0];
105
+ assert.equal(f.id, 'id_8a1efc7c4ab7cfece8aedd847679ca27');
106
+ assert.equal(f.filename, 'khmer_angkor.ico');
107
+ assert.equal(f.filePath, 'source/khmer_angkor.ico');
108
+ assert.equal(f.fileVersion, '');
109
+ assert.equal(f.fileType, '.ico');
110
+ assert.isEmpty(f.details);
111
+ assert.lengthOf(f.childFiles, 0);
112
+
113
+ f = <KeymanDeveloperProjectFile10>project.files[1];
114
+ f = <KeymanDeveloperProjectFile10>f.childFiles[0];
115
+ assert.equal(f.id, 'id_8dc195db32d1fd0514de0ad51fff5df0');
116
+ assert.equal(f.filename, 'khmer_angkor.js');
117
+ assert.equal(f.filePath, 'source/../build/khmer_angkor.js');
118
+ assert.equal(f.fileVersion, '');
119
+ assert.equal(f.fileType, '.js');
120
+ assert.isEmpty(f.details);
121
+ assert.lengthOf(f.childFiles, 0);
122
+ });
123
+ });
@@ -0,0 +1,15 @@
1
+ import * as fs from 'fs';
2
+ import 'mocha';
3
+ import { makePathToFixture } from '../helpers/index.js';
4
+ import KvkFileReader from "../../src/kvk/kvk-file-reader.js";
5
+ import { verify_khmer_angkor } from './test-kvk-utils.js';
6
+
7
+ describe('kvk-file-reader', function () {
8
+ it('kvk-file-reader should read a valid file', function() {
9
+ const path = makePathToFixture('kvk', 'khmer_angkor.kvk');
10
+ const input = fs.readFileSync(path);
11
+ const reader = new KvkFileReader();
12
+ const vk = reader.read(input);
13
+ verify_khmer_angkor(vk);
14
+ });
15
+ });
@@ -0,0 +1,87 @@
1
+ import * as fs from 'fs';
2
+ import 'mocha';
3
+ import {assert} from 'chai';
4
+ import Hexy from 'hexy';
5
+ import gitDiff from 'git-diff';
6
+ const { hexy } = Hexy;
7
+ import { loadKvksJsonSchema, makePathToFixture } from '../helpers/index.js';
8
+ import KvksFileReader, { KVKSParseError } from "../../src/kvk/kvks-file-reader.js";
9
+ import KvkFileReader from "../../src/kvk/kvk-file-reader.js";
10
+ import KvkFileWriter from "../../src/kvk/kvk-file-writer.js";
11
+ import KvksFileWriter from "../../src/kvk/kvks-file-writer.js";
12
+
13
+ /**
14
+ *
15
+ * @param actual input buffer
16
+ * @param expected expected buffer
17
+ * @returns
18
+ */
19
+ function assertBufferMatch(actual: Buffer, expected: Buffer) {
20
+ const sourceHex = hexy(actual);
21
+ const expectedHex = hexy(expected);
22
+ const diff = gitDiff(expectedHex, sourceHex);
23
+
24
+ assert(!diff, 'Buffers did not match:\n' + diff);
25
+ assert.equal(actual.length, expected.length, 'Buffer lengths are not the same');
26
+ assert.deepEqual(actual, expected); // double check buffers: hexy can return '' on failure
27
+ }
28
+
29
+ describe('kvk-file-reader', function () {
30
+ it('kvk-file-reader should round-trip with kvk-file-writer', function() {
31
+ const path = makePathToFixture('kvk', 'khmer_angkor.kvk');
32
+ const input = fs.readFileSync(path);
33
+ const reader = new KvkFileReader();
34
+ const vk = reader.read(input);
35
+ const writer = new KvkFileWriter();
36
+ const output = writer.write(vk);
37
+ assertBufferMatch(input, Buffer.from(output));
38
+
39
+ // and check the 2nd generation also
40
+ const vk2 = reader.read(output);
41
+ assert.deepEqual(vk2, vk);
42
+ });
43
+ });
44
+
45
+ describe('kvks-file-reader', function () {
46
+ it('kvks-file-reader should compile with kvk-file-writer', function() {
47
+ const inputPath = makePathToFixture('kvk', 'khmer_angkor.kvks');
48
+ const compiledPath = makePathToFixture('kvk', 'khmer_angkor.kvk');
49
+ const input = fs.readFileSync(inputPath);
50
+ const compiled = fs.readFileSync(compiledPath);
51
+ const reader = new KvksFileReader();
52
+ const kvks = reader.read(input);
53
+ assert.doesNotThrow(() => {
54
+ reader.validate(kvks, loadKvksJsonSchema());
55
+ });
56
+ const errors: KVKSParseError[] = [];
57
+ const vk = reader.transform(kvks, errors);
58
+ assert.isEmpty(errors);
59
+ const writer = new KvkFileWriter();
60
+ const output = writer.write(vk);
61
+ assertBufferMatch(Buffer.from(output), compiled);
62
+ });
63
+
64
+ describe('kvks-file-writer', function() {
65
+ it('kvks-file-writer should match what kvk-file-reader reads', function() {
66
+ const kvkIn = makePathToFixture('kvk', 'khmer_angkor.kvk');
67
+ const kvkBuf = fs.readFileSync(kvkIn);
68
+ const kvkReader = new KvkFileReader();
69
+ const kvksReader = new KvksFileReader();
70
+ const vk = kvkReader.read(kvkBuf);
71
+ const kvksWriter = new KvksFileWriter();
72
+ const kvksOut = kvksWriter.write(vk);
73
+
74
+ // Now, re-read kvk from the kvks
75
+ const kvks = kvksReader.read(Buffer.from(kvksOut));
76
+ assert.doesNotThrow(() => {
77
+ kvksReader.validate(kvks, loadKvksJsonSchema());
78
+ });
79
+ const errors: KVKSParseError[] = [];
80
+ const vk2 = kvksReader.transform(kvks, errors);
81
+ assert.isEmpty(errors);
82
+
83
+ // make sure the binary is the same
84
+ assert.deepEqual(vk2, vk);
85
+ });
86
+ });
87
+ });
@@ -0,0 +1,24 @@
1
+ import 'mocha';
2
+ import {assert} from 'chai';
3
+ import { VisualKeyboard, VisualKeyboardHeaderFlags, VisualKeyboardKeyFlags, VisualKeyboardShiftState } from "../../src/kvk/visual-keyboard.js";
4
+ import { USVirtualKeyCodes } from '../../src/consts/virtual-key-constants.js';
5
+
6
+ export function verify_khmer_angkor(vk: VisualKeyboard) {
7
+ assert.equal(vk.header.flags, VisualKeyboardHeaderFlags.kvkhAltGr);
8
+ assert.equal(vk.header.associatedKeyboard, 'khmer_angkor');
9
+ assert.equal(vk.header.ansiFont.name, 'Arial');
10
+ assert.equal(vk.header.ansiFont.size, -12);
11
+ assert.equal(vk.header.ansiFont.color, 0xFF000008);
12
+ assert.equal(vk.header.unicodeFont.name, 'Khmer Busra Kbd');
13
+ assert.equal(vk.header.unicodeFont.size, 16);
14
+ assert.equal(vk.header.unicodeFont.color, 0xFF000008);
15
+ assert.equal(vk.keys.length, 186);
16
+ assert.equal(vk.keys[0].flags, VisualKeyboardKeyFlags.kvkkUnicode);
17
+ assert.equal(vk.keys[0].vkey, USVirtualKeyCodes.K_B);
18
+ assert.equal(vk.keys[0].shift, VisualKeyboardShiftState.KVKS_RALT);
19
+ assert.equal(vk.keys[0].text, 'ឞ');
20
+ assert.equal(vk.keys[185].flags, VisualKeyboardKeyFlags.kvkkUnicode);
21
+ assert.equal(vk.keys[185].vkey, USVirtualKeyCodes.K_COMMA);
22
+ assert.equal(vk.keys[185].shift, VisualKeyboardShiftState.KVKS_SHIFT);
23
+ assert.equal(vk.keys[185].text, '');
24
+ }
@@ -0,0 +1,45 @@
1
+ import * as fs from 'fs';
2
+ import 'mocha';
3
+ import { loadKvksJsonSchema, makePathToFixture } from '../helpers/index.js';
4
+ import KvksFileReader, { KVKSParseError } from "../../src/kvk/kvks-file-reader.js";
5
+ import KvksFileWriter from "../../src/kvk/kvks-file-writer.js";
6
+ import { verify_khmer_angkor } from './test-kvk-utils.js';
7
+ import { assert } from 'chai';
8
+
9
+ describe('kvks-file-reader', function() {
10
+ it('should read a valid file', function() {
11
+ const path = makePathToFixture('kvk', 'khmer_angkor.kvks');
12
+ const input = fs.readFileSync(path);
13
+
14
+ const reader = new KvksFileReader();
15
+ const kvks = reader.read(input);
16
+ assert.doesNotThrow(() => {
17
+ reader.validate(kvks, loadKvksJsonSchema());
18
+ });
19
+ const errors: KVKSParseError[] = [];
20
+ const vk = reader.transform(kvks, errors);
21
+ assert.isEmpty(errors);
22
+ verify_khmer_angkor(vk);
23
+ });
24
+ });
25
+
26
+ describe('kvks-file-writer', function() {
27
+ it('should write a valid file', function() {
28
+ const path = makePathToFixture('kvk', 'khmer_angkor.kvks');
29
+ const input = fs.readFileSync(path);
30
+
31
+ const reader = new KvksFileReader();
32
+ const kvksExpected = reader.read(input);
33
+ const errors: KVKSParseError[] = [];
34
+ const vk = reader.transform(kvksExpected, errors);
35
+ assert.isEmpty(errors);
36
+
37
+ const writer = new KvksFileWriter();
38
+ const output = writer.write(vk);
39
+
40
+ // We compare the (re)loaded data, because there may be
41
+ // minor, irrelevant formatting differences in the emitted xml
42
+ const kvks = reader.read(Buffer.from(output, 'utf8'));
43
+ assert.deepEqual(kvks, kvksExpected);
44
+ });
45
+ });
@@ -0,0 +1,51 @@
1
+ import { constants } from '@keymanapp/ldml-keyboard-constants';
2
+ import { assert } from 'chai';
3
+ import 'mocha';
4
+ import { testTestdataReaderCases } from '../helpers/reader-callback-test.js';
5
+
6
+ describe('ldml keyboard xml reader tests', function () {
7
+ this.slow(500); // 0.5 sec -- json schema validation takes a while
8
+
9
+ testTestdataReaderCases([
10
+ {
11
+ subpath: 'test-fr.xml',
12
+ callback: (data, source) => {
13
+ assert.ok(source);
14
+ assert.ok(source.keyboardTest);
15
+ assert.equal(source.keyboardTest.conformsTo, constants.cldr_version_latest);
16
+
17
+ assert.deepEqual(source.keyboardTest.info, {
18
+ keyboard: 'fr-t-k0-azerty.xml',
19
+ author: 'Team Keyboard',
20
+ name: 'fr-test'
21
+ });
22
+
23
+ assert.sameDeepMembers(source.keyboardTest.repertoire, [
24
+ {
25
+ name: 'simple-repertoire',
26
+ chars: '[a b c d e \\u{22}]',
27
+ type: 'simple'
28
+ },
29
+ { name: 'chars-repertoire', chars: '[á é ó]', type: 'gesture' }
30
+ ]);
31
+
32
+ assert.equal(1, source.keyboardTest.tests?.length);
33
+ assert.equal('key-tests', source.keyboardTest.tests[0].name);
34
+ assert.equal(1, source.keyboardTest.tests[0].test?.length);
35
+ const test0 = source.keyboardTest.tests[0].test[0];
36
+ assert.equal('key-test', test0.name);
37
+ assert.equal('abc\\u0022...', test0.startContext?.to);
38
+ assert.sameDeepOrderedMembers([
39
+ { keystroke: { key: 's' } },
40
+ { check: { result: 'abc\\u0022...s' } },
41
+ { keystroke: { key: 't' } },
42
+ { check: { result: 'abc\\u0022...st' } },
43
+ { keystroke: { key: 'u' } },
44
+ { check: { result: 'abc\\u0022...stu' } },
45
+ { emit: { to: 'v' } },
46
+ { check: { result: 'abc\\u0022...stuv' } },
47
+ ], test0.actions);
48
+ },
49
+ }
50
+ ]);
51
+ });