Skip to content

Commit

Permalink
reinforced#71 fix most mono incompatibilities
Browse files Browse the repository at this point in the history
fix spellings in code and comments

add stub to settings to prevent missing parameter error
  • Loading branch information
PandaWood committed Oct 6, 2018
1 parent 5773dc7 commit 17b60b8
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 71 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -210,3 +210,5 @@ docplan.txt
/Reinforced.Typings/Reinforced.snk
/Reinforced.Typings.Cli/Reinforced.snk
/Reinforced.Typings.Integrate/Reinforced.snk

\.idea/
14 changes: 7 additions & 7 deletions Reinforced.Typings.Cli/Bootstrapper.cs
Expand Up @@ -61,7 +61,7 @@ public static class Bootstrapper
/// <param name="args"></param>
public static void Main(string[] args)
{
Console.WriteLine("Reinforced.Typings CLI generator (c) 2015 by Pavel B. Novikov");
Console.WriteLine("Reinforced.Typings CLI generator (c) 2015-2018 by Pavel B. Novikov");

if (args.Length == 0)
{
Expand Down Expand Up @@ -240,7 +240,7 @@ private static string LookupAssemblyPathInternal(string assemblyNameOrFullPath,
{
if (storeIfFullName)
{
var lastAssemblyLocalDir = Path.GetDirectoryName(assemblyNameOrFullPath) + "\\";
var lastAssemblyLocalDir = Path.GetDirectoryName(assemblyNameOrFullPath) + Path.DirectorySeparatorChar;
if (!_allAssembliesDirs.Contains(lastAssemblyLocalDir)) _allAssembliesDirs.Add(lastAssemblyLocalDir);
}
#if DEBUG
Expand Down Expand Up @@ -397,14 +397,14 @@ public static void PrintHelp()
string requiredText = null;
switch (req)
{
case Required.NotReuired:
requiredText = "(not requred)";
case Required.Not:
requiredText = "(not required)";
break;
case Required.Reuired:
requiredText = "(requred)";
case Required.Is:
requiredText = "(required)";
break;
case Required.Partially:
requiredText = "(sometimes requred)";
requiredText = "(sometimes required)";
break;
}
Console.WriteLine(propertyInfo.Name + " " + requiredText);
Expand Down
6 changes: 3 additions & 3 deletions Reinforced.Typings.Cli/ConsoleHelpAttribute.cs
Expand Up @@ -15,7 +15,7 @@ public class ConsoleHelpAttribute : Attribute
public Required RequiredType { get; set; }


public ConsoleHelpAttribute(string helpText,Required requiredType = Required.NotReuired)
public ConsoleHelpAttribute(string helpText,Required requiredType = Required.Not)
{
HelpText = helpText;
RequiredType = requiredType;
Expand All @@ -24,8 +24,8 @@ public ConsoleHelpAttribute(string helpText,Required requiredType = Required.Not

public enum Required
{
Reuired,
NotReuired,
Is,
Not,
Partially
}
}
14 changes: 7 additions & 7 deletions Reinforced.Typings.Cli/ExporterConsoleParameters.cs
Expand Up @@ -16,9 +16,9 @@ public class ExporterConsoleParameters
/// The assemblies to extract typings from
/// </summary>
[ConsoleHelp(@"
The semicolon-separated assemblies list to extract typings from.
The semicolon-separated assembly list to extract typings from.
Example: rtcli.exe SourceAssemblies=""C:\TestProject\Assembly1.dll;C:\TestProject\Assembly2.dll""
", Required.Reuired)]
", Required.Is)]
public string[] SourceAssemblies { get; set; }

/// <summary>
Expand All @@ -27,18 +27,18 @@ public class ExporterConsoleParameters
/// </summary>
[ConsoleHelp(@"
Target file where to store generated sources.
Not required if Hirarchy=""true"" specified. Otherwise required.
Not required if Hierarchy=""true"" is specified. Otherwise required.
Example: rtcli.exe TargetFile=""C:\path\to\target\file.ts""", Required.Partially)]
public string TargetFile { get; set; }

/// <summary>
/// Target directory where to store generated typing files.
/// This parameter is not used when Hierarcy is false
/// This parameter is not used when Hierarchy is false
/// </summary>
[ConsoleHelp(@"
Target directory where to store generated typing files.
Not required if Hirarchy=""false"" or not specified. Otherwise required.
Example: rtcli.exe TargetDirectory=""C:\path\to\project\"" (regardless ending slash)", Required.Partially)]
Not required if Hierarchy=""false"" is not specified. Otherwise required.
Example: rtcli.exe TargetDirectory=""C:\path\to\project\"" (ending slash optional)", Required.Partially)]
public string TargetDirectory { get; set; }

/// <summary>
Expand Down Expand Up @@ -100,7 +100,7 @@ public void Validate()
throw new Exception("Target directory must be specified in case of hierarchy generation");

if (SourceAssemblies == null || SourceAssemblies.Length == 0)
throw new Exception("Source assemblies is not specified. Nothing to export");
throw new Exception("No source assemblies specified. Nothing to export");
}

public ExporterConsoleParameters()
Expand Down
2 changes: 1 addition & 1 deletion Reinforced.Typings.Tests/BasicTypesResolvationTests.cs
Expand Up @@ -26,7 +26,7 @@ public BasicTypesResolvationTests()
_context = new ExportContext()
{
SourceAssemblies = new[] { Assembly.GetExecutingAssembly() },
TargetDirectory = "D:\\"
TargetDirectory = "targetDir/"
};
var exporter = new TsExporter(_context);
exporter.Initialize();
Expand Down
8 changes: 6 additions & 2 deletions Reinforced.Typings.Tests/ClassicMultiFileResolvationTests.cs
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -23,7 +24,7 @@ protected ExportedFile Setup2Files(string filePath1, string filePath2, Action<Co
a.ExportAsInterface<TestFluentAssembly.TwoInterfaces.IInterface2>().ExportTo(filePath2);
});

return setup.Exporter.SetupExportedFile("D:\\" + filePath1);
return setup.Exporter.SetupExportedFile(Path.Combine(TargetDir, filePath1));
}

[Fact]
Expand All @@ -43,6 +44,7 @@ public void SimpleModuleResolvationTestSingleDir()
{
var file = Setup2Files("File1.ts", "File2.ts", x => x.Global(a => a.UseModules()));

//todo this fails in mono, the Prefix property of this below is "" - but Prefix of one below is null
var typeName = file.TypeResolver.ResolveTypeName(typeof(TestFluentAssembly.TwoInterfaces.IInterface2));

Assert.Equal(new RtSimpleTypeName("IInterface2"), typeName, _comparer);
Expand Down Expand Up @@ -81,11 +83,13 @@ public void SimpleReferenceResolvationTestDifferentDirs()
Assert.Equal("Another/File2.ts", rf.Path);
}


[Fact]
public void SimpleModuleResolvationTestDifferentDirs()
{
var file = Setup2Files("File1.ts", "Another/File2.ts", x => x.Global(a => a.UseModules()));

//todo this fails in mono, the Prefix property of this below is "" - but Prefix of one below is null
var typeName = file.TypeResolver.ResolveTypeName(typeof(TestFluentAssembly.TwoInterfaces.IInterface2));

Assert.Equal(new RtSimpleTypeName("IInterface2"), typeName, _comparer);
Expand Down
5 changes: 3 additions & 2 deletions Reinforced.Typings.Tests/ConfigurationBuilderTestBase.cs
Expand Up @@ -11,6 +11,7 @@ namespace Reinforced.Typings.Tests
{
public abstract class ConfigurationBuilderTestBase
{
protected const string TargetDir = "targetDir";
protected const string Sample = "target.ts";

protected TestInitializationData InitializeSingleFile(Action<ConfigurationBuilder> configuration)
Expand All @@ -22,7 +23,7 @@ protected TestInitializationData InitializeSingleFile(Action<ConfigurationBuilde
ConfigurationMethod = configuration,
Hierarchical = false,
SourceAssemblies = new Assembly[] { Assembly.GetExecutingAssembly(), typeof(TestFluentAssembly.TwoInterfaces.IInterface1).Assembly },
TargetDirectory = "D:\\",
TargetDirectory = TargetDir,
TargetFile = Sample
};
TsExporter te = new TsExporter(ec);
Expand All @@ -39,7 +40,7 @@ protected TestInitializationData InitializeMultipleFiles(Action<ConfigurationBui
ConfigurationMethod = configuration,
Hierarchical = true,
SourceAssemblies = new Assembly[] { Assembly.GetExecutingAssembly(), typeof(TestFluentAssembly.TwoInterfaces.IInterface1).Assembly },
TargetDirectory = "D:\\"
TargetDirectory = TargetDir
};
TsExporter te = new TsExporter(ec);
te.Initialize();
Expand Down
Expand Up @@ -44,6 +44,9 @@ public partial class SpecificTestCases
[Fact]
public void ConstantProperties()
{
// NB this test fails on Mono because the Members property of RtClass does not
// order the tokens in the same order as the CLR on Windows (ie it's CLR-specific, relying on a certain order)
// (Similar to the way that the order of attributes in C# code is CLR-dependent and shouldn't be relied on)
const string result = @"
module Test {
export enum ExportedEnum {
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using Reinforced.Typings.Fluent;
using Xunit;

Expand Down Expand Up @@ -54,11 +55,11 @@ public void ReferencesPart1()
;
s.ExportAsClass<SomeIndirectlyReferencedClass>().ExportTo("Indirect/File2.ts");
s.ExportAsClass<SomeFluentReferencedType>().ExportTo("Fluently/File3.ts");
}, new Dictionary<string, string>()
}, new Dictionary<string, string>
{
{"D:\\Exported\\File1.ts", file1},
{"D:\\Indirect\\File2.ts", file2},
{"D:\\Fluently\\File3.ts", file3},
{ Path.Combine(TargetDir, "Exported", "File1.ts"), file1 },
{ Path.Combine(TargetDir, "Indirect", "File2.ts"), file2 },
{ Path.Combine(TargetDir, "Fluently", "File3.ts"), file3 }
}, compareComments: true);
}
}
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using Reinforced.Typings.Fluent;
using Xunit;

Expand Down Expand Up @@ -57,11 +58,11 @@ public void ReferencesPart2()
;
s.ExportAsClass<SomeIndirectlyReferencedClass>().ExportTo("Indirect/File2.ts");
s.ExportAsClass<SomeFluentReferencedType>().ExportTo("Fluently/File3.ts");
}, new Dictionary<string, string>()
}, new Dictionary<string, string>
{
{"D:\\Exported\\File1.ts", file1},
{"D:\\Indirect\\File2.ts", file2},
{"D:\\Fluently\\File3.ts", file3},
{ Path.Combine(TargetDir, "Exported", "File1.ts"), file1 },
{ Path.Combine(TargetDir, "Indirect", "File2.ts"), file2 },
{ Path.Combine(TargetDir, "Fluently", "File3.ts"), file3 }
}, compareComments: true);
}
}
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using Reinforced.Typings.Fluent;
using Xunit;

Expand Down Expand Up @@ -70,11 +71,11 @@ public void ReferencesPart3()
;
s.ExportAsClass<SomeIndirectlyReferencedClass>().ExportTo("Indirect/File2.ts");
s.ExportAsClass<SomeFluentReferencedType>().ExportTo("Fluently/File3.ts");
}, new Dictionary<string, string>()
}, new Dictionary<string, string>
{
{"D:\\Exported\\File1.ts", file1},
{"D:\\Indirect\\File2.ts", file2},
{"D:\\Fluently\\File3.ts", file3},
{ Path.Combine(TargetDir, "Exported", "File1.ts"), file1 },
{ Path.Combine(TargetDir, "Indirect", "File2.ts"), file2 },
{ Path.Combine(TargetDir, "Fluently", "File3.ts"), file3 }
}, compareComments: true);
}
}
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using Reinforced.Typings.Fluent;
using Xunit;

Expand Down Expand Up @@ -59,10 +60,10 @@ public void ReferencesPart4()
;
s.ExportAsClass<SomeIndirectlyReferencedClass>().ExportTo("Stuff/Stuff.ts");
s.ExportAsClass<SomeFluentReferencedType>().ExportTo("Stuff/Stuff.ts");
}, new Dictionary<string, string>()
}, new Dictionary<string, string>
{
{"D:\\Exported\\File1.ts", file1},
{"D:\\Stuff\\Stuff.ts", file2},
{ Path.Combine(TargetDir, "Exported", "File1.ts"), file1},
{ Path.Combine(TargetDir, "Stuff", "Stuff.ts"), file2}
}, compareComments: true);
}
}
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using Reinforced.Typings.Fluent;
using Xunit;

Expand Down Expand Up @@ -69,10 +70,10 @@ public void ReferencesPart5()
s.ExportAsClass<SomeIndirectlyReferencedClass>().ExportTo("Stuff/Stuff.ts");
s.ExportAsClass<SomeFluentReferencedType>().DontIncludeToNamespace().ExportTo("Stuff/Stuff.ts");
s.ExportAsEnum<SomeIndirectEnum>().DontIncludeToNamespace().ExportTo("Stuff/Stuff.ts");
}, new Dictionary<string, string>()
}, new Dictionary<string, string>
{
{"D:\\Exported\\File1.ts", file1},
{"D:\\Stuff\\Stuff.ts", file2},
{ Path.Combine(TargetDir, "Exported", "File1.ts"), file1},
{ Path.Combine(TargetDir, "Stuff", "Stuff.ts"), file2}
}, compareComments: true);
}
}
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.IO;
using Reinforced.Typings.Fluent;
using Xunit;

Expand Down Expand Up @@ -36,10 +37,10 @@ public void ReferencesPart6ByDanielWest()
s.ExportAsEnum<SomeEnum>().ExportTo("Areas/APIv2/Models/TimeAndAttendance/Enum.ts");
s.ExportAsClass<SomeViewModel>().WithPublicProperties().ExportTo("Areas/Reporting/Models/Model.ts");
}, new Dictionary<string, string>()
}, new Dictionary<string, string>
{
{"D:\\Areas\\APIv2\\Models\\TimeAndAttendance\\Enum.ts", file1},
{"D:\\Areas\\Reporting\\Models\\Model.ts", file2},
{ Path.Combine(TargetDir, "Areas", "APIv2", "Models", "TimeAndAttendance", "Enum.ts"), file1 },
{ Path.Combine(TargetDir, "Areas", "Reporting", "Models", "Model.ts"), file2 }
}, compareComments: true);
}
}
Expand Down
7 changes: 4 additions & 3 deletions Reinforced.Typings.Tests/Tokenizing/SimpleTokenizer.cs
Expand Up @@ -7,9 +7,10 @@ namespace Reinforced.Typings.Tests.Tokenizing
{
sealed class SimpleTokenizer
{
private const string CommentSyntax = "//";
private const string TokenSeparators = ".,;:{[()]}=,+-/*%@!&|";
private readonly TextReader _reader;
private readonly bool _tokenizeComments;
private const string TokenSeparators = ".,;:{[()]}=,+-/*%@!&|";
private bool _inComment;
private readonly StringBuilder _buffer = new StringBuilder();

Expand All @@ -26,7 +27,7 @@ public IEnumerable<string> Tokenize()
{
foreach (var token in TokenizeLine(line))
{
if (!_tokenizeComments&&token.StartsWith("//")) continue;
if (!_tokenizeComments && token.StartsWith(CommentSyntax)) continue;
yield return token;
}
line = _reader.ReadLine();
Expand All @@ -44,7 +45,7 @@ private IEnumerable<string> TokenizeLine(string s)
bool readingToken = false;
for (int i = 0; i < s.Length; i++)
{
if (Ahead(s, "//", i))
if (Ahead(s, CommentSyntax, i))
{
if (_buffer.Length > 0) yield return _buffer.ToString();
_buffer.Clear();
Expand Down
4 changes: 3 additions & 1 deletion Reinforced.Typings/Ast/RtClass.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Reinforced.Typings.Ast.TypeNames;

namespace Reinforced.Typings.Ast
Expand All @@ -24,7 +25,7 @@ public class RtClass : RtCompilationUnit, ITypeMember, IDecoratable
public RtTypeName Extendee { get; set; }

/// <inheritdoc />
public List<RtNode> Members { get; private set; }
public List<RtNode> Members { get; private set; } //todo this needs to be sorted to be cross-platform, it's returning different order for Mono

/// <summary>
/// Constructs new instance of AST node
Expand Down Expand Up @@ -53,6 +54,7 @@ public override IEnumerable<RtNode> Children
{
yield return implementee;
}

yield return Extendee;
foreach (var rtMember in Members)
{
Expand Down
2 changes: 0 additions & 2 deletions Reinforced.Typings/ExportContext.cs
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Reinforced.Typings.Attributes;
using Reinforced.Typings.Exceptions;
using Reinforced.Typings.Fluent;
using Reinforced.Typings.Fluent.Interfaces;
using Reinforced.Typings.Xmldoc;

namespace Reinforced.Typings
Expand Down
2 changes: 1 addition & 1 deletion Reinforced.Typings/Generators/NamespaceCodeGenerator.cs
Expand Up @@ -33,7 +33,7 @@ public virtual RtNamespace Generate(IEnumerable<Type> types, string namespaceNam
foreach (var type in types)
{
var converter = Context.Generators.GeneratorFor(type, Context);
if (converter==null) continue;
if (converter == null) continue;
var member = converter.Generate(type, resolver);
var m = member as RtCompilationUnit;
if (m != null)
Expand Down

0 comments on commit 17b60b8

Please sign in to comment.