testcontext.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Phoenix Shell.
  5. *
  6. * Phoenix Shell is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import assert from 'assert';
  20. import { Context } from "../context.js";
  21. describe('context', () => {
  22. it ('works', () => {
  23. const ctx = new Context({ a: 1 });
  24. const subCtx = ctx.sub({ b: 2 });
  25. assert.equal(ctx.a, 1);
  26. assert.equal(ctx.b, undefined);
  27. assert.equal(subCtx.a, 1);
  28. assert.equal(subCtx.b, 2);
  29. }),
  30. it ('doesn\'t mangle inner-contexts', () => {
  31. const ctx = new Context({
  32. plainObject: { a: 1, b: 2, c: 3 },
  33. contextObject: new Context({ i: 4, j: 5, k: 6 }),
  34. });
  35. const subCtx = ctx.sub({
  36. plainObject: { a: 101 },
  37. contextObject: { i: 104 },
  38. });
  39. assert.equal(subCtx.plainObject.a, 101);
  40. assert.equal(subCtx.plainObject.b, undefined);
  41. assert.equal(subCtx.contextObject.i, 104);
  42. assert.equal(subCtx.contextObject.j, 5);
  43. })
  44. });