版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

97 regels
3.0 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('$.has: simple code', () => {
  7. expect(() => {
  8. const G = $('var a = 1;');
  9. G.has('var $_$ ');
  10. }).not.toThrow();
  11. })
  12. test('$.has: simple code', () => {
  13. expect(() => {
  14. const G = $('var a = 1;');
  15. G.has('var $_$ ');
  16. }).not.toThrow();
  17. })
  18. test('$.has: simple code result should be ok', () => {
  19. const G = $('var a = 1;');
  20. const result = G.has('var $_$ ');
  21. expect(result).toBeTruthy();
  22. })
  23. test('$.has: simple1 code result should be ok', () => {
  24. const G = $(jc1);
  25. const result = G.has('xxMonitor.start()');
  26. expect(result).toBeTruthy();
  27. })
  28. test('$.has: simple1 code result should be ok', () => {
  29. const G = $(jc1);
  30. const result = G.has('var a = 1234');
  31. expect(result).not.toBeTruthy();
  32. })
  33. test('$.has: simple2 code result should be ok', () => {
  34. const G = $(jc2);
  35. const result = G.has('var a = 1234');
  36. expect(result).not.toBeTruthy();
  37. })
  38. test('$.has: simple2 code result should be ok', () => {
  39. const G = $(jc2);
  40. const result = G.find('View.extend($_$)').has('var a = 1234');
  41. expect(result).not.toBeTruthy();
  42. })
  43. test('$.has: simple2 code result should be ok', () => {
  44. const G = $(jc2);
  45. const result = G.find('View.extend($_$)').has(`this.observeLocation(['start', 'end'])`);
  46. expect(result).toBeTruthy();
  47. })
  48. test('$.has: simple1 html code', () => {
  49. expect(() => {
  50. const G = $(hc1, config.html);
  51. G.has('<span>test</span>');
  52. }).not.toThrow();
  53. })
  54. test('$.has: simple1 html code result should be ok', () => {
  55. const G = $(hc1, config.html);
  56. const result = G.has('<span>test</span>');
  57. expect(result).toBeTruthy();
  58. })
  59. test('$.has: simple1 html code result should be ok', () => {
  60. const G = $(hc1, config.html);
  61. const result = G.has('<title>$_$</title>');
  62. expect(result).toBeTruthy();
  63. })
  64. test('$.has: simple1 html code result should be ok', () => {
  65. const G = $(hc1, config.html);
  66. const result = G.has('<title id="title1">$_$</title>');
  67. expect(result).not.toBeTruthy();
  68. })
  69. test('$.has: code result should be ok', () => {
  70. const G = $(hc1, config.html);
  71. const result = G.has('<!DOCTYPE html>');
  72. expect(result).toBeTruthy();
  73. })
  74. test('$.has: script code result should be ok', () => {
  75. const G = $(hc1, config.html);
  76. const result = G.has('<script>$_$</script>');
  77. expect(result).toBeTruthy();
  78. })
  79. test('$.has: style code result should be ok', () => {
  80. const G = $(hc1, config.html);
  81. const result = G.has('<style>$_$</style>');
  82. expect(result).toBeTruthy();
  83. })
  84. test('$.has: comment code result should be ok', () => {
  85. const G = $(hc1, config.html);
  86. const result = G.has('<!-- $_$ -->');
  87. expect(result).toBeTruthy();
  88. })
  89. test('$.has: vue has', () => {
  90. const result = $('<template></template>', { parseOptions: { language: 'vue' } })
  91. .has('var a = 1')
  92. expect(!result).toBeTruthy();
  93. })