版博士V2.0程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

141 lignes
3.4 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('$.siblings: this[0] is null', () => {
  7. expect(()=>{
  8. const G = $('var a = 1;');
  9. G[0] = null
  10. G.siblings();
  11. }).not.toThrow();
  12. })
  13. test('$.siblings: simple code', () => {
  14. expect(()=>{
  15. const G = $('var a = 1;')
  16. G.siblings()
  17. }).not.toThrow()
  18. })
  19. test('$.siblings: simple code 2', () => {
  20. expect(() => {
  21. const code = `
  22. function test(){
  23. let a = 1;
  24. let b = 2;
  25. }
  26. test();
  27. `
  28. const G = $(code)
  29. const ss = G.siblings()
  30. }).not.toThrow()
  31. })
  32. test('$.siblings: simple code 3', () => {
  33. expect(() => {
  34. const code = `
  35. let obj = { a: 1, b: 2 };
  36. let c = obj.a + obj.b;
  37. `
  38. const G = $(code)
  39. const ss = G.siblings()
  40. }).not.toThrow()
  41. })
  42. test('$.siblings: simple code 4', () => {
  43. expect(() => {
  44. const code = `
  45. function parent(){
  46. let name = 'jerry';
  47. function eat(){
  48. console.log('do eat');
  49. }
  50. }
  51. parent();
  52. `
  53. const G = $(code).find('let $_$ = \'$_$\'');
  54. const ss = G.siblings()
  55. }).not.toThrow()
  56. })
  57. test('$.siblings: simple code 4', () => {
  58. const code = `
  59. function parent(){
  60. let name = 'jerry';
  61. function eat(){
  62. console.log('do eat');
  63. }
  64. }
  65. parent();
  66. `
  67. const G = $(code).find('let $_$ = \'$_$\'');
  68. const result = G.siblings().generate()
  69. const compareCode = $(`function eat(){
  70. console.log('do eat');
  71. }`).generate();
  72. expect(result).toBe(compareCode);
  73. })
  74. test('$.siblings: simple2 code result should be ok', () => {
  75. const G = $(jc1).find('let $_$ = \'$_$\'');
  76. const result = G.siblings().generate()
  77. const compareCode = $(`const $ = require('../index');`).generate();
  78. expect(result).toBe(compareCode);
  79. })
  80. test('$.siblings: simple html code', () => {
  81. const code = `<div>test</div>`;
  82. expect(() => {
  83. const G = $(code, config.html);
  84. G.siblings();
  85. }).not.toThrow();
  86. })
  87. test('$.siblings: simple html code', () => {
  88. const code = `<div>
  89. <img src=""/>
  90. <span>test</span>
  91. <a href="xxx">is a link</a>
  92. </div>`;
  93. expect(() => {
  94. const G = $(code, config.html).find('<span>$_$</span>');
  95. const s = G.siblings();
  96. }).not.toThrow();
  97. })
  98. test('$: simple1 html code', () => {
  99. expect(() => {
  100. const G = $(hc1, config.html);
  101. const s = G.siblings();
  102. }).not.toThrow();
  103. })
  104. test('$: simple1 html code result should be ok', () => {
  105. const G = $(hc1, config.html);
  106. const s = G.siblings();
  107. const code = s.generate();
  108. expect(code).toBe('\n');
  109. })
  110. test('$: simple1 html code result should be ok', () => {
  111. const G = $(hc1, config.html).find('<span>$_$</span>');
  112. const s = G.siblings().eq(0);
  113. const code = s.generate();
  114. expect(code).toBe('\n ');
  115. })
  116. test('$: simple1 html code result should be ok', () => {
  117. const res = $(`
  118. //a
  119. function foo(){
  120. console.log('foo')
  121. }
  122. function foo1(){
  123. console.log('foo1')
  124. }
  125. //b
  126. function foo2(){
  127. console.log('foo2')
  128. }
  129. `)
  130. .find('//b')
  131. .parent(1)
  132. .siblings()
  133. .generate();
  134. expect(!!res.match('a')).toBeTruthy();
  135. })