12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using Jint.Runtime;
- using Jint.Runtime.Modules;
- using System;
- using System.IO;
- using System.Reflection;
- using Xunit;
- using Xunit.Sdk;
- namespace Jint.Tests.Test262.Language;
- public class ModuleTests : Test262Test
- {
- [Theory(DisplayName = "language\\module-code")]
- [MemberData(nameof(SourceFiles), "language\\module-code", false)]
- [MemberData(nameof(SourceFiles), "language\\module-code", true, Skip = "Skipped")]
- protected void ModuleCode(SourceFile sourceFile)
- {
- RunModuleTest(sourceFile);
- }
- [Theory(DisplayName = "language\\export")]
- [MemberData(nameof(SourceFiles), "language\\export", false)]
- [MemberData(nameof(SourceFiles), "language\\export", true, Skip = "Skipped")]
- protected void Export(SourceFile sourceFile)
- {
- RunModuleTest(sourceFile);
- }
- [Theory(DisplayName = "language\\import")]
- [MemberData(nameof(SourceFiles), "language\\import", false)]
- [MemberData(nameof(SourceFiles), "language\\import", true, Skip = "Skipped")]
- protected void Import(SourceFile sourceFile)
- {
- RunModuleTest(sourceFile);
- }
- private static void RunModuleTest(SourceFile sourceFile)
- {
- if (sourceFile.Skip)
- {
- return;
- }
- var code = sourceFile.Code;
- var options = new Options();
- options.Host.Factory = _ => new ModuleTestHost();
- options.EnableModules(Path.Combine(BasePath, "test"));
- var engine = new Engine(options);
- var negative = code.IndexOf("negative:", StringComparison.OrdinalIgnoreCase) != -1;
- string lastError = null;
- try
- {
- engine.LoadModule(sourceFile.FullPath);
- }
- catch (JavaScriptException ex)
- {
- lastError = ex.ToString();
- }
- catch (Exception ex)
- {
- lastError = ex.ToString();
- }
- if (!negative && !string.IsNullOrWhiteSpace(lastError))
- {
- throw new XunitException(lastError);
- }
- }
- }
|