StringTests.cs 925 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using Xunit;
  3. namespace Jint.Tests.Runtime
  4. {
  5. public class StringTests
  6. {
  7. public StringTests()
  8. {
  9. _engine = new Engine()
  10. .SetValue("log", new Action<object>(Console.WriteLine))
  11. .SetValue("assert", new Action<bool>(Assert.True))
  12. .SetValue("equal", new Action<object, object>(Assert.Equal));
  13. }
  14. private readonly Engine _engine;
  15. [Fact]
  16. public void StringConcatenationAndReferences()
  17. {
  18. const string script = @"
  19. var foo = 'foo';
  20. foo += 'foo';
  21. var bar = foo;
  22. bar += 'bar';
  23. ";
  24. var value = _engine.Execute(script);
  25. var foo = _engine.Execute("foo").GetCompletionValue().AsString();
  26. var bar = _engine.Execute("bar").GetCompletionValue().AsString();
  27. Assert.Equal("foofoo", foo);
  28. Assert.Equal("foofoobar", bar);
  29. }
  30. }
  31. }