tests_alternations.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. export default function (qunit, $, Inputmask) {
  2. qunit.module("Alternations");
  3. qunit.test("\"9{1,2}C|S A{1,3} 9{4}\" - ankitajain32", function (assert) {
  4. var $fixture = $("#qunit-fixture");
  5. $fixture.append('<input type="text" id="testmask" />');
  6. var testmask = document.getElementById("testmask");
  7. Inputmask("9{1,2}C|S A{1,3} 9{4}").mask(testmask);
  8. $("#testmask").Type("12Cabc1234");
  9. assert.equal(testmask.inputmask._valueGet(), "12C ABC 1234", "Result " + testmask.inputmask._valueGet());
  10. });
  11. qunit.test("\"9{1,2}C|S A{1,3} 9{4}\" replace C with S - ankitajain32", function (assert) {
  12. var $fixture = $("#qunit-fixture");
  13. $fixture.append('<input type="text" id="testmask" />');
  14. var testmask = document.getElementById("testmask");
  15. Inputmask("9{1,2}C|S A{1,3} 9{4}").mask(testmask);
  16. $("#testmask").Type("12Cabc1234");
  17. $.caret(testmask, 2, 3);
  18. $("#testmask").Type("S");
  19. assert.equal(testmask.inputmask._valueGet(), "12S ABC 1234", "Result " + testmask.inputmask._valueGet());
  20. });
  21. qunit.test("nested alternations 1", function (assert) {
  22. var $fixture = $("#qunit-fixture");
  23. $fixture.append('<input type="text" id="testmask" />');
  24. var testmask = document.getElementById("testmask");
  25. Inputmask("0<2)##-##-##>|<3<4)#-##-##>|<5)#-##-##>|<6)#-##-##>>", {
  26. groupmarker: {
  27. start: "<",
  28. end: ">"
  29. }
  30. }).mask(testmask);
  31. $("#testmask").Type("02121212");
  32. assert.equal(testmask.inputmask._valueGet(), "02)12-12-12", "Result " + testmask.inputmask._valueGet());
  33. });
  34. qunit.test("nested alternations 2", function (assert) {
  35. var $fixture = $("#qunit-fixture");
  36. $fixture.append('<input type="text" id="testmask" />');
  37. var testmask = document.getElementById("testmask");
  38. Inputmask("0<2)##-##-##>|<3<4)#-##-##>|<5)#-##-##>|<6)#-##-##>>", {
  39. groupmarker: {
  40. start: "<",
  41. end: ">"
  42. }
  43. }).mask(testmask);
  44. $("#testmask").Type("03411212");
  45. assert.equal(testmask.inputmask._valueGet(), "034)1-12-12", "Result " + testmask.inputmask._valueGet());
  46. });
  47. qunit.test("nested alternations 3", function (assert) {
  48. var $fixture = $("#qunit-fixture");
  49. $fixture.append('<input type="text" id="testmask" />');
  50. var testmask = document.getElementById("testmask");
  51. Inputmask("0<2)##-##-##>|<3<4)#-##-##>|<5)#-##-##>|<6)#-##-##>>", {
  52. groupmarker: {
  53. start: "<",
  54. end: ">"
  55. }
  56. }).mask(testmask);
  57. $("#testmask").Type("03511212");
  58. assert.equal(testmask.inputmask._valueGet(), "035)1-12-12", "Result " + testmask.inputmask._valueGet());
  59. });
  60. qunit.test("nested alternations 4", function (assert) {
  61. var $fixture = $("#qunit-fixture");
  62. $fixture.append('<input type="text" id="testmask" />');
  63. var testmask = document.getElementById("testmask");
  64. Inputmask("0<2)##-##-##>|<3<4)#-##-##>|<5)#-##-##>|<6)#-##-##>>", {
  65. groupmarker: {
  66. start: "<",
  67. end: ">"
  68. }
  69. }).mask(testmask);
  70. $("#testmask").Type("03611212");
  71. assert.equal(testmask.inputmask._valueGet(), "036)1-12-12", "Result " + testmask.inputmask._valueGet());
  72. });
  73. qunit.test("alternations W|XY|Z", function (assert) {
  74. var $fixture = $("#qunit-fixture");
  75. $fixture.append('<input type="text" id="testmask" />');
  76. var testmask = document.getElementById("testmask");
  77. Inputmask("W|XY|Z").mask(testmask);
  78. $("#testmask").Type("WZ");
  79. assert.equal(testmask.inputmask._valueGet(), "WZ", "Result " + testmask.inputmask._valueGet());
  80. });
  81. qunit.test("alternations (W)|(X)(Y)|(Z)", function (assert) {
  82. var $fixture = $("#qunit-fixture");
  83. $fixture.append('<input type="text" id="testmask" />');
  84. var testmask = document.getElementById("testmask");
  85. Inputmask("(W)|(X)(Y)|(Z)").mask(testmask);
  86. $("#testmask").Type("WZ");
  87. assert.equal(testmask.inputmask._valueGet(), "WZ", "Result " + testmask.inputmask._valueGet());
  88. });
  89. qunit.test("alternations (9{1,3}|SE|NE|SW|NW)-9{1,3} - yesman85", function (assert) {
  90. var $fixture = $("#qunit-fixture");
  91. $fixture.append('<input type="text" id="testmask" />');
  92. var testmask = document.getElementById("testmask");
  93. Inputmask("(9{1,3}|SE|NE|SW|NW)-9{1,3}").mask(testmask);
  94. $("#testmask").Type("(NE123");
  95. assert.equal(testmask.inputmask._valueGet(), "NE-123", "Result " + testmask.inputmask._valueGet());
  96. });
  97. qunit.test("((S))", function (assert) {
  98. var $fixture = $("#qunit-fixture");
  99. $fixture.append('<input type="text" id="testmask" />');
  100. var testmask = document.getElementById("testmask");
  101. Inputmask("((S))").mask(testmask);
  102. testmask.focus();
  103. assert.equal(testmask.inputmask._valueGet(), "((S))", "Result " + testmask.inputmask._valueGet());
  104. });
  105. qunit.test("((S)", function (assert) {
  106. var $fixture = $("#qunit-fixture");
  107. $fixture.append('<input type="text" id="testmask" />');
  108. var testmask = document.getElementById("testmask");
  109. Inputmask("((S)").mask(testmask);
  110. testmask.focus();
  111. assert.equal(testmask.inputmask._valueGet(), "((S)", "Result " + testmask.inputmask._valueGet());
  112. });
  113. qunit.test("+371-99-999-999 - artemkaint", function (assert) {
  114. var $fixture = $("#qunit-fixture");
  115. $fixture.append('<input type="text" id="testmask" />');
  116. var testmask = document.getElementById("testmask");
  117. Inputmask([
  118. "+371-99-999-999",
  119. "+370(999)99-999",
  120. "+375(99)999-99-99",
  121. "+374-99-999-999",
  122. "+380(99)999-99-99",
  123. "+358(999)999-99-99",
  124. "+373-9999-9999",
  125. "+381-99-999-9999"
  126. ]).mask(testmask);
  127. testmask.focus();
  128. $("#testmask").Type("112123123");
  129. assert.equal(testmask.inputmask._valueGet(), "+371-12-123-123", "Result " + testmask.inputmask._valueGet());
  130. });
  131. qunit.test("+371-99-999-999 - artemkaint", function (assert) {
  132. var $fixture = $("#qunit-fixture");
  133. $fixture.append('<input type="text" id="testmask" />');
  134. var testmask = document.getElementById("testmask");
  135. Inputmask([
  136. "+371-99-999-999",
  137. "+370(999)99-999",
  138. "+375(99)999-99-99",
  139. "+374-99-999-999",
  140. "+380(99)999-99-99",
  141. "+358(999)999-99-99",
  142. "+373-9999-9999",
  143. "+381-99-999-9999"
  144. ]).mask(testmask);
  145. testmask.focus();
  146. $("#testmask").Type("412123123");
  147. assert.equal(testmask.inputmask._valueGet(), "+374-12-123-123", "Result " + testmask.inputmask._valueGet());
  148. });
  149. qunit.test("(9)|(a9) - type 1 - ivaninDarpatov", function (assert) {
  150. var $fixture = $("#qunit-fixture");
  151. $fixture.append('<input type="text" id="testmask" />');
  152. var testmask = document.getElementById("testmask");
  153. Inputmask("(9)|(a9)").mask(testmask);
  154. testmask.focus();
  155. $("#testmask").Type("12");
  156. assert.equal(testmask.inputmask._valueGet(), "1", "Result " + testmask.inputmask._valueGet());
  157. });
  158. qunit.test("(9)|(a9) - type a1 - ivaninDarpatov", function (assert) {
  159. var $fixture = $("#qunit-fixture");
  160. $fixture.append('<input type="text" id="testmask" />');
  161. var testmask = document.getElementById("testmask");
  162. Inputmask("(9)|(a9)").mask(testmask);
  163. testmask.focus();
  164. $("#testmask").Type("a1");
  165. assert.equal(testmask.inputmask._valueGet(), "a1", "Result " + testmask.inputmask._valueGet());
  166. });
  167. qunit.test("(999)|(0aa) - type 0ab - ivaninDarpatov", function (assert) {
  168. var $fixture = $("#qunit-fixture");
  169. $fixture.append('<input type="text" id="testmask" />');
  170. var testmask = document.getElementById("testmask");
  171. Inputmask("(999)|(0aa)").mask(testmask);
  172. testmask.focus();
  173. $("#testmask").Type("0ab");
  174. assert.equal(testmask.inputmask._valueGet(), "0ab", "Result " + testmask.inputmask._valueGet());
  175. });
  176. qunit.test("(999)|(0aa) - type 1ab - ivaninDarpatov", function (assert) {
  177. var $fixture = $("#qunit-fixture");
  178. $fixture.append('<input type="text" id="testmask" />');
  179. var testmask = document.getElementById("testmask");
  180. Inputmask("(999)|(0aa)").mask(testmask);
  181. testmask.focus();
  182. $("#testmask").Type("1ab");
  183. assert.equal(testmask.inputmask._valueGet(), "1__", "Result " + testmask.inputmask._valueGet());
  184. });
  185. qunit.test("(9)|(09)|(19)|(2f) - type 41 - ivaninDarpatov", function (assert) {
  186. var $fixture = $("#qunit-fixture");
  187. $fixture.append('<input type="text" id="testmask" />');
  188. var testmask = document.getElementById("testmask");
  189. Inputmask("(9)|(09)|(19)|(2f)", {
  190. definitions: {
  191. "f": {validator: "[0-3]"}
  192. }
  193. }).mask(testmask);
  194. testmask.focus();
  195. $("#testmask").Type("41");
  196. assert.equal(testmask.inputmask._valueGet(), "4", "Result " + testmask.inputmask._valueGet());
  197. });
  198. qunit.test("(9)|(09)|(19)|(2f) - type 01 - ivaninDarpatov", function (assert) {
  199. var $fixture = $("#qunit-fixture");
  200. $fixture.append('<input type="text" id="testmask" />');
  201. var testmask = document.getElementById("testmask");
  202. Inputmask("(9)|(09)|(19)|(2f)", {
  203. definitions: {
  204. "f": {validator: "[0-3]"}
  205. }
  206. }).mask(testmask);
  207. testmask.focus();
  208. $("#testmask").Type("01");
  209. assert.equal(testmask.inputmask._valueGet(), "01", "Result " + testmask.inputmask._valueGet());
  210. });
  211. qunit.test("(9)|(09)|(19)|(2f) - type 11 - ivaninDarpatov", function (assert) {
  212. var $fixture = $("#qunit-fixture");
  213. $fixture.append('<input type="text" id="testmask" />');
  214. var testmask = document.getElementById("testmask");
  215. Inputmask("(9)|(09)|(19)|(2f)", {
  216. definitions: {
  217. "f": {validator: "[0-3]"}
  218. }
  219. }).mask(testmask);
  220. testmask.focus();
  221. $("#testmask").Type("11");
  222. assert.equal(testmask.inputmask._valueGet(), "11", "Result " + testmask.inputmask._valueGet());
  223. });
  224. qunit.test("(9)|(09)|(19)|(2f) - type 23 - ivaninDarpatov", function (assert) {
  225. var $fixture = $("#qunit-fixture");
  226. $fixture.append('<input type="text" id="testmask" />');
  227. var testmask = document.getElementById("testmask");
  228. Inputmask("(9)|(09)|(19)|(2f)", {
  229. definitions: {
  230. "f": {validator: "[0-3]"}
  231. }
  232. }).mask(testmask);
  233. testmask.focus();
  234. $("#testmask").Type("23");
  235. assert.equal(testmask.inputmask._valueGet(), "23", "Result " + testmask.inputmask._valueGet());
  236. });
  237. qunit.test("(9|09|19|2f) - type 24 - ivaninDarpatov", function (assert) {
  238. var $fixture = $("#qunit-fixture");
  239. $fixture.append('<input type="text" id="testmask" />');
  240. var testmask = document.getElementById("testmask");
  241. Inputmask("(9|09|19|2f)", {
  242. definitions: {
  243. "f": {validator: "[0-3]"}
  244. }
  245. }).mask(testmask);
  246. testmask.focus();
  247. $("#testmask").Type("24");
  248. assert.equal(testmask.inputmask._valueGet(), "2_", "Result " + testmask.inputmask._valueGet());
  249. });
  250. };