validate-identifier.test.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. const validateIdentifier = require("./validate-identifier");
  3. describe("validate-identifier", () => {
  4. it("should return true for reserved keyword", () => {
  5. const l = "while";
  6. expect(validateIdentifier.isKeyword(l)).toBe(true);
  7. });
  8. it("should return false for unreserved keyword", () => {
  9. const l = "foo";
  10. expect(validateIdentifier.isKeyword(l)).toBe(false);
  11. });
  12. it("should retrun false if literal is not in U+200C zero width non-joiner, U+200D zero width joiner, or any symbol with the Unicode derived core property ID_Continue", () => {
  13. const l = "\u00A9";
  14. expect(validateIdentifier.isIdentifierChar(l)).toBe(false);
  15. });
  16. it("should retrun true if literal is in U+200C zero width non-joiner, U+200D zero width joiner, or any symbol with the Unicode derived core property ID_Continue", () => {
  17. const l = "foo$bar";
  18. expect(validateIdentifier.isIdentifierChar(l)).toBe(true);
  19. });
  20. it("should return true if literal name starts with $, _ or any symbol with the unicode derived core property ID_Start", () => {
  21. const l = "$foo";
  22. expect(validateIdentifier.isIdentifierStart(l)).toBe(true);
  23. });
  24. it("should return false if literal name does not starts with $, _ or any symbol with the unicode derived core property ID_Start", () => {
  25. const l = "^bar";
  26. expect(validateIdentifier.isIdentifierStart(l)).toBe(false);
  27. });
  28. });