Skip to content

Commit

Permalink
Merge pull request #89 from PandaWood/mono-clean
Browse files Browse the repository at this point in the history
#71 fix some mono incompatibilities
  • Loading branch information
pavel-b-novikov committed Oct 14, 2018
2 parents e230727 + 3e707a2 commit fffff35
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -211,3 +211,5 @@ docplan.txt
/Reinforced.Typings/Reinforced.snk
/Reinforced.Typings.Cli/Reinforced.snk
/Reinforced.Typings.Integrate/Reinforced.snk

\.idea/
4 changes: 2 additions & 2 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
2 changes: 1 addition & 1 deletion Reinforced.Typings.Cli/ExporterConsoleParameters.cs
Expand Up @@ -33,7 +33,7 @@ public class ExporterConsoleParameters

/// <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 to store generated typing files.
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
4 changes: 2 additions & 2 deletions Reinforced.Typings/Generators/PropertyCodeGenerator.cs
Expand Up @@ -125,7 +125,7 @@ protected virtual void FillInitialization(MemberInfo element, RtField result, Ty
{
var val = GetStaticValue(element);
if (val == null) result.InitializationExpression = "null";
else result.InitializationExpression = ((bool)val) ? "true" : "false";
else result.InitializationExpression = (bool)val ? "true" : "false";
}

if (memberType == typeof(string))
Expand Down Expand Up @@ -162,7 +162,7 @@ protected virtual void FillInitialization(MemberInfo element, RtField result, Ty
}
}

if (attr != null && attr.InitializerEvaluator != null)
if (attr?.InitializerEvaluator != null)
{
var val = element.IsStatic() ? GetStaticValue(element) : null;
result.InitializationExpression = attr.InitializerEvaluator(element, resolver, val);
Expand Down
16 changes: 7 additions & 9 deletions Reinforced.Typings/ReferencesInspection/ReferenceInspector.cs
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -118,7 +118,7 @@ public string GetPathForType(Type t, bool stripExtension = true)
if (fromConfiguration.EndsWith(".ts"))
fromConfiguration = fromConfiguration.Substring(0, fromConfiguration.Length - 3);
}
var r = Path.Combine(_context.TargetDirectory, fromConfiguration.Replace("/", "\\")).Replace("/", "\\");
var r = Path.Combine(_context.TargetDirectory, fromConfiguration);
return r;
}

Expand All @@ -138,7 +138,7 @@ public string GetPathForType(Type t, bool stripExtension = true)
{
ns = ns.Replace(_context.Global.RootNamespace, string.Empty);
}
ns = ns.Trim('.').Replace('.', '\\');
ns = ns.Trim('.').Replace('.', Path.DirectorySeparatorChar);

var pth =
Path.Combine(
Expand All @@ -163,7 +163,6 @@ private string GetRelativePathForType(Type typeToReference, string currentFile)
Path.GetDirectoryName(desiredFile));

relPath = Path.Combine(relPath, desiredFileName);
relPath = relPath.Replace('\\', '/');
if (_context.Global.UseModules)
{
if (!relPath.StartsWith(".")) relPath = "./" + relPath;
Expand All @@ -177,14 +176,13 @@ private string GetRelativeNamespacePath(string currentNamespace, string desiredN
if (currentNamespace == desiredNamespace) return string.Empty;
if (string.IsNullOrEmpty(currentNamespace)) return desiredNamespace;


var current = currentNamespace.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
var desired = desiredNamespace.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
var current = currentNamespace.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
var desired = desiredNamespace.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

var result = new StringBuilder();
if (string.IsNullOrEmpty(desiredNamespace))
{
for (var i = 0; i < current.Length; i++) result.Append("..\\");
for (var i = 0; i < current.Length; i++) result.Append("../");
}
else
{
Expand All @@ -205,7 +203,7 @@ private string GetRelativeNamespacePath(string currentNamespace, string desiredN
result.AppendFormat("{0}/", desired[level]);
}
}
return result.ToString().Trim('/');
return result.ToString().Trim(Path.DirectorySeparatorChar);
}


Expand Down

0 comments on commit fffff35

Please sign in to comment.