HexadecimalIdentifierNamesGenerator.spec.ts 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import 'reflect-metadata';
  2. import { assert } from 'chai';
  3. import { ServiceIdentifiers } from '../../../../src/container/ServiceIdentifiers';
  4. import { IIdentifierNamesGenerator } from '../../../../src/interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
  5. import { IInversifyContainerFacade } from '../../../../src/interfaces/container/IInversifyContainerFacade';
  6. import { IdentifierNamesGenerator } from '../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
  7. import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
  8. describe('HexadecimalIdentifierNamesGenerator', () => {
  9. describe('generate (length: number): string', () => {
  10. describe('Hexadecimal name without prefix', () => {
  11. let identifierNamesGenerator: IIdentifierNamesGenerator,
  12. hexadecimalIdentifierName: string,
  13. regExp: RegExp;
  14. before(() => {
  15. const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
  16. inversifyContainerFacade.load('', {});
  17. identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
  18. ServiceIdentifiers.IIdentifierNamesGenerator,
  19. IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
  20. )
  21. });
  22. describe('variant #1: hexadecimal name with length `4`', () => {
  23. before(() => {
  24. hexadecimalIdentifierName = identifierNamesGenerator.generate(4);
  25. regExp = /^_0x(\w){4}$/;
  26. });
  27. it('should return hexadecimal name', () => {
  28. assert.match(hexadecimalIdentifierName, regExp);
  29. })
  30. });
  31. describe('variant #2: hexadecimal name with length `6`', () => {
  32. before(() => {
  33. hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
  34. regExp = /^_0x(\w){4,6}$/;
  35. });
  36. it('should return hexadecimal name', () => {
  37. assert.match(hexadecimalIdentifierName, regExp);
  38. })
  39. });
  40. });
  41. describe('Hexadecimal name with prefix', () => {
  42. let identifierNamesGenerator: IIdentifierNamesGenerator,
  43. hexadecimalIdentifierName: string,
  44. regExp: RegExp;
  45. before(() => {
  46. const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
  47. inversifyContainerFacade.load('', {
  48. identifiersPrefix: 'foo'
  49. });
  50. identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
  51. ServiceIdentifiers.IIdentifierNamesGenerator,
  52. IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
  53. )
  54. });
  55. describe('variant #1: hexadecimal name with prefix', () => {
  56. before(() => {
  57. hexadecimalIdentifierName = identifierNamesGenerator.generate(6);
  58. regExp = /^foo_0x(\w){4,6}$/;
  59. });
  60. it('should return hexadecimal name', () => {
  61. assert.match(hexadecimalIdentifierName, regExp);
  62. })
  63. });
  64. });
  65. });
  66. });