本文整理汇总了C#中MockErrorReporter类的典型用法代码示例。如果您正苦于以下问题:C# MockErrorReporter类的具体用法?C# MockErrorReporter怎么用?C# MockErrorReporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockErrorReporter类属于命名空间,在下文中一共展示了MockErrorReporter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Compile
internal Tuple<string, ICompilation, IMetadataImporter, MockErrorReporter> Compile(string source, bool includeLinq = false, bool expectErrors = false)
{
var sourceFile = new MockSourceFile("file.cs", source);
var md = new MetadataImporter.ScriptSharpMetadataImporter(false);
var n = new DefaultNamer();
var er = new MockErrorReporter(!expectErrors);
PreparedCompilation compilation = null;
var rtl = new ScriptSharpRuntimeLibrary(md, er, n.GetTypeParameterName, tr => { var t = tr.Resolve(compilation.Compilation).GetDefinition(); return new JsTypeReferenceExpression(t.ParentAssembly, md.GetTypeSemantics(t).Name); });
var compiler = new Compiler.Compiler(md, n, rtl, er);
var references = includeLinq ? new[] { Common.Mscorlib, Common.Linq } : new[] { Common.Mscorlib };
compilation = compiler.CreateCompilation(new[] { sourceFile }, references, null);
var compiledTypes = compiler.Compile(compilation);
if (expectErrors) {
Assert.That(er.AllMessages, Is.Not.Empty, "Compile should have generated errors");
return Tuple.Create((string)null, compilation.Compilation, (IMetadataImporter)md, er);
}
er.AllMessagesText.Should().BeEmpty("Compile should not generate errors");
var js = new OOPEmulator.ScriptSharpOOPEmulator(md, rtl, er).Rewrite(compiledTypes, compilation.Compilation);
js = new GlobalNamespaceReferenceImporter().ImportReferences(js);
string script = string.Join("", js.Select(s => OutputFormatter.Format(s, allowIntermediates: false)));
if (Output == OutputType.GeneratedScript)
Console.WriteLine(script);
return Tuple.Create(script, compilation.Compilation, (IMetadataImporter)md, er);
}
开发者ID:qiaojie,项目名称:SaltarelleCompiler,代码行数:30,代码来源:RuntimeLibraryTestBase.cs
示例2: CannotUseNotUsableTypeAsAGenericArgument
public void CannotUseNotUsableTypeAsAGenericArgument()
{
var nc = new MockMetadataImporter { GetTypeSemantics = t => t.Name == "C1" ? TypeScriptSemantics.NotUsableFromScript() : TypeScriptSemantics.NormalType(t.Name) };
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
class C {
public void F1<T>() {}
public void M() {
F1<C1>();
}
}" }, metadataImporter: nc, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("generic argument") && er.AllMessagesText[0].Contains("C1") && er.AllMessagesText[0].Contains("F1"));
er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
interface I1<T> {}
class C {
public void F1<T>() {}
public void M() {
F1<I1<I1<C1>>>();
}
}" }, metadataImporter: nc, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("generic argument") && er.AllMessagesText[0].Contains("C1") && er.AllMessagesText[0].Contains("F1"));
}
开发者ID:koczkatamas,项目名称:SaltarelleCompiler,代码行数:30,代码来源:InvocationTests.cs
示例3: AssigningToFieldImplementedAsConstantIsAnError
public void AssigningToFieldImplementedAsConstantIsAnError()
{
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C {
public int F1;
public void M() {
// BEGIN
F1 = 1;
// END
}
}" }, namingConvention: new MockNamingConventionResolver { GetFieldSemantics = f => f.Name == "F1" ? FieldScriptSemantics.NullConstant() : FieldScriptSemantics.Field(f.Name) }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText.Any(m => m.Contains("C.F1") && m.Contains("cannot be assigned to")));
er = new MockErrorReporter(false);
Compile(new[] {
@"class C {
public int F1;
public void M() {
// BEGIN
F1 += 1;
// END
}
}" }, namingConvention: new MockNamingConventionResolver { GetFieldSemantics = f => f.Name == "F1" ? FieldScriptSemantics.NullConstant() : FieldScriptSemantics.Field(f.Name) }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText.Any(m => m.Contains("C.F1") && m.Contains("cannot be assigned to")));
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:30,代码来源:MemberAccessTests.cs
示例4: CanCompileAsyncTaskGenericMethod
public void CanCompileAsyncTaskGenericMethod()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File1.cs"), @"
using System.Threading.Tasks;
public class C1 {
public async Task<int> M() {
var t = new Task(() => {});
await t;
return 0;
}
}");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File1.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
}, "File1.cs", "Test.dll", "Test.js");
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:27,代码来源:DriverTests.cs
示例5: ChangingTheWarningLevelWorks
public void ChangingTheWarningLevelWorks()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0l; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js"),
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(er.AllMessages.Select(m => m.Code).ToList(), Is.EquivalentTo(new[] { 219, 78 }));
}, "File.cs", "Test.dll", "Test.js");
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0l; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js"),
WarningLevel = 3,
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(er.AllMessages.Select(m => m.Code), Is.EqualTo(new[] { 219 }));
}, "File.cs", "Test.dll", "Test.js");
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:35,代码来源:DriverTests.cs
示例6: AnErrorIsIssuedIfTheMainMethodIsNotImplementedAsANormalMethod
public void AnErrorIsIssuedIfTheMainMethodIsNotImplementedAsANormalMethod()
{
var type = CreateMockTypeDefinition("MyClass");
var main = new Mock<IMethod>(MockBehavior.Strict);
main.SetupGet(_ => _.DeclaringTypeDefinition).Returns(type);
main.SetupGet(_ => _.Name).Returns("Main");
main.SetupGet(_ => _.FullName).Returns("MyClass.Main");
main.SetupGet(_ => _.Parameters).Returns(EmptyList<IParameter>.Instance);
main.SetupGet(_ => _.Region).Returns(DomRegion.Empty);
var er = new MockErrorReporter();
Process(
new[] {
new JsClass(type, JsClass.ClassTypeEnum.Class, null, null, null) {
StaticMethods = { new JsMethod(main.Object, "$Main", new string[0], JsExpression.FunctionDefinition(new string[0], new JsExpressionStatement(JsExpression.Identifier("X")))) }
}
},
new MockScriptSharpMetadataImporter() { GetMethodSemantics = m => ReferenceEquals(m, main.Object) ? MethodScriptSemantics.InlineCode("X") : MethodScriptSemantics.NormalMethod("$" + m.Name) },
er,
main.Object
);
Assert.That(er.AllMessages, Has.Count.EqualTo(1));
Assert.That(er.AllMessages.Any(m => m.Code == 7801 && (string)m.Args[0] == "MyClass.Main"));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:26,代码来源:OverallStructureTests.cs
示例7: CannotUseNotUsableTypeInATypeOfExpression
public void CannotUseNotUsableTypeInATypeOfExpression()
{
var metadataImporter = new MockMetadataImporter { GetTypeSemantics = t => t.Name == "C1" ? TypeScriptSemantics.NotUsableFromScript() : TypeScriptSemantics.NormalType(t.Name) };
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
class C {
public void M() {
var t = typeof(C1);
}
}" }, metadataImporter: metadataImporter, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("typeof") && er.AllMessagesText[0].Contains("C1"));
er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {}
interface I1<T> {}
class C {
public void M() {
var t= typeof(I1<I1<C1>>);
}
}" }, metadataImporter: metadataImporter, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("not usable from script") && er.AllMessagesText[0].Contains("typeof") && er.AllMessagesText[0].Contains("C1"));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:28,代码来源:TypeOfTests.cs
示例8: AssertCorrect
private void AssertCorrect(string code, string feature)
{
var er = new MockErrorReporter();
Compile(new[] { code }, errorReporter: er, allowUnsupportedConstructs: false);
Assert.That(er.AllMessages.Count, Is.EqualTo(1));
Assert.That(er.AllMessages[0].Code, Is.EqualTo(7998));
Assert.That(er.AllMessages[0].Args[0], Is.EqualTo(feature));
}
开发者ID:dested,项目名称:SaltarelleCompiler,代码行数:8,代码来源:UnsupportedConstructsScannerTests.cs
示例9: ConstructorsAreReportedAsJsonConstructors
public void ConstructorsAreReportedAsJsonConstructors()
{
var compilation = new SimpleCompilation(new CSharpProjectContent());
var md = new MetadataImporter.ScriptSharpMetadataImporter(false);
var er = new MockErrorReporter(true);
md.Prepare(new ITypeDefinition[0], compilation.MainAssembly, er);
Assert.That(er.AllMessagesText, Is.Empty, "Prepare should not generate errors");
var t = CreateType(compilation);
var c = md.GetConstructorSemantics(DefaultResolvedMethod.GetDummyConstructor(compilation, t));
Assert.That(c.Type, Is.EqualTo(ConstructorScriptSemantics.ImplType.Json));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:13,代码来源:AnonymousTypeTests.cs
示例10: Process
protected string Process(IEnumerable<JsType> types, IScriptSharpMetadataImporter metadataImporter = null)
{
metadataImporter = metadataImporter ?? new MockScriptSharpMetadataImporter();
IProjectContent proj = new CSharpProjectContent();
proj = proj.AddAssemblyReferences(new[] { Common.Mscorlib });
var comp = proj.CreateCompilation();
var er = new MockErrorReporter(true);
var obj = new OOPEmulator.ScriptSharpOOPEmulator(metadataImporter, er);
Assert.That(er.AllMessages, Is.Empty, "Should not have errors");
var rewritten = obj.Rewrite(types, comp);
return string.Join("", rewritten.Select(s => OutputFormatter.Format(s, allowIntermediates: true)));
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:13,代码来源:ScriptSharpOOPEmulatorTestBase.cs
示例11: TransparentIdentiferIsValidJavascriptIdentifierStartingWithDollar
public void TransparentIdentiferIsValidJavascriptIdentifierStartingWithDollar()
{
var compilation = new SimpleCompilation(new CSharpProjectContent());
var md = new MetadataImporter.ScriptSharpMetadataImporter(false);
var er = new MockErrorReporter(true);
md.Prepare(new ITypeDefinition[0], compilation.MainAssembly, er);
Assert.That(er.AllMessagesText, Is.Empty, "Prepare should not generate errors");
var t = CreateType(compilation, new[] { "<>Identifier" });
var c = md.GetPropertySemantics(t.GetProperties().Single());
Assert.That(c.Type, Is.EqualTo(PropertyScriptSemantics.ImplType.Field));
Assert.That(c.FieldName, Is.EqualTo("$Identifier"));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:14,代码来源:AnonymousTypeTests.cs
示例12: CannotAccessExpandedParamsParameter
public void CannotAccessExpandedParamsParameter()
{
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {
public void M(int i, int j, params int[] myParamArray) {
int x = myParamArray[3];
}
}" }, metadataImporter: new MockMetadataImporter { GetMethodSemantics = m => MethodScriptSemantics.NormalMethod("$" + m.Name, expandParams: true) }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("myParamArray") && er.AllMessagesText[0].Contains("expand") && er.AllMessagesText[0].Contains("param array"));
}
开发者ID:tml,项目名称:SaltarelleCompiler,代码行数:14,代码来源:ThisTests.cs
示例13: CannotPerformMethodGroupConversionOnMethodThatExpandsParams
public void CannotPerformMethodGroupConversionOnMethodThatExpandsParams()
{
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C1 {
public void F(int x, int y, params int[] args) {}
public void M() {
System.Action<int, int, int[]> a = F;
}
}" }, namingConvention: new MockNamingConventionResolver { GetMethodSemantics = m => MethodScriptSemantics.NormalMethod("$" + m.Name, expandParams: m.Name == "F") }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("C1.F") && er.AllMessagesText[0].Contains("expand") && er.AllMessagesText[0].Contains("param array"));
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:15,代码来源:MethodGroupConversionTests.cs
示例14: CannotAccessExpandedParamsParameterInExpressionLambda
public void CannotAccessExpandedParamsParameterInExpressionLambda()
{
var er = new MockErrorReporter();
Compile(new[] {
@"public delegate int F(int x, int y, params int[] args);
public class C {
public void M() {
F f = (a, b, myParamArray) => myParamArray[1];
}
}" }, metadataImporter: new MockMetadataImporter { GetDelegateSemantics = d => new DelegateScriptSemantics(expandParams: true) }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText[0].Contains("myParamArray") && er.AllMessagesText[0].Contains("expand") && er.AllMessagesText[0].Contains("param array"));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:15,代码来源:LocalsTests.cs
示例15: CanCompileProject
public void CanCompileProject()
{
var opts = ReadProject(@"C:\Projects\EngineGit\Project\Search\Search.Client\Search.Client.csproj", @"C:\Projects\EngineGit\Project");
opts.DefineConstants.Add("CLIENT");
try {
var er = new MockErrorReporter();
var d = new CompilerDriver(er);
bool result = d.Compile(opts, false);
Assert.That(result, Is.True);
Assert.That(er.AllMessages, Is.Empty);
}
finally {
try { File.Delete(Path.GetFullPath("output.dll")); } catch {}
try { File.Delete(Path.GetFullPath("output.js")); } catch {}
}
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:16,代码来源:EndToEndCompilation.cs
示例16: CanCompileMscorlib
public void CanCompileMscorlib()
{
var opts = ReadProject(Path.GetFullPath(@"..\..\..\Runtime\src\Libraries\CoreLib\CoreLib.csproj"));
try {
var er = new MockErrorReporter();
var d = new CompilerDriver(er);
bool result = d.Compile(opts, false);
Assert.That(result, Is.True);
Assert.That(er.AllMessages, Is.Empty);
}
finally {
try { File.Delete(Path.GetFullPath("output.dll")); } catch {}
try { File.Delete(Path.GetFullPath("output.js")); } catch {}
}
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:16,代码来源:EndToEndCompilation.cs
示例17: InlineCodeWithSyntaxErrorIsAnError
public void InlineCodeWithSyntaxErrorIsAnError()
{
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C {
public void F(string p1, int p2, params string[] p3) {}
public void M() {
string[] args = null;
// BEGIN
F(""x"", 1, ""y"", ""z"");
// END
}
}" }, metadataImporter: new MockMetadataImporter { GetMethodSemantics = m => m.Name == "F" ? MethodScriptSemantics.InlineCode("{p1}*{p2}+") : MethodScriptSemantics.NormalMethod(m.Name) }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText.Any(m => m.Contains("syntax error")));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:17,代码来源:InlineCodeMethodCompilerTests.cs
示例18: CanInitializeListWithCollectionInitializer
public void CanInitializeListWithCollectionInitializer()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("Test.cs"), @"using System.Collections.Generic; public class C1 { public void M() { var l = new List<int> { 1 }; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("Test.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True, "Compilation failed with " + string.Join(Environment.NewLine, er.AllMessagesText));
}, "File1.cs", "Test.dll", "Test.js");
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:17,代码来源:DriverTests.cs
示例19: InvokingMethodWithExpandedParamArrayInNonExpandedFormIsAnError
public void InvokingMethodWithExpandedParamArrayInNonExpandedFormIsAnError()
{
var er = new MockErrorReporter(false);
Compile(new[] {
@"class C {
public void F(string p1, int p2, params string[] p3) {}
public void M() {
string[] args = null;
// BEGIN
F(""x"", 1, new[] { ""y"", ""z"" });
// END
}
}" }, metadataImporter: new MockMetadataImporter { GetMethodSemantics = m => m.Name == "F" ? MethodScriptSemantics.InlineCode("{p1}*{p2}({*p3})") : MethodScriptSemantics.NormalMethod(m.Name) }, errorReporter: er);
Assert.That(er.AllMessagesText.Count, Is.EqualTo(1));
Assert.That(er.AllMessagesText.Any(m => m.Contains("C.F") && m.Contains("expanded")));
}
开发者ID:JimmyJune,项目名称:SaltarelleCompiler,代码行数:17,代码来源:InlineCodeMethodCompilerTests.cs
示例20: InvokingMethodWithExpandedParamArrayWithCommaBeforeWorks
public void InvokingMethodWithExpandedParamArrayWithCommaBeforeWorks()
{
var er = new MockErrorReporter(false);
AssertCorrect(
@"public void F(string p1, int p2, params string[] p3) {}
public void M() {
// BEGIN
F(""x"", 4);
F(""x"", 4, ""y"");
F(""x"", 4, ""y"", ""z"");
// END
}",
@" [ 'x', 4 ];
[ 'x', 4, 'y' ];
[ 'x', 4, 'y', 'z' ];
", namingConvention: new MockNamingConventionResolver { GetMethodSemantics = m => m.Name == "F" ? MethodScriptSemantics.InlineCode("[ {p1}, {p2}{,p3} ]") : MethodScriptSemantics.NormalMethod(m.Name) });
}
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:17,代码来源:InlineCodeMethodCompilerTests.cs
注:本文中的MockErrorReporter类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论