版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

121 строка
3.5 KiB

  1. const $ = require('../index');
  2. const config = require('./config');
  3. const jc1 = require('./code/simple1');
  4. const jc2 = require('./code/simple2');
  5. const hc1 = require('./code/simple1.html');
  6. test('$.match: simple js code should not throw error', () => {
  7. expect(() => {
  8. const G = $(jc1).find('var $_$');
  9. G.match;
  10. }).not.toThrow();
  11. })
  12. test('$.match: simple js code match should be undefined', () => {
  13. const G = $(jc1);
  14. const match = G.match;
  15. expect(match).toBe(undefined);
  16. })
  17. test('$.match: simple js code match should be same', () => {
  18. const G = $(jc1).find('var $_$');
  19. const match = G.match;
  20. expect(match[0][0].value === 'a').toBeTruthy();
  21. })
  22. test('$.match: js code match should be same', () => {
  23. const G = $(jc2).find(`const $_$ = { name: '1' };`);
  24. const match = G.match;
  25. expect(match[0][0].value === 'params').toBeTruthy();
  26. })
  27. test('$.match: html code should not throw error', () => {
  28. expect(() => {
  29. const G = $(hc1, config.html);
  30. const w = G.match;
  31. }).not.toThrow();
  32. })
  33. test('$.match: html code match should be undefined', () => {
  34. const G = $(hc1, config.html);
  35. const match = G.match;
  36. expect(match).toBe(undefined);
  37. })
  38. test('$.match: html code match should be same', () => {
  39. const G = $(hc1, config.html).find('<span>$_$</span>');
  40. const match = G.match;
  41. expect(match[0] &&
  42. match[0][0].node.length &&
  43. match[0][0].node[0].nodeType === 'text' &&
  44. match[0][0].node[0].content.value.content === 'test'
  45. ).toBeTruthy();
  46. })
  47. test('$.match: html code attr value match should be same', () => {
  48. const G = $(hc1, config.html).find('<div id=$_$>');
  49. const match = G.match;
  50. expect(match[0] &&
  51. match[0][0].node &&
  52. match[0][0].node.content === '1'
  53. ).toBeTruthy();
  54. })
  55. test('$.match: html code attr key match should be same', () => {
  56. const G = $(hc1, config.html).find('<div $_$="1">');
  57. const match = G.match;
  58. expect(match[0] &&
  59. match[0][0].node &&
  60. match[0][0].node.content === 'id'
  61. ).toBeTruthy();
  62. })
  63. test('$.match: html code attr key match should be same', () => {
  64. let res = [];
  65. $(`(function(param_1, param_2) {
  66. // Code that runs in your function
  67. })({"config": {a:1}, "data": {b:2}}, {"actions": {c:3}, "misc": {d:4}});
  68. (function(param_1, param_2) {
  69. // Code that runs in your function
  70. })({"config": {a:1}, "data": {b:2}}, {"actions": {c:3}, "misc": {d:4}});
  71. (function() {
  72. // Code that runs in your function
  73. })({"config2": {a:1}});
  74. (somethingelse)(111);`)
  75. .find(`(function(){})($_$2)`)
  76. .each(item => {
  77. res.push(item.match[2].map(m => m.value))
  78. })
  79. expect(res.length == 3).toBeTruthy();
  80. })
  81. test('$.match: match params', () => {
  82. const res = $(`foo(a)`)
  83. .find(`foo($_$1, $_$2)`)
  84. expect(!res.length).toBeTruthy();
  85. })
  86. test('$.match: match params', () => {
  87. const res = $(`
  88. function xx(){
  89. var a =5;
  90. return 6666
  91. }`)
  92. .find([
  93. 'function $_$xx(){return $_$return}',
  94. ])
  95. expect(res.match['return'].length == 1).toBeTruthy();
  96. })
  97. // test('$.match: match params', () => {
  98. // const res = $(`
  99. // var tt = this, a = 1;`)
  100. // .find('var $_$thisName = this')
  101. // expect(res.match['thisName'].length == 1).toBeTruthy();
  102. // })
  103. test('$.match: match params', () => {
  104. expect(() => {
  105. const AST = $('iii');
  106. const b = AST.find('a')
  107. console.log(b.match)
  108. }).not.toThrow()
  109. })