ClassTests.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. namespace Jint.Tests.Runtime;
  2. public class ClassTests
  3. {
  4. [Fact]
  5. public void IsBlockScoped()
  6. {
  7. const string Script = @"
  8. class C {}
  9. var c1 = C;
  10. {
  11. class C {}
  12. var c2 = C;
  13. }
  14. return C === c1;";
  15. var engine = new Engine();
  16. Assert.True(engine.Evaluate(Script).AsBoolean());
  17. }
  18. [Fact]
  19. public void CanDestructureNestedMembers()
  20. {
  21. const string Script = @"
  22. class Board {
  23. constructor () {
  24. this.grid = {width: 10, height: 10}
  25. }
  26. get width () {
  27. const {grid} = this
  28. return grid.width
  29. }
  30. get doubleWidth () {
  31. const {width} = this
  32. return width * 2
  33. }
  34. }";
  35. var engine = new Engine();
  36. engine.Execute(Script);
  37. engine.Evaluate("var board = new Board()");
  38. Assert.Equal(10, engine.Evaluate("board.width"));
  39. Assert.Equal(20, engine.Evaluate("board.doubleWidth "));
  40. }
  41. }