dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

indentation-tests.cs (5182B)


      1 using System;
      2 
      3 /* comment block
      4    on namespace test */
      5 namespace Boo
      6 {
      7     // comment on class test
      8     public class Foo
      9     {
     10         // auto-property-test
     11         public bool AutoProperty { get; set; }
     12 
     13         // regular property-test
     14         public bool Property
     15         {
     16             get
     17             {
     18                 return true;
     19             }
     20             set
     21             {
     22                 // ignored
     23             }
     24         }
     25 
     26         /// <summary>
     27         /// Codedoc on method-test
     28         /// </summary>
     29         public void Foo(string a = "hkfdhkd", string b = "bbbbbb")
     30         {
     31             // OK!
     32         }
     33 
     34         [Fact]
     35         [Test]
     36         public void Test()
     37         {
     38             if (test)
     39             {
     40 
     41             }
     42 
     43             if (test2) {
     44                 // should work too
     45                 bool b = true;
     46             }
     47 
     48             var x = new {
     49                 adhoc = object,
     50                 with = new prop(),
     51             };
     52 
     53             // test-cases for type initializer indetation issue:
     54             // https://github.com/josteink/csharp-mode/issues/95
     55             var x_gen = new Foo<bar>
     56             {
     57                 a,
     58                 b,
     59                 c
     60             };
     61 
     62             return new Foo<bar>
     63             {
     64                 a,
     65                 b,
     66                 c
     67             };
     68 
     69             yield return new Foo<bar>
     70             {
     71                 a,
     72                 b,
     73                 c
     74             };
     75 
     76             new Foo<Bar>
     77             {
     78                 a,
     79                 b,
     80                 c
     81             };
     82 
     83             var array1 = new ArrayList
     84             {
     85                 1, 2, 3, 4, 5
     86             };
     87 
     88             var array2 = new string[]
     89             {
     90                 "a", "b", "c"
     91             };
     92 
     93             var map = new Dictionary<int,string> {
     94                 { 1, "true" },
     95                 { 2, "false" },
     96             };
     97 
     98             var map2 = new Dictionary<int,string>
     99             {
    100                 { 1, "true" },
    101                 { 2, "false" },
    102             };
    103 
    104             var map3 = new Dictionary<string,Func<int, bool>>
    105             {
    106                 { "IsZero", (int i) => i == 0 }
    107             };
    108 
    109             var innerClassIntance = new TypeOuter.TypeInner
    110             {
    111                 Boo = "Foo",
    112                 May = "Yay"
    113             };
    114 
    115             // yielding has different behaviour... for some reason!
    116             // https://github.com/josteink/csharp-mode/issues/94
    117             yield return new InnerA {
    118                 PropA = 1,
    119                 PropB = 2
    120             };
    121 
    122             // yield return new InnerA.InnerB {
    123             //     PropA = 1,
    124             //     PropB = 2
    125             // };
    126 
    127             yield return new InnerA
    128             {
    129                 Boo = "Foo",
    130                 May = "Yay"
    131             };
    132 
    133             // yield return new InnerA.InnerB
    134             // {
    135             //     Boo = "Foo",
    136             //     May = "Yay"
    137             // };
    138 
    139             // extra test-cases
    140 
    141             new Foo{
    142                 a,
    143                 b,
    144                 c
    145             };
    146 
    147             new Foo  {
    148                 a,
    149                 b,
    150                 c
    151             };
    152 
    153             new Foo
    154             {
    155                 a,
    156                 b,
    157                 c
    158             };
    159 
    160             using (test)
    161             {
    162                 System.Console.WriteLine("boo");
    163             }
    164 
    165             /* Callback indentation test. */
    166             SomeFunction(() => {
    167                 System
    168                     .Console
    169                     .WriteLine("boo");
    170             });
    171 
    172             SomeFunction(() =>
    173             {
    174                 System
    175                     .Console
    176                     .WriteLine("boo");
    177             });
    178 
    179             SomeFunction((withParam) => {
    180                 System
    181                     .Console
    182                     .WriteLine("boo");
    183             });
    184 
    185             SomeFunction((withParam) =>
    186             {
    187                 System
    188                     .Console
    189                     .WriteLine("boo");
    190             });
    191         }
    192 
    193         public void CaseStamentIndentation()
    194         {
    195             int bar = 0;
    196             switch (foo)
    197             {
    198                 case "foo":
    199                     bar = 0;
    200                     break;
    201             }
    202             switch (bar)
    203             {
    204                 case 1:
    205                 case 2:
    206                     bar = 0;
    207                     break;
    208             }
    209             switch (foo)
    210             {
    211                 case "foo":
    212                 case "bar":
    213                     bar = 0;
    214                     bar += 1;
    215                     break;
    216             }
    217         }
    218     }
    219 }
    220 
    221 public class NestedPreProcessor
    222 {
    223 #if DEBUG
    224     public static bool Debug = true;
    225 #endif
    226 }
    227 
    228 enum SomeEnum
    229 {
    230     Item,
    231     Another,
    232     Yeah
    233 }
    234 
    235 enum AnotherEnum
    236 {
    237     First = 1,
    238     Second = 2,
    239     Third = 3
    240 }
    241 
    242 public async Task WriteAsync()
    243 {
    244     using (var memoryStream = new MemoryStream())
    245     using (var writer = new BinaryWriter())
    246     {
    247         // double using should indent like this
    248     }
    249 
    250     using (var memoryStream = new MemoryStream())
    251     {
    252         using (var writer = new BinaryWriter())
    253         {
    254             // or this
    255         }
    256     }
    257 }