private void AssertModule(string moduleName, ModuleLoaderType configLoaderType, ModuleType?moduleType, bool?isAmd) { var block = GetInlineArgumentsBlock(configLoaderType); var amd = new List <string>(); var cjs = new List <string>(); var module = moduleType.HasValue ? new Module(moduleName, moduleType.Value, null) : null; block.AddModuleByType(amd, cjs, module); var message = string.Format("{0} Config: {1} Module: {2} - ", moduleName, configLoaderType, moduleType); if (isAmd.HasValue) { if (isAmd.Value) { Assert.AreEqual(0, cjs.Count, message + "cjs list should be empty"); Assert.AreEqual(1, amd.Count, message + "amd list should contain one element"); Assert.Contains(moduleName, amd, message + "amd list should countain the module name"); } else { Assert.AreEqual(0, amd.Count, message + ":amd list should be empty"); Assert.AreEqual(1, cjs.Count, message + ":cjs list should contain one element"); Assert.Contains(moduleName, cjs, message + ":cjs list should countain the module name"); } } else { Assert.AreEqual(0, amd.Count, message + ":amd list should be empty"); Assert.AreEqual(0, cjs.Count, message + ":cjs list should be empty"); } }
private static InlineArgumentsBlock GetInlineArgumentsBlock(ModuleLoaderType moduleType) { var emitter = EmitterHelper.GetEmitter( assemblyInfo: new AssemblyInfo() { Loader = new ModuleLoader { Type = moduleType } } ); var info = new ArgumentsInfo(emitter, new string[] { }); var block = new InlineArgumentsBlock(emitter, info, null); return(block); }
public void ShouldAddCommonJSModuleTests(string moduleName, ModuleLoaderType configLoaderType, ModuleType moduleType) { AssertModule(moduleName, configLoaderType, moduleType, false); }
public void ShouldAddAmdModuleTests(string moduleName, ModuleLoaderType configLoaderType, ModuleType moduleType) { AssertModule(moduleName, configLoaderType, moduleType, true); }
public void ShouldNotAddModuleTests(string moduleName, ModuleLoaderType configLoaderType, ModuleType?moduleType) { AssertModule(moduleName, configLoaderType, moduleType, null); }
/// <summary> Specifies how to export the module </summary> public JsGenerator UseModuleType(ModuleLoaderType type) { this.ModuleType = type; return(this); }
/// <summary> Generates JavaScript code. </summary> public JsGenerator() { ModuleType = ModuleLoaderType.Autodetect; VariableName = "api"; }