版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

109 righe
2.7 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('$.nextAll: empty code', () => {
  7. expect(()=>{
  8. const G = $('');
  9. G.nextAll();
  10. }).not.toThrow();
  11. })
  12. test('$.nextAll: simple code', () => {
  13. expect(()=>{
  14. const G = $('var a = 1;');
  15. G.nextAll();
  16. }).not.toThrow();
  17. })
  18. test('$.nextAll: this[0] is null', () => {
  19. expect(()=>{
  20. const G = $('var a = 1;');
  21. G[0] = null
  22. G.nextAll();
  23. }).not.toThrow();
  24. })
  25. test('$.nextAll: simple code 2', () => {
  26. expect(() => {
  27. const code = `
  28. function test(){
  29. let a = 1;
  30. let b = 2;
  31. }
  32. test();
  33. `
  34. const G = $(code)
  35. const ss = G.nextAll()
  36. }).not.toThrow()
  37. })
  38. test('$.nextAll: simple code 3', () => {
  39. expect(() => {
  40. const code = `
  41. let obj = { a: 1, b: 2 };
  42. let c = obj.a + obj.b;
  43. `
  44. const G = $(code)
  45. const ss = G.nextAll()
  46. }).not.toThrow()
  47. })
  48. test('$.nextAll: simple code 4', () => {
  49. expect(() => {
  50. const code = `
  51. function parent(){
  52. let name = 'jerry';
  53. function eat(){
  54. console.log('do eat');
  55. }
  56. }
  57. parent();
  58. `
  59. const G = $(code).find('let $_$ = \'$_$\'');
  60. const ss = G.nextAll()
  61. }).not.toThrow()
  62. })
  63. test('$.nextAll: simple code 4', () => {
  64. const code = `
  65. function parent(){
  66. let name = 'jerry';
  67. function eat(){
  68. console.log('do eat');
  69. }
  70. }
  71. parent();
  72. `
  73. const G = $(code).find('let $_$ = \'$_$\'');
  74. const result = G.nextAll().generate()
  75. const compareCode = $(`function eat(){
  76. console.log('do eat');
  77. }`).generate();
  78. // comment:可以考虑去掉换行符和空格之后再做对比,不然代码缩进会影响结果
  79. expect(result).toBe(compareCode);
  80. })
  81. test('$.nextAll: simple html code', () => {
  82. const code = `<div>test</div>`;
  83. expect(() => {
  84. const G = $(code, config.html);
  85. G.nextAll();
  86. }).not.toThrow();
  87. })
  88. test('$.nextAll: simple html code', () => {
  89. const code = `<div>
  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. G.nextAll();
  96. }).not.toThrow();
  97. })
  98. test('$.nextAll: simple html code result should be ok', () => {
  99. const code = `<div>
  100. <span>test</span>
  101. <a href="xxx">is a link</a>
  102. </div>`;
  103. const G = $(code, config.html).find('<span>$_$</span>');
  104. const result = G.nextAll().generate();
  105. expect(result).toBe(`\n `);
  106. })