public void TestDivide() { var typescript = @" if (pageSize > 0) { page = skippedSoFar / pageSize; } var pageCount = 0; var i = totalCount; while (i > 0) { pageCount++; i -= pageSize; } dbList.PagingInfo = new PagingInfo(skippedSoFar, totalCount, pageSize, page, pageCount);"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"if (pageSize > 0) { page = skippedSoFar / pageSize; } var pageCount = 0; var i = totalCount; while (i > 0) { pageCount++; i -= pageSize; } dbList.PagingInfo = new PagingInfo(skippedSoFar, totalCount, pageSize, page, pageCount);", result); }
protected static string Beautify(string typescript) { var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); return(result); }
public void TestLargeFile2() { var typescript = LargeFile.Input2; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(LargeFile.Input2Beautified, result); }
public void TestImports() { var typescript = @"import { PropertyInfo , Type, Interface, TypeInfo} from ""@brandless/tsutility"";"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"import { PropertyInfo, Type, Interface, TypeInfo } from ""@brandless/tsutility"";", result); }
public void TestGenerics() { var typescript = @"f<Array<string>>(p => { });"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"f<Array<string>>(p => {});", result); }
public void TestSingleLineWhitespaceCleaning() { var typescript = "let x: string = `something` ;"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"let x: string = `something`;", result); }
public void TestBug1() { var jsBeautifyOptions = new TsBeautifyOptions(); jsBeautifyOptions.PreserveNewlines = false; var typescript = Bug1.TypeScript; typescript = new TsBeautifier(jsBeautifyOptions).Beautify(typescript); }
public void TestMultipleGenerics() { var code = @" private _propertiesMap: Dictionary<string, IProperty> = new Dictionary<string, IProperty>();"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(code); Assert.AreEqual(@"private _propertiesMap: Dictionary<string, IProperty> = new Dictionary<string, IProperty>();", result); }
public void TestHugeConversion() { var typescript = TsBeautifyTs.Code; for (var i = 0; i < 1000; i++) { var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); } }
public void Test123() { var typescript = @"r=// `^$`;"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"r = // `^$`;", result); }
public void TestTest() { var code = @"@test public async""Test1"" () { }@test public async""Test2"" () { }"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(code); Assert.AreEqual(@"@test public async ""Test1"" () {} @test public async ""Test2"" () {}", result); }
public void Test456() { var typescript = @"let set = (<ITrackingSet><any>MethodInfoExtensions.InvokeGeneric(Enumerable.First(TypeInfo.GetRuntimeMethods(TrackingSetCollection ) , m => m.Name == <any>`TrackingSet`) , this, new Array<Object>(), type));"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"let set = (<ITrackingSet><any>MethodInfoExtensions.InvokeGeneric(Enumerable.First(TypeInfo.GetRuntimeMethods(TrackingSetCollection), m => m.Name == <any>`TrackingSet`), this, new Array<Object>(), type));", result); }
public void TestKeepBracesOnNewLines() { var code = @"if (true) { var x = 1; }"; var beautifier = new TsBeautifier().Configure(x => x.OpenBlockOnNewLine = true); var result = beautifier.Beautify(code); Assert.AreEqual(@"if (true) { var x = 1; }", result); }
private static void Iterate(Stopwatch timer) { var typescript = TsBeautifyTs.Code; var iterations = 100; for (var i = 0; i < iterations; i++) { var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); } timer.Stop(); Console.WriteLine($"Completed {iterations} iterations in {FormatTime(timer.ElapsedTicks)}"); Console.WriteLine($"Each iteration took an average of {FormatTime(timer.ElapsedTicks / iterations)}"); }
static void Main(string[] args) { Console.WriteLine("Preparing"); var timer = new Stopwatch(); var files = Directory.EnumerateFiles(@"D:\Code\Brandless\Iql.Npm.Unformatted", "*.ts", SearchOption.AllDirectories) .Select(f => new { File = f, Contents = File.ReadAllText(f) }).ToList(); var options = new ProgressBarOptions { ProgressCharacter = '─', ProgressBarOnBottom = false }; //foreach (var text in texts) //{ // var beautifier = new TsBeautifier(); // var result = beautifier.Beautify(text); //} using (var pbar = new ProgressBar(files.Count, "Starting parallel", options)) { object lastFile = null; timer.Start(); //foreach (var file in files) //{ // pbar.Tick(Path.GetFileName(file.File)); // if (Path.GetFileName(file.File) == "MetadataSerializationJsonCache.ts") // { // continue; // } // var beautifier = new TsBeautifier(); // var result = beautifier.Beautify(file.Contents); //} Parallel.ForEach(files, file => { lastFile = file; pbar.Tick(Path.GetFileName(file.File)); var beautifier = new TsBeautifier(); var result = beautifier.Beautify(file.Contents); }); } //var text = File.ReadAllText( // @"D:\Code\Brandless\Iql.Npm.Unformatted\Iql.Tests\src\Tests\MetadataSerialization\MetadataSerializationJsonCache.ts"); //var beautifier = new TsBeautifier(); //var result = beautifier.Beautify(text); timer.Stop(); Console.WriteLine($"Completed in {FormatTime(timer.ElapsedTicks)}"); }
public void TestImportModule() { var typescript = @"import ""module-alias/register""; import { suite, test, slow, timeout } from ""mocha-typescript""; import { assert } from ""chai"";import { __Iql_Tests_Types_typeLoaded, __Iql_Tests_Types_defer } from ""../../Iql.Tests.Types.Defer""; import { TestsBase } from ""../TestsBase""; "; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"import ""module-alias/register""; import { suite, test, slow, timeout } from ""mocha-typescript""; import { assert } from ""chai""; import { __Iql_Tests_Types_typeLoaded, __Iql_Tests_Types_defer } from ""../../Iql.Tests.Types.Defer""; import { TestsBase } from ""../TestsBase"";", result); }
public void TestSingleLineCommentShouldBeOnNewLine() { var code = @"if (true) { // I am a comment var x = 1; // An am an end-of-line comment var y = /* I am an in-line comment */ 2; // I am another comment }"; var beautifier = new TsBeautifier().Configure(x => x.OpenBlockOnNewLine = true); var result = beautifier.Beautify(code); Assert.AreEqual(@"if (true) { // I am a comment var x = 1; // An am an end-of-line comment var y = /* I am an in-line comment */ 2; // I am another comment }", result); }
public void ClassNameWithGenericsShouldHaveSpace() { var code = @"class MyClass<T> extends MyOtherClass { SomeMethod(): string { let x = <string><any>""""; return <string><any>""""; } }"; var beautifier = new TsBeautifier().Configure(x => x.OpenBlockOnNewLine = true); var result = beautifier.Beautify(code); Assert.AreEqual( @"class MyClass<T> extends MyOtherClass { SomeMethod(): string { let x = <string><any>""""; return <string><any>""""; } }", result); }
public void TestKeyWordInLiteral() { var typescript = @" switch (type) { case ""number"": return """" + key; case ""string"": return <string><any>key; case ""function"": { let name = key[""ClassName""] || key[""Name""] || key[""name""];//TypeInfo.NameOf(key); if (!name) { name = TypeInfo.NameOf(key); } if (name) { return name; } } break; }"; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); Assert.AreEqual(@"switch (type) { case ""number"": return """" + key; case ""string"": return <string><any>key; case ""function"": { let name = key[""ClassName""] || key[""Name""] || key[""name""]; //TypeInfo.NameOf(key); if (!name) { name = TypeInfo.NameOf(key); } if (name) { return name; } } break; }", result); }
public void TestHugeStringConversion() { var typescript = HugeString.TypeScript; var beautifier = new TsBeautifier(); var result = beautifier.Beautify(typescript); }