SwitchTests.cs 741 B

1234567891011121314151617181920212223242526272829
  1. namespace Jint.Tests.Runtime;
  2. public class JintFailureTest
  3. {
  4. [Fact]
  5. public void ShouldHandleCaseBlockLexicalScopeCorrectly()
  6. {
  7. var engine = new Engine();
  8. engine.SetValue("switchVal", 1);
  9. engine.SetValue("getCoffee", new Func<string>(() => "coffee"));
  10. engine.Execute(@"
  11. function myFunc() {
  12. switch(switchVal) {
  13. case 0:
  14. const text = getCoffee();
  15. return text;
  16. break;
  17. case 1:
  18. const line = getCoffee();
  19. return line;
  20. break;
  21. }
  22. }
  23. ");
  24. Assert.Equal("coffee", engine.Evaluate("myFunc()"));
  25. }
  26. }