コード例 #1
0
        public void FullComplexIf()
        {
            SourceCodeFormatter.UseTabs    = false;
            SourceCodeFormatter.IndentText = "    ";
            string code =
                @"using System;

void main()
{
     if(true)
        Console.WriteLine(2);
    else if (false)
{            print();
}
}";
            int    pos     = 0;
            string newCode = SourceCodeFormatter.FormatCodeManually(code, ref pos);

            TextAssert.Equal(
                @"using System;

void main()
{
    if(true)
        Console.WriteLine(2);
    else if (false)
    {
        print();
    }
}", newCode);
        }
コード例 #2
0
        public void ShouldNotModifyStringsNorChars()
        {
            SourceCodeFormatter.UseTabs    = false;
            SourceCodeFormatter.IndentText = "    ";

            string code = @"using System;

                            class Script
                            {
                                void main2(int test,int test2)
                                {
                                    var t = '=';
                                    t = ',';
                                    vat test=1;
                                }
                            }";

            int    pos     = 0;
            string newCode = SourceCodeFormatter.FormatCodeManually(code, ref pos);

            TextAssert.Equal(
                @"using System;

class Script
{
    void main2(int test, int test2)
    {
        var t = '=';
        t = ',';
        vat test = 1;
    }
}", newCode);
        }
コード例 #3
0
        public void Reflector_Reconstruct_Enum()
        {
            ITypeDefinition enumType    = LoadLocalType("TestEnum");
            ITypeDefinition nonEnumType = LoadLocalType("TestClass1");

            Assert.True(enumType.IsEnum());
            Assert.False(nonEnumType.IsEnum());

            string code = new Reflector().Process(enumType)
                          .Code;

            TextAssert.Equal(code,
                             @"namespace CSScriptIntellisense.Test
{
    /// Test values
    public enum TestEnum
    {
        /// Value 1
        Val1 = 0,
        /// Value 2
        Val2 = 33,
        /// Value 3
        Val3 = 33,
        /// Value 4
        Val4 = 34,
    }
}");
        }
コード例 #4
0
        public void Reflector_Reconstruct_ComplexDocumentation()
        {
            ITypeDefinition type      = LoadLocalType("TestApiDocClass");
            var             reflector = new Reflector(usedNamespaces);

            string code = reflector.Process(type)
                          .Code;

            TextAssert.Equal(@"namespace CSScriptIntellisense.Test
{
    public class TestApiDocClass : object
    {
        /// This is the value of the UpgradeCode attribute of the Wix Product element.
        /// Both WiX and MSI consider this element as optional even it is the only available identifier for defining relationship between different versions of the same product. Wix# in contrary enforces that value to allow any future updates of the product being installed.
        ///  If user doesn't specify this value Wix# engine will use !:Project.GUID as UpgradeCode.
        public System.Guid? UpgradeCode;
        /// Generic WixSharp.WixEntity container for defining WiX Package element attributes.
        /// These attributes are the properties about the package to be placed in the Summary Information Stream. These are visible from COM through the IStream interface, and these properties can be seen on the package in Explorer.
        /// The following is an example of defining the Package attributes.
        ///
        ///              var project =
        ///                  new Project(""My Product"",
        ///                      new Dir(@""%ProgramFiles%\My Company\My Product"",
        ///
        ///                  ...
        ///
        ///              project.Package.AttributesDefinition = @""AdminImage=Yes;
        ///                                                       Comments=Release Candidate;
        ///                                                       Description=Fantastic product..."";
        ///
        ///              Compiler.BuildMsi(project);
        public void Test() {}
    }
}", code);
        }
コード例 #5
0
        public void Reconstruct_NullableStruct()
        {
            var enumSymbol = LoadType("System.Nulla|ble<int>");

            string code = enumSymbol.Reconstruct(false);

            TextAssert.Equal(@"namespace System
{
    public sealed struct Nullable<T>
        where T: struct
    {
        public Nullable();
        public Nullable(T value);

        public bool HasValue { get; }
        public T Value { get; }

        public override bool Equals(object other);
        public override int GetHashCode();
        public T GetValueOrDefault();
        public T GetValueOrDefault(T defaultValue);
        public override string ToString();

        public static explicit operator T(Nullable<T> value);
        public static implicit operator Nullable<T>(T value);
    }
}", code);
        }
コード例 #6
0
        public void Reflector_Reconstruct_NestedGenericClass()
        {
            ITypeDefinition type = LoadLocalType("TestNestedChildGenericClass`1");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public partial class TestNestedGrandParentGenericClass
    {
        public partial class TestNestedParentGenericClass
        {
            public class TestNestedChildGenericClass<T0, T1, T2> : object
            {
                public T0 T0_Prop { get; set; }
                public T1 T1_Prop { get; set; }
                public T2 T2_Prop { get; set; }
                public int[] ArrayProp { get; set; }
            }
        }
    }
}", code);
        }
コード例 #7
0
        public void StringBuilderExtensions2()
        {
            var builder = new StringBuilder();

            builder.AppendLine("");
            builder.AppendLine("");
            TextAssert.Equal("", builder.TrimEmptyEndLines().ToString());

            builder.Clear();
            builder.Append("test");
            TextAssert.Equal("test", builder.TrimEmptyEndLines().ToString());

            builder.Clear();
            builder.AppendLine("");
            TextAssert.Equal("", builder.TrimEmptyEndLines(2).ToString());

            builder.Clear();
            builder.AppendLine("test");
            TextAssert.Equal("test" + Environment.NewLine, builder.TrimEmptyEndLines(2).ToString());

            builder.Clear();
            builder.AppendLine("test");
            builder.AppendLine("");
            TextAssert.Equal("test" + Environment.NewLine + Environment.NewLine, builder.TrimEmptyEndLines(2).ToString());

            builder.Clear();
            builder.AppendLine("test");
            builder.AppendLine("");
            builder.AppendLine("");
            TextAssert.Equal("test" + Environment.NewLine + Environment.NewLine + Environment.NewLine, builder.TrimEmptyEndLines(2).ToString());

            builder.Clear();
            builder.AppendLine("test");
            builder.AppendLine("");
            builder.AppendLine("");
            builder.AppendLine("");
            builder.AppendLine("");
            builder.AppendLine("");
            builder.AppendLine("");
            TextAssert.Equal("test" + Environment.NewLine + Environment.NewLine + Environment.NewLine, builder.TrimEmptyEndLines(2).ToString());

            builder.Clear();
            builder.AppendLine("test");
            builder.AppendLine("");
            builder.AppendLine("");
            TextAssert.Equal("test" + Environment.NewLine, builder.TrimEmptyEndLines(0).ToString());

            builder.Clear();
            builder.Append(
                @"{
");
            string test = builder.TrimEmptyEndLines(0).ToString();

            Assert.Equal("{" + Environment.NewLine, test);
        }
コード例 #8
0
        public void ShouldHandleGuidsBracketsInStrings()
        {
            SourceCodeFormatter.UseTabs    = false;
            SourceCodeFormatter.IndentText = "    ";

            string code = @"SetKeyValue(@""*\shellex\ContextMenuHandlers\CS-Script"", """", ""{25D84CB0-7345-11D3-A4A1-0080C8ECFED4}"");";

            int    pos     = 0;
            string newCode = SourceCodeFormatter.FormatCodeManually(code, ref pos);

            TextAssert.Equal(code, newCode); //no changes
        }
コード例 #9
0
        public void Reflector_Reconstruct_Delegate()
        {
            ITypeDefinition type = LoadLocalType("TestDelgt`1");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public int? TestDelgt<T>(CustomIndex count, int? contextArg, T parent) where T: struct;
}", code);
        }
コード例 #10
0
        public void DocumentationForReflectedDocumentation()
        {
            var xmlText = @"<summary>Creates all directories and subdirectories as specified by <paramref name=""path""/>.
                            </summary>
                            <returns>A <see cref=""T:System.IO.DirectoryInfo""/> as specified by <paramref name=""path""/>.
                            </returns>
                            <param name=""path"">The directory path to create.</param>
                            <param name=""path2"">Fake parameter for testing.</param>
                            <exception cref=""T:System.IO.IOException"">The directory specified by <paramref name=""path""/>
                            is read-only.</exception>
                            <exception cref=""T:System.UnauthorizedAccessException"">The caller does not have
                            the required permission.</exception>
                            <exception cref=""T:System.ArgumentException"">
                            <paramref name=""path""/> is a zero-length string, contains only white space, or
                            contains one or more invalid characters as defined by <see cref=""F:System.IO.Path.InvalidPathChars""/>.-or-
                            <paramref name=""path""/> is prefixed with, or contains only a colon character
                            (:).</exception>
                            <exception cref=""T:System.ArgumentNullException"">
                            <paramref name=""path""/> is null. </exception>
                            <exception cref=""T:System.IO.PathTooLongException"">The specified path, file name,
                            or both exceed the system-defined maximum length. For example, on Windows-based
                            platforms, paths must be less than 248 characters and file names must be less
                            than 260 characters. </exception>
                            <exception cref=""T:System.IO.DirectoryNotFoundException"">The specified path is
                            invalid (for example, it is on an unmapped drive). </exception>
                            <exception cref=""T:System.NotSupportedException"">
                            <paramref name=""path""/> contains a colon character (:) that is not part of a
                            drive label (""C:\"").</exception>
                            <filterpriority>1</filterpriority>
                            <PermissionSet>
                            <IPermission class=""System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" version=""1"" Unrestricted=""true""/>
                            </PermissionSet>";

            string plainText = xmlText.XmlToPlainText(true);

            TextAssert.Equal(@"Creates all directories and subdirectories as specified by path.
--------------------------
Returns: A System.IO.DirectoryInfo as specified by path.
--------------------------
path: The directory path to create.
path2: Fake parameter for testing.
--------------------------
Exceptions: " /*otherwise CodeMade swallows space at the end of line*/ + @"
  System.IO.IOException
  System.UnauthorizedAccessException
  System.ArgumentException
  System.ArgumentNullException
  System.IO.PathTooLongException
  System.IO.DirectoryNotFoundException
  System.NotSupportedException", plainText);
        }
コード例 #11
0
        public void DocumentationForReflectedDocumentationOfDocGhost()
        {
            var    xmlText   = @"<summary>
Gets or sets my property.
</summary>
<value>
My property.
</value>";
            string plainText = xmlText.XmlToPlainText(true);

            TextAssert.Equal(@"Gets or sets my property.
--------------------------
My property.", plainText);
        }
コード例 #12
0
        public void Reconstruct_Delegate()
        {
            var type = LoadType("CSScriptIntellisense.Test.TestDel|gt<int>");

            string code = type.Reconstruct(false);

            TextAssert.Equal(
                @"using System;

namespace CSScriptIntellisense.Test
{
    public delegate int? TestDelgt<T>(CustomIndex count, int? contextArg, T parent) where T: struct;
}", code);
        }
コード例 #13
0
        public void DocumentationForTooltip()
        {
            string apiDoc = @"<summary>Deletes the specified file.<para>The parameter <paramref name=""path""/> must not be NULL.</para></summary>
<param name=""path"">The name of the file to be deleted. Wildcard characters are
not supported.</param>
<param name=""recursively"">Delete files in subdirectories.</param>
<exception cref=""T:System.ArgumentException"">
<paramref name=""path""/> is a zero-length string, contains only white space, or
contains one or more invalid characters as defined by <see cref=""F:System.IO.Path.InvalidPathChars""/>.
</exception>
<exception cref=""T:System.ArgumentNullException"">
<paramref name=""path""/> is null. </exception>
<exception cref=""T:System.IO.DirectoryNotFoundException"">The specified path is
invalid (for example, it is on an unmapped drive). </exception>
<exception cref=""T:System.IO.IOException"">The specified file is in use. -or-There
is an open handle on the file, and the operating system is Windows XP or earlier.
This open handle can result from enumerating directories and files. For more
information, see How to: Enumerate Directories and Files.</exception>
<exception cref=""T:System.NotSupportedException"">
<paramref name=""path""/> is in an invalid format. </exception>
<exception cref=""T:System.IO.PathTooLongException"">The specified path, file name,
or both exceed the system-defined maximum length. For example, on Windows-based
platforms, paths must be less than 248 characters, and file names must be less
than 260 characters. </exception>
<exception cref=""T:System.UnauthorizedAccessException"">The caller does not have
the required permission.-or- <paramref name=""path""/> is a directory.-or- <paramref name=""path""/>
specified a read-only file. </exception>
<filterpriority>1</filterpriority>
<PermissionSet>
<IPermission class=""System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" version=""1"" Unrestricted=""true""/>
</PermissionSet>"
                            .XmlToPlainText();

            var expected = @"Deletes the specified file.
The parameter path must not be NULL.

path: The name of the file to be deleted. Wildcard characters are not supported.
recursively: Delete files in subdirectories.

Exceptions: " /*otherwise CodeMade swallows space at the end of line*/ + @"
  System.ArgumentException
  System.ArgumentNullException
  System.IO.DirectoryNotFoundException
  System.IO.IOException
  System.NotSupportedException
  System.IO.PathTooLongException
  System.UnauthorizedAccessException";

            TextAssert.Equal(expected, apiDoc);
        }
コード例 #14
0
        public void ShouldHandleNonUnicodeChiniseChars()
        {
            SourceCodeFormatter.UseTabs    = false;
            SourceCodeFormatter.IndentText = "    ";

            string code =
                @"Console.WriteLine(""§ä§Ö§ã§ä"");
Console.WriteLine(""ÕâÊÇÖÐÎÄ"");";

            int    pos     = 0;
            string newCode = SourceCodeFormatter.FormatCodeManually(code, ref pos);

            TextAssert.Equal(code, newCode); //no changes
        }
コード例 #15
0
        public void Reflector_Reconstruct_HidingDefaultConstructors()
        {
            ITypeDefinition type = LoadLocalType("TestBaseClassDefC");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public class TestBaseClassDefC : object
    {
    }
}", code);
        }
コード例 #16
0
        public void Reflector_Reconstruct_NestedGenericClassConstraints()
        {
            ITypeDefinition type = LoadLocalType("TestBaseGenericClass3`2");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public class TestBaseGenericClass3<T, T2> where T: class, new() where T2: TestBaseClass, System.Collections.Generic.IEnumerable<int>, System.Collections.Generic.IList<int> : object
    {
    }
}", code);
        }
コード例 #17
0
        public void Lambdas_1()
        {
            SourceCodeFormatter.UseTabs    = false;
            SourceCodeFormatter.IndentText = "    ";
            string code =
                @"
using System;

void main()
{
    var lines = Npp.GetAllLines()
                   .Select(line =>
                           {
                                    if (false)
                               line.Split('\t'));
else
                          line.Split('\n'));

                                    if (true)
{
line.Split('\t'));
}
                           });
}
";
            int    pos     = 0;
            string newCode = SourceCodeFormatter.FormatCodeManually(code, ref pos);

            TextAssert.Equal(
                @"using System;

void main()
{
    var lines = Npp.GetAllLines()
                   .Select(line =>
                           {
                               if (false)
                                   line.Split('\t'));
                               else
                                   line.Split('\n'));

                               if (true)
                               {
                                   line.Split('\t'));
                               }
                           });
}", newCode);;
        }
コード例 #18
0
        public void Reconstruct_HidingDefaultConstructors()
        {
            var type = LoadType <TestBaseClassDefC>();

            string code = type.Reconstruct(false);

            TextAssert.Equal(
                @"using System;

namespace CSScriptIntellisense.Test
{
    public class TestBaseClassDefC
    {
    }
}", code);
        }
コード例 #19
0
        public void Reflector_Reconstruct_StaticClass()
        {
            ITypeDefinition type = LoadLocalType("Test.TestStaticClass");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public static class TestStaticClass : object
    {
        public static int MyProperty { get; set; }
    }
}", code);
        }
コード例 #20
0
        public void Reflector_Reconstruct_OperatorOverloads()
        {
            ITypeDefinition type = LoadLocalType("Test.OperatorsOveloadClass");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public class OperatorsOveloadClass : object
    {
        public static OperatorsOveloadClass operator +(OperatorsOveloadClass c1, OperatorsOveloadClass c2) {}
    }
}", code);
        }
コード例 #21
0
        public void Reconstruct_ExtensionMethodsClass()
        {
            var symbol = LoadType("CSScriptIntellisense.Test.ExtensionsCla|ss");

            string code = symbol.Reconstruct(false);

            TextAssert.Equal(@"using System;

namespace CSScriptIntellisense.Test
{
    public static class ExtensionsClass
    {
        public static bool IsEmpty(this string obj);
    }
}", code);
        }
コード例 #22
0
        public void Reflector_Reconstruct_Struct()
        {
            ITypeDefinition type = LoadLocalType("TestStruct1");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public sealed struct TestStruct1 : System.ValueType
    {
        public int MyProperty { get; set; }
    }
}", code);
        }
コード例 #23
0
        public void Reconstruct_MethodParamModifiers()
        {
            var symbol = LoadType("CSScriptIntellisense.Test.TestClass|27");

            string code = symbol.Reconstruct(false);

            TextAssert.Equal(@"using System;

namespace CSScriptIntellisense.Test
{
    public static class TestClass27
    {
        public static void TestMethod(this int r, ref string data, out string data2, string separator = ""test"", char separator2 = 'r', StringComparison sc = 4, params string[] items);
    }
}", code);
        }
コード例 #24
0
        public void Reconstruct_SrcExtensionMethodUse()
        {
            var symbol = LoadExpression("var empty = \"test\".IsEmp|ty()");

            string code = symbol.Reconstruct(false);

            TextAssert.Equal(@"using System;

namespace CSScriptIntellisense.Test
{
    public static class ExtensionsClass
    {
        public static bool IsEmpty(this string obj);
    }
}", code);
        }
コード例 #25
0
        public void Reflector_Reconstruct_ExtensionMethods()
        {
            ITypeDefinition type = LoadLocalType("Test.ExtensionsClass");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public static class ExtensionsClass : object
    {
        public static bool IsEmpty(this string obj) {}
    }
}", code);
        }
コード例 #26
0
        public void Reconstruct_StaticClass()
        {
            var symbol = LoadType("CSScriptIntellisense.Test.TestS|taticClass");

            string code = symbol.Reconstruct(false);

            TextAssert.Equal(@"using System;

namespace CSScriptIntellisense.Test
{
    public static class TestStaticClass
    {
        public static int MyProperty { get; set; }
    }
}", code);
        }
コード例 #27
0
        public void Reflector_Reconstruct_Delegate2()
        {
            ITypeDefinition type = LoadLocalType("TestDelgt3");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public partial class TestClass1
    {
        public int TestDelgt3();
    }
}", code);
        }
コード例 #28
0
        public void Reflector_Reconstruct_AbstractClass()
        {
            ITypeDefinition type = LoadLocalType("Test.TestAbstractClass");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public abstract class TestAbstractClass : object
    {
        public abstract int MyProperty { get; set; }
        public abstract void MyMethod() {}
    }
}", code);
        }
コード例 #29
0
        public void Reflector_Reconstruct_ParamArrayClass()
        {
            ITypeDefinition type = LoadLocalType("Test.TestParamArrayClass");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public class TestParamArrayClass : object
    {
        public TestClass1[,] ArrayProp { get; set; }
        public string[,,] Test(int[,] arg, params string[] names) {}
    }
}", code);
        }
コード例 #30
0
        public void Reflector_Reconstruct_Interface()
        {
            ITypeDefinition type = LoadLocalType("Test.TestInterface");

            string code = new Reflector().Process(type)
                          .Code;

            TextAssert.Equal(
                @"namespace CSScriptIntellisense.Test
{
    public interface TestInterface
    {
        int MyProperty { get; set; }
        event System.Action OnLoad;
    }
}", code);
        }