number.js 890 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. let _ = require('lodash');
  3. let hljs = require('../../build');
  4. let utility = require('../utility');
  5. const pattern = new RegExp(`${hljs.NUMBER_RE}$`);
  6. let numberToString = utility.numberToString;
  7. describe('.NUMBER_RE', function() {
  8. it('should match regular numbers and decimals', function() {
  9. const number = _.map(_.range(0, 1001), numberToString);
  10. const decimal = _.map(_.range(0, 1.001, 0.001), numberToString);
  11. const noLeadingZero = ['.1234', '.5206', '.0002', '.9998'];
  12. const numbers = [].concat(number, decimal, noLeadingZero);
  13. numbers.should.matchEach(pattern);
  14. });
  15. it('should not match hex or binary numbers', function() {
  16. const numbers = [ '0xbada55', '0xfa1755', '0x45362e'
  17. , '0b0101' , '0b1100' , '0b1001'
  18. ];
  19. numbers.should.not.matchEach(pattern);
  20. });
  21. });