UuidTests.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Jint.Tests.Runtime.Domain;
  2. using System;
  3. using Xunit;
  4. namespace Jint.Tests.Runtime
  5. {
  6. public class UuidTests : IDisposable
  7. {
  8. private readonly Engine _engine;
  9. public UuidTests()
  10. {
  11. _engine = new Engine(o => o.AddObjectConverter(new UuidConverter()))
  12. .SetValue("copy", new Func<Guid, Guid>(v => new Guid(v.ToByteArray())))
  13. ;
  14. UuidConstructor.CreateUuidConstructor(_engine);
  15. }
  16. void IDisposable.Dispose()
  17. {
  18. }
  19. private object RunTest(string source)
  20. {
  21. return _engine.Execute(source).GetCompletionValue().ToObject();
  22. }
  23. [Fact]
  24. public void Empty()
  25. {
  26. Assert.Equal(Guid.Empty, RunTest($"Uuid.parse('{Guid.Empty}')"));
  27. Assert.Equal(Guid.Empty, RunTest($"Uuid.Empty"));
  28. }
  29. [Fact]
  30. public void Random()
  31. {
  32. var actual = RunTest($"new Uuid()");
  33. Assert.NotEqual(Guid.Empty, actual);
  34. Assert.IsType<Guid>(actual);
  35. }
  36. [Fact]
  37. public void Copy()
  38. {
  39. var actual = (bool)RunTest($"const g = new Uuid(); copy(g).toString() === g.toString()");
  40. Assert.True(actual);
  41. }
  42. }
  43. }