mirror of https://github.com/icsharpcode/ILSpy.git
312 changed files with 48547 additions and 463 deletions
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
import os, sys |
||||
|
||||
def check(filename): |
||||
ok = True |
||||
with open(filename, 'r') as f: |
||||
for i, line in enumerate(f): |
||||
if line.startswith(' '): |
||||
print('{}:{}: Line starting with spaces. Use tabs for indentation instead!'.format(filename, i+1)) |
||||
ok = False |
||||
return ok |
||||
|
||||
def main(): |
||||
root_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..')) |
||||
dirs_to_check = ( |
||||
os.path.join(root_dir, subdir) |
||||
for subdir in ('ICSharpCode.Decompiler', 'ILSpy', 'ILSpy.BamlDecompiler')) |
||||
ok = True |
||||
for dir in dirs_to_check: |
||||
for root, dirs, files in os.walk(dir): |
||||
if '\\obj\\' in root: |
||||
continue |
||||
for filename in files: |
||||
if filename.lower().endswith('.cs'): |
||||
if not check(os.path.join(root, filename)): |
||||
ok = False |
||||
print('Tidy check: {}'.format('successful' if ok else 'failed')) |
||||
return 0 if ok else 1 |
||||
|
||||
if __name__ == '__main__': |
||||
sys.exit(main()) |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Reflection; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.FSharpPatterns |
||||
{ |
||||
[TestFixture] |
||||
public class FSharpPatternTests |
||||
{ |
||||
[Test] |
||||
public void FSharpUsingDecompilesToCSharpUsing_Debug() |
||||
{ |
||||
var ilCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Debug.il"); |
||||
var csharpCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Debug.cs"); |
||||
TestHelpers.RunIL(ilCode, csharpCode); |
||||
} |
||||
|
||||
[Test] |
||||
public void FSharpUsingDecompilesToCSharpUsing_Release() |
||||
{ |
||||
var ilCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Release.il"); |
||||
var csharpCode = TestHelpers.FuzzyReadResource("FSharpUsing.fs.Release.cs"); |
||||
TestHelpers.RunIL(ilCode, csharpCode); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
module FSharpUsingPatterns |
||||
|
||||
open System |
||||
open System.IO |
||||
|
||||
let sample1() = |
||||
use fs = File.Create("x.txt") |
||||
fs.WriteByte(byte 1) |
||||
|
||||
let sample2() = |
||||
Console.WriteLine("some text") |
||||
use fs = File.Create("x.txt") |
||||
fs.WriteByte(byte 2) |
||||
Console.WriteLine("some text") |
||||
|
||||
let sample3() = |
||||
Console.WriteLine("some text") |
||||
do use fs = File.Create("x.txt") |
||||
fs.WriteByte(byte 3) |
||||
Console.WriteLine("some text") |
||||
|
||||
let sample4() = |
||||
Console.WriteLine("some text") |
||||
let firstByte = |
||||
use fs = File.OpenRead("x.txt") |
||||
fs.ReadByte() |
||||
Console.WriteLine("read:" + firstByte.ToString()) |
||||
|
||||
let sample5() = |
||||
Console.WriteLine("some text") |
||||
let firstByte = |
||||
use fs = File.OpenRead("x.txt") |
||||
fs.ReadByte() |
||||
let secondByte = |
||||
use fs = File.OpenRead("x.txt") |
||||
fs.ReadByte() |> ignore |
||||
fs.ReadByte() |
||||
Console.WriteLine("read: {0}, {1}", firstByte, secondByte) |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
public static class FSharpUsingPatterns |
||||
{ |
||||
public static void sample1() |
||||
{ |
||||
using (FileStream fs = File.Create("x.txt")) |
||||
{ |
||||
fs.WriteByte((byte)1); |
||||
} |
||||
} |
||||
|
||||
public static void sample2() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
using (FileStream fs = File.Create("x.txt")) |
||||
{ |
||||
fs.WriteByte((byte)2); |
||||
Console.WriteLine("some text"); |
||||
} |
||||
} |
||||
|
||||
public static void sample3() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
using (FileStream fs = File.Create("x.txt")) |
||||
{ |
||||
fs.WriteByte((byte)3); |
||||
} |
||||
Console.WriteLine("some text"); |
||||
} |
||||
|
||||
public static void sample4() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
int num; |
||||
using (FileStream fs = File.OpenRead("x.txt")) |
||||
{ |
||||
num = fs.ReadByte(); |
||||
} |
||||
int firstByte = num; |
||||
Console.WriteLine("read:" + firstByte.ToString()); |
||||
} |
||||
|
||||
public static void sample5() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
int num; |
||||
using (FileStream fs = File.OpenRead("x.txt")) |
||||
{ |
||||
num = fs.ReadByte(); |
||||
} |
||||
int firstByte = num; |
||||
int num3; |
||||
using (FileStream fs = File.OpenRead("x.txt")) |
||||
{ |
||||
int num2 = fs.ReadByte(); |
||||
num3 = fs.ReadByte(); |
||||
} |
||||
int secondByte = num3; |
||||
Console.WriteLine("read: {0}, {1}", firstByte, secondByte); |
||||
} |
||||
} |
@ -0,0 +1,344 @@
@@ -0,0 +1,344 @@
|
||||
.class public auto ansi abstract sealed FSharpUsingPatterns |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
// Methods |
||||
.method public static |
||||
void sample1 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x2050 |
||||
// Code size 53 (0x35) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.IO.FileStream fs, |
||||
[1] class [mscorlib]System.Object, |
||||
[2] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "x.txt" |
||||
IL_0006: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::Create(string) |
||||
IL_000b: stloc.0 |
||||
.try |
||||
{ |
||||
IL_000c: ldloc.0 |
||||
IL_000d: ldc.i4.1 |
||||
IL_000e: conv.u1 |
||||
IL_000f: callvirt instance void [mscorlib]System.IO.Stream::WriteByte(uint8) |
||||
IL_0014: ldnull |
||||
IL_0015: stloc.1 |
||||
IL_0016: leave.s IL_0032 |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0018: ldloc.0 |
||||
IL_0019: isinst [mscorlib]System.IDisposable |
||||
IL_001e: stloc.2 |
||||
IL_001f: ldloc.2 |
||||
IL_0020: brfalse.s IL_0024 |
||||
|
||||
IL_0022: br.s IL_0026 |
||||
|
||||
IL_0024: br.s IL_002f |
||||
|
||||
IL_0026: ldloc.2 |
||||
IL_0027: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_002c: ldnull |
||||
IL_002d: pop |
||||
IL_002e: endfinally |
||||
|
||||
IL_002f: ldnull |
||||
IL_0030: pop |
||||
IL_0031: endfinally |
||||
} // end handler |
||||
|
||||
IL_0032: ldloc.1 |
||||
IL_0033: pop |
||||
IL_0034: ret |
||||
} // end of method FSharpUsingPatterns::sample1 |
||||
|
||||
.method public static |
||||
void sample2 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x20a4 |
||||
// Code size 73 (0x49) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.IO.FileStream fs, |
||||
[1] class [mscorlib]System.Object, |
||||
[2] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: ldstr "x.txt" |
||||
IL_0010: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::Create(string) |
||||
IL_0015: stloc.0 |
||||
.try |
||||
{ |
||||
IL_0016: ldloc.0 |
||||
IL_0017: ldc.i4.2 |
||||
IL_0018: conv.u1 |
||||
IL_0019: callvirt instance void [mscorlib]System.IO.Stream::WriteByte(uint8) |
||||
IL_001e: ldstr "some text" |
||||
IL_0023: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_0028: ldnull |
||||
IL_0029: stloc.1 |
||||
IL_002a: leave.s IL_0046 |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_002c: ldloc.0 |
||||
IL_002d: isinst [mscorlib]System.IDisposable |
||||
IL_0032: stloc.2 |
||||
IL_0033: ldloc.2 |
||||
IL_0034: brfalse.s IL_0038 |
||||
|
||||
IL_0036: br.s IL_003a |
||||
|
||||
IL_0038: br.s IL_0043 |
||||
|
||||
IL_003a: ldloc.2 |
||||
IL_003b: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0040: ldnull |
||||
IL_0041: pop |
||||
IL_0042: endfinally |
||||
|
||||
IL_0043: ldnull |
||||
IL_0044: pop |
||||
IL_0045: endfinally |
||||
} // end handler |
||||
|
||||
IL_0046: ldloc.1 |
||||
IL_0047: pop |
||||
IL_0048: ret |
||||
} // end of method FSharpUsingPatterns::sample2 |
||||
|
||||
.method public static |
||||
void sample3 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x210c |
||||
// Code size 73 (0x49) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.IO.FileStream fs, |
||||
[1] class [mscorlib]System.Object, |
||||
[2] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: ldstr "x.txt" |
||||
IL_0010: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::Create(string) |
||||
IL_0015: stloc.0 |
||||
.try |
||||
{ |
||||
IL_0016: ldloc.0 |
||||
IL_0017: ldc.i4.3 |
||||
IL_0018: conv.u1 |
||||
IL_0019: callvirt instance void [mscorlib]System.IO.Stream::WriteByte(uint8) |
||||
IL_001e: ldnull |
||||
IL_001f: stloc.1 |
||||
IL_0020: leave.s IL_003c |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0022: ldloc.0 |
||||
IL_0023: isinst [mscorlib]System.IDisposable |
||||
IL_0028: stloc.2 |
||||
IL_0029: ldloc.2 |
||||
IL_002a: brfalse.s IL_002e |
||||
|
||||
IL_002c: br.s IL_0030 |
||||
|
||||
IL_002e: br.s IL_0039 |
||||
|
||||
IL_0030: ldloc.2 |
||||
IL_0031: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0036: ldnull |
||||
IL_0037: pop |
||||
IL_0038: endfinally |
||||
|
||||
IL_0039: ldnull |
||||
IL_003a: pop |
||||
IL_003b: endfinally |
||||
} // end handler |
||||
|
||||
IL_003c: ldloc.1 |
||||
IL_003d: pop |
||||
IL_003e: ldstr "some text" |
||||
IL_0043: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_0048: ret |
||||
} // end of method FSharpUsingPatterns::sample3 |
||||
|
||||
.method public static |
||||
void sample4 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x2174 |
||||
// Code size 89 (0x59) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] int32 firstByte, |
||||
[1] class [mscorlib]System.IO.FileStream fs, |
||||
[2] int32, |
||||
[3] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: nop |
||||
IL_000c: ldstr "x.txt" |
||||
IL_0011: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::OpenRead(string) |
||||
IL_0016: stloc.1 |
||||
.try |
||||
{ |
||||
IL_0017: ldloc.1 |
||||
IL_0018: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_001d: stloc.2 |
||||
IL_001e: leave.s IL_003a |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0020: ldloc.1 |
||||
IL_0021: isinst [mscorlib]System.IDisposable |
||||
IL_0026: stloc.3 |
||||
IL_0027: ldloc.3 |
||||
IL_0028: brfalse.s IL_002c |
||||
|
||||
IL_002a: br.s IL_002e |
||||
|
||||
IL_002c: br.s IL_0037 |
||||
|
||||
IL_002e: ldloc.3 |
||||
IL_002f: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0034: ldnull |
||||
IL_0035: pop |
||||
IL_0036: endfinally |
||||
|
||||
IL_0037: ldnull |
||||
IL_0038: pop |
||||
IL_0039: endfinally |
||||
} // end handler |
||||
|
||||
IL_003a: ldloc.2 |
||||
IL_003b: stloc.0 |
||||
IL_003c: ldstr "read:" |
||||
IL_0041: ldloca.s firstByte |
||||
IL_0043: constrained. [mscorlib]System.Int32 |
||||
IL_0049: callvirt instance string [mscorlib]System.Object::ToString() |
||||
IL_004e: call string [mscorlib]System.String::Concat(string, string) |
||||
IL_0053: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_0058: ret |
||||
} // end of method FSharpUsingPatterns::sample4 |
||||
|
||||
.method public static |
||||
void sample5 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x21ec |
||||
// Code size 155 (0x9b) |
||||
.maxstack 5 |
||||
.locals init ( |
||||
[0] int32 firstByte, |
||||
[1] class [mscorlib]System.IO.FileStream fs, |
||||
[2] int32, |
||||
[3] class [mscorlib]System.IDisposable, |
||||
[4] int32 secondByte, |
||||
[5] class [mscorlib]System.IO.FileStream fs, |
||||
[6] int32, |
||||
[7] int32, |
||||
[8] int32, |
||||
[9] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: nop |
||||
IL_000c: ldstr "x.txt" |
||||
IL_0011: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::OpenRead(string) |
||||
IL_0016: stloc.1 |
||||
.try |
||||
{ |
||||
IL_0017: ldloc.1 |
||||
IL_0018: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_001d: stloc.2 |
||||
IL_001e: leave.s IL_003a |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0020: ldloc.1 |
||||
IL_0021: isinst [mscorlib]System.IDisposable |
||||
IL_0026: stloc.3 |
||||
IL_0027: ldloc.3 |
||||
IL_0028: brfalse.s IL_002c |
||||
|
||||
IL_002a: br.s IL_002e |
||||
|
||||
IL_002c: br.s IL_0037 |
||||
|
||||
IL_002e: ldloc.3 |
||||
IL_002f: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0034: ldnull |
||||
IL_0035: pop |
||||
IL_0036: endfinally |
||||
|
||||
IL_0037: ldnull |
||||
IL_0038: pop |
||||
IL_0039: endfinally |
||||
} // end handler |
||||
|
||||
IL_003a: ldloc.2 |
||||
IL_003b: stloc.0 |
||||
IL_003c: nop |
||||
IL_003d: ldstr "x.txt" |
||||
IL_0042: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::OpenRead(string) |
||||
IL_0047: stloc.s fs |
||||
.try |
||||
{ |
||||
IL_0049: ldloc.s fs |
||||
IL_004b: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_0050: stloc.s 7 |
||||
IL_0052: ldloc.s 7 |
||||
IL_0054: stloc.s 8 |
||||
IL_0056: ldloc.s fs |
||||
IL_0058: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_005d: stloc.s 6 |
||||
IL_005f: leave.s IL_007f |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0061: ldloc.s fs |
||||
IL_0063: isinst [mscorlib]System.IDisposable |
||||
IL_0068: stloc.s 9 |
||||
IL_006a: ldloc.s 9 |
||||
IL_006c: brfalse.s IL_0070 |
||||
|
||||
IL_006e: br.s IL_0072 |
||||
|
||||
IL_0070: br.s IL_007c |
||||
|
||||
IL_0072: ldloc.s 9 |
||||
IL_0074: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0079: ldnull |
||||
IL_007a: pop |
||||
IL_007b: endfinally |
||||
|
||||
IL_007c: ldnull |
||||
IL_007d: pop |
||||
IL_007e: endfinally |
||||
} // end handler |
||||
|
||||
IL_007f: ldloc.s 6 |
||||
IL_0081: stloc.s secondByte |
||||
IL_0083: ldstr "read: {0}, {1}" |
||||
IL_0088: ldloc.0 |
||||
IL_0089: box [mscorlib]System.Int32 |
||||
IL_008e: ldloc.s secondByte |
||||
IL_0090: box [mscorlib]System.Int32 |
||||
IL_0095: call void [mscorlib]System.Console::WriteLine(string, object, object) |
||||
IL_009a: ret |
||||
} // end of method FSharpUsingPatterns::sample5 |
||||
|
||||
} // end of class FSharpUsingPatterns |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
public static class FSharpUsingPatterns |
||||
{ |
||||
public static void sample1() |
||||
{ |
||||
using (FileStream fs = File.Create("x.txt")) |
||||
{ |
||||
fs.WriteByte(1); |
||||
} |
||||
} |
||||
|
||||
public static void sample2() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
using (FileStream fs = File.Create("x.txt")) |
||||
{ |
||||
fs.WriteByte(2); |
||||
Console.WriteLine("some text"); |
||||
} |
||||
} |
||||
|
||||
public static void sample3() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
using (FileStream fs = File.Create("x.txt")) |
||||
{ |
||||
fs.WriteByte(3); |
||||
} |
||||
Console.WriteLine("some text"); |
||||
} |
||||
|
||||
public static void sample4() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
int num; |
||||
using (FileStream fs = File.OpenRead("x.txt")) |
||||
{ |
||||
num = fs.ReadByte(); |
||||
} |
||||
int firstByte = num; |
||||
Console.WriteLine("read:" + firstByte.ToString()); |
||||
} |
||||
|
||||
public static void sample5() |
||||
{ |
||||
Console.WriteLine("some text"); |
||||
int secondByte; |
||||
using (FileStream fs = File.OpenRead("x.txt")) |
||||
{ |
||||
secondByte = fs.ReadByte(); |
||||
} |
||||
int firstByte = secondByte; |
||||
int num2; |
||||
using (FileStream fs = File.OpenRead("x.txt")) |
||||
{ |
||||
int num = fs.ReadByte(); |
||||
num2 = fs.ReadByte(); |
||||
} |
||||
secondByte = num2; |
||||
Console.WriteLine("read: {0}, {1}", firstByte, secondByte); |
||||
} |
||||
} |
@ -0,0 +1,311 @@
@@ -0,0 +1,311 @@
|
||||
.class public auto ansi abstract sealed FSharpUsingPatterns |
||||
extends [mscorlib]System.Object |
||||
{ |
||||
// Methods |
||||
.method public static |
||||
void sample1 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x2050 |
||||
// Code size 48 (0x30) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.IO.FileStream fs, |
||||
[1] class [mscorlib]System.Object, |
||||
[2] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "x.txt" |
||||
IL_0006: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::Create(string) |
||||
IL_000b: stloc.0 |
||||
.try |
||||
{ |
||||
IL_000c: ldloc.0 |
||||
IL_000d: ldc.i4.1 |
||||
IL_000e: callvirt instance void [mscorlib]System.IO.Stream::WriteByte(uint8) |
||||
IL_0013: ldnull |
||||
IL_0014: stloc.1 |
||||
IL_0015: leave.s IL_002d |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0017: ldloc.0 |
||||
IL_0018: isinst [mscorlib]System.IDisposable |
||||
IL_001d: stloc.2 |
||||
IL_001e: ldloc.2 |
||||
IL_001f: brfalse.s IL_002a |
||||
|
||||
IL_0021: ldloc.2 |
||||
IL_0022: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0027: ldnull |
||||
IL_0028: pop |
||||
IL_0029: endfinally |
||||
|
||||
IL_002a: ldnull |
||||
IL_002b: pop |
||||
IL_002c: endfinally |
||||
} // end handler |
||||
|
||||
IL_002d: ldloc.1 |
||||
IL_002e: pop |
||||
IL_002f: ret |
||||
} // end of method FSharpUsingPatterns::sample1 |
||||
|
||||
.method public static |
||||
void sample2 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x209c |
||||
// Code size 68 (0x44) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.IO.FileStream fs, |
||||
[1] class [mscorlib]System.Object, |
||||
[2] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: ldstr "x.txt" |
||||
IL_0010: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::Create(string) |
||||
IL_0015: stloc.0 |
||||
.try |
||||
{ |
||||
IL_0016: ldloc.0 |
||||
IL_0017: ldc.i4.2 |
||||
IL_0018: callvirt instance void [mscorlib]System.IO.Stream::WriteByte(uint8) |
||||
IL_001d: ldstr "some text" |
||||
IL_0022: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_0027: ldnull |
||||
IL_0028: stloc.1 |
||||
IL_0029: leave.s IL_0041 |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_002b: ldloc.0 |
||||
IL_002c: isinst [mscorlib]System.IDisposable |
||||
IL_0031: stloc.2 |
||||
IL_0032: ldloc.2 |
||||
IL_0033: brfalse.s IL_003e |
||||
|
||||
IL_0035: ldloc.2 |
||||
IL_0036: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_003b: ldnull |
||||
IL_003c: pop |
||||
IL_003d: endfinally |
||||
|
||||
IL_003e: ldnull |
||||
IL_003f: pop |
||||
IL_0040: endfinally |
||||
} // end handler |
||||
|
||||
IL_0041: ldloc.1 |
||||
IL_0042: pop |
||||
IL_0043: ret |
||||
} // end of method FSharpUsingPatterns::sample2 |
||||
|
||||
.method public static |
||||
void sample3 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x20fc |
||||
// Code size 68 (0x44) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] class [mscorlib]System.IO.FileStream fs, |
||||
[1] class [mscorlib]System.Object, |
||||
[2] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: ldstr "x.txt" |
||||
IL_0010: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::Create(string) |
||||
IL_0015: stloc.0 |
||||
.try |
||||
{ |
||||
IL_0016: ldloc.0 |
||||
IL_0017: ldc.i4.3 |
||||
IL_0018: callvirt instance void [mscorlib]System.IO.Stream::WriteByte(uint8) |
||||
IL_001d: ldnull |
||||
IL_001e: stloc.1 |
||||
IL_001f: leave.s IL_0037 |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0021: ldloc.0 |
||||
IL_0022: isinst [mscorlib]System.IDisposable |
||||
IL_0027: stloc.2 |
||||
IL_0028: ldloc.2 |
||||
IL_0029: brfalse.s IL_0034 |
||||
|
||||
IL_002b: ldloc.2 |
||||
IL_002c: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0031: ldnull |
||||
IL_0032: pop |
||||
IL_0033: endfinally |
||||
|
||||
IL_0034: ldnull |
||||
IL_0035: pop |
||||
IL_0036: endfinally |
||||
} // end handler |
||||
|
||||
IL_0037: ldloc.1 |
||||
IL_0038: pop |
||||
IL_0039: ldstr "some text" |
||||
IL_003e: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_0043: ret |
||||
} // end of method FSharpUsingPatterns::sample3 |
||||
|
||||
.method public static |
||||
void sample4 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x215c |
||||
// Code size 85 (0x55) |
||||
.maxstack 4 |
||||
.locals init ( |
||||
[0] int32 firstByte, |
||||
[1] class [mscorlib]System.IO.FileStream fs, |
||||
[2] int32, |
||||
[3] class [mscorlib]System.IDisposable |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: nop |
||||
IL_000c: ldstr "x.txt" |
||||
IL_0011: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::OpenRead(string) |
||||
IL_0016: stloc.1 |
||||
.try |
||||
{ |
||||
IL_0017: ldloc.1 |
||||
IL_0018: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_001d: stloc.2 |
||||
IL_001e: leave.s IL_0036 |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0020: ldloc.1 |
||||
IL_0021: isinst [mscorlib]System.IDisposable |
||||
IL_0026: stloc.3 |
||||
IL_0027: ldloc.3 |
||||
IL_0028: brfalse.s IL_0033 |
||||
|
||||
IL_002a: ldloc.3 |
||||
IL_002b: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0030: ldnull |
||||
IL_0031: pop |
||||
IL_0032: endfinally |
||||
|
||||
IL_0033: ldnull |
||||
IL_0034: pop |
||||
IL_0035: endfinally |
||||
} // end handler |
||||
|
||||
IL_0036: ldloc.2 |
||||
IL_0037: stloc.0 |
||||
IL_0038: ldstr "read:" |
||||
IL_003d: ldloca.s firstByte |
||||
IL_003f: constrained. [mscorlib]System.Int32 |
||||
IL_0045: callvirt instance string [mscorlib]System.Object::ToString() |
||||
IL_004a: call string [mscorlib]System.String::Concat(string, string) |
||||
IL_004f: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_0054: ret |
||||
} // end of method FSharpUsingPatterns::sample4 |
||||
|
||||
.method public static |
||||
void sample5 () cil managed |
||||
{ |
||||
// Method begins at RVA 0x21d0 |
||||
// Code size 134 (0x86) |
||||
.maxstack 5 |
||||
.locals init ( |
||||
[0] int32 firstByte, |
||||
[1] class [mscorlib]System.IO.FileStream fs, |
||||
[2] int32 secondByte, |
||||
[3] class [mscorlib]System.IDisposable, |
||||
[4] int32, |
||||
[5] int32 |
||||
) |
||||
|
||||
IL_0000: nop |
||||
IL_0001: ldstr "some text" |
||||
IL_0006: call void [mscorlib]System.Console::WriteLine(string) |
||||
IL_000b: nop |
||||
IL_000c: ldstr "x.txt" |
||||
IL_0011: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::OpenRead(string) |
||||
IL_0016: stloc.1 |
||||
.try |
||||
{ |
||||
IL_0017: ldloc.1 |
||||
IL_0018: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_001d: stloc.2 |
||||
IL_001e: leave.s IL_0036 |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0020: ldloc.1 |
||||
IL_0021: isinst [mscorlib]System.IDisposable |
||||
IL_0026: stloc.3 |
||||
IL_0027: ldloc.3 |
||||
IL_0028: brfalse.s IL_0033 |
||||
|
||||
IL_002a: ldloc.3 |
||||
IL_002b: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0030: ldnull |
||||
IL_0031: pop |
||||
IL_0032: endfinally |
||||
|
||||
IL_0033: ldnull |
||||
IL_0034: pop |
||||
IL_0035: endfinally |
||||
} // end handler |
||||
|
||||
IL_0036: ldloc.2 |
||||
IL_0037: stloc.0 |
||||
IL_0038: nop |
||||
IL_0039: ldstr "x.txt" |
||||
IL_003e: call class [mscorlib]System.IO.FileStream [mscorlib]System.IO.File::OpenRead(string) |
||||
IL_0043: stloc.1 |
||||
.try |
||||
{ |
||||
IL_0044: ldloc.1 |
||||
IL_0045: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_004a: stloc.s 5 |
||||
IL_004c: ldloc.1 |
||||
IL_004d: callvirt instance int32 [mscorlib]System.IO.Stream::ReadByte() |
||||
IL_0052: stloc.s 4 |
||||
IL_0054: leave.s IL_006c |
||||
} // end .try |
||||
finally |
||||
{ |
||||
IL_0056: ldloc.1 |
||||
IL_0057: isinst [mscorlib]System.IDisposable |
||||
IL_005c: stloc.3 |
||||
IL_005d: ldloc.3 |
||||
IL_005e: brfalse.s IL_0069 |
||||
|
||||
IL_0060: ldloc.3 |
||||
IL_0061: callvirt instance void [mscorlib]System.IDisposable::Dispose() |
||||
IL_0066: ldnull |
||||
IL_0067: pop |
||||
IL_0068: endfinally |
||||
|
||||
IL_0069: ldnull |
||||
IL_006a: pop |
||||
IL_006b: endfinally |
||||
} // end handler |
||||
|
||||
IL_006c: ldloc.s 4 |
||||
IL_006e: stloc.2 |
||||
IL_006f: ldstr "read: {0}, {1}" |
||||
IL_0074: ldloc.0 |
||||
IL_0075: box [mscorlib]System.Int32 |
||||
IL_007a: ldloc.2 |
||||
IL_007b: box [mscorlib]System.Int32 |
||||
IL_0080: call void [mscorlib]System.Console::WriteLine(string, object, object) |
||||
IL_0085: ret |
||||
} // end of method FSharpUsingPatterns::sample5 |
||||
|
||||
} // end of class FSharpUsingPatterns |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
using ICSharpCode.Decompiler.Ast; |
||||
using ICSharpCode.Decompiler.Tests.Helpers; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using Mono.Cecil; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Reflection; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.FSharpPatterns |
||||
{ |
||||
public class TestHelpers |
||||
{ |
||||
public static string FuzzyReadResource(string resourceName) |
||||
{ |
||||
var asm = Assembly.GetExecutingAssembly(); |
||||
var allResources = asm.GetManifestResourceNames(); |
||||
var fullResourceName = allResources.Single(r => r.EndsWith(resourceName, StringComparison.OrdinalIgnoreCase)); |
||||
return new StreamReader(asm.GetManifestResourceStream(fullResourceName)).ReadToEnd(); |
||||
} |
||||
|
||||
static Lazy<string> ilasm = new Lazy<string>(() => ToolLocator.FindTool("ilasm.exe")); |
||||
static Lazy<string> ildasm = new Lazy<string>(() => ToolLocator.FindTool("ildasm.exe")); |
||||
|
||||
public static string CompileIL(string source) |
||||
{ |
||||
if (ilasm.Value == null) |
||||
Assert.NotNull(ilasm.Value, "Could not find ILASM.exe"); |
||||
var tmp = Path.GetTempFileName(); |
||||
File.Delete(tmp); |
||||
var sourceFile = Path.ChangeExtension(tmp, ".il"); |
||||
File.WriteAllText(sourceFile, source); |
||||
var asmFile = Path.ChangeExtension(sourceFile, ".dll"); |
||||
|
||||
var args = string.Format("{0} /dll /debug /output:{1}", sourceFile, asmFile); |
||||
using (var proc = Process.Start(new ProcessStartInfo(ilasm.Value, args) { UseShellExecute = false, })) |
||||
{ |
||||
proc.WaitForExit(); |
||||
Assert.AreEqual(0, proc.ExitCode); |
||||
} |
||||
|
||||
File.Delete(sourceFile); |
||||
Assert.True(File.Exists(asmFile), "Assembly File does not exist"); |
||||
return asmFile; |
||||
} |
||||
|
||||
public static void RunIL(string ilCode, string expectedCSharpCode) |
||||
{ |
||||
var asmFilePath = CompileIL(ilCode); |
||||
CompareAssemblyAgainstCSharp(expectedCSharpCode, asmFilePath); |
||||
} |
||||
|
||||
private static void CompareAssemblyAgainstCSharp(string expectedCSharpCode, string asmFilePath) |
||||
{ |
||||
var module = ModuleDefinition.ReadModule(asmFilePath); |
||||
try |
||||
{ |
||||
try { module.ReadSymbols(); } catch { } |
||||
AstBuilder decompiler = new AstBuilder(new DecompilerContext(module)); |
||||
decompiler.AddAssembly(module); |
||||
new Helpers.RemoveCompilerAttribute().Run(decompiler.SyntaxTree); |
||||
StringWriter output = new StringWriter(); |
||||
|
||||
// the F# assembly contains a namespace `<StartupCode$tmp6D55>` where the part after tmp is randomly generated.
|
||||
// remove this from the ast to simplify the diff
|
||||
var startupCodeNode = decompiler.SyntaxTree.Children.OfType<NamespaceDeclaration>().SingleOrDefault(d => d.Name.StartsWith("<StartupCode$", StringComparison.Ordinal)); |
||||
if (startupCodeNode != null) |
||||
startupCodeNode.Remove(); |
||||
|
||||
decompiler.GenerateCode(new PlainTextOutput(output)); |
||||
var fullCSharpCode = output.ToString(); |
||||
|
||||
CodeAssert.AreEqual(expectedCSharpCode, output.ToString()); |
||||
} |
||||
finally |
||||
{ |
||||
File.Delete(asmFilePath); |
||||
File.Delete(Path.ChangeExtension(asmFilePath, ".pdb")); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.FSharpPatterns |
||||
{ |
||||
public class ToolLocator |
||||
{ |
||||
public static string FindTool(string fileName) |
||||
{ |
||||
var allPaths = FindPathForDotNetFramework().Concat(FindPathForWindowsSdk()); |
||||
return allPaths.Select(dir => Path.Combine(dir, fileName)).FirstOrDefault(File.Exists); |
||||
} |
||||
|
||||
private static IEnumerable<string> FindPathForWindowsSdk() |
||||
{ |
||||
string[] windowsSdkPaths = new[] |
||||
{ |
||||
@"Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\", |
||||
@"Microsoft SDKs\Windows\v8.0A\bin\", |
||||
@"Microsoft SDKs\Windows\v8.0\bin\NETFX 4.0 Tools\", |
||||
@"Microsoft SDKs\Windows\v8.0\bin\", |
||||
@"Microsoft SDKs\Windows\v7.1A\bin\NETFX 4.0 Tools\", |
||||
@"Microsoft SDKs\Windows\v7.1A\bin\", |
||||
@"Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\", |
||||
@"Microsoft SDKs\Windows\v7.0A\bin\", |
||||
@"Microsoft SDKs\Windows\v6.1A\bin\", |
||||
@"Microsoft SDKs\Windows\v6.0A\bin\", |
||||
@"Microsoft SDKs\Windows\v6.0\bin\", |
||||
@"Microsoft.NET\FrameworkSDK\bin" |
||||
}; |
||||
|
||||
foreach (var possiblePath in windowsSdkPaths) |
||||
{ |
||||
string fullPath = string.Empty; |
||||
|
||||
// Check alternate program file paths as well as 64-bit versions.
|
||||
if (Environment.Is64BitProcess) |
||||
{ |
||||
fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), possiblePath, "x64"); |
||||
if (Directory.Exists(fullPath)) |
||||
{ |
||||
yield return fullPath; |
||||
} |
||||
|
||||
fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), possiblePath, "x64"); |
||||
if (Directory.Exists(fullPath)) |
||||
{ |
||||
yield return fullPath; |
||||
} |
||||
} |
||||
|
||||
fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), possiblePath); |
||||
if (Directory.Exists(fullPath)) |
||||
{ |
||||
yield return fullPath; |
||||
} |
||||
|
||||
fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), possiblePath); |
||||
if (Directory.Exists(fullPath)) |
||||
{ |
||||
yield return fullPath; |
||||
} |
||||
} |
||||
} |
||||
|
||||
private static IEnumerable<string> FindPathForDotNetFramework() |
||||
{ |
||||
string[] frameworkPaths = new[] |
||||
{ |
||||
@"Microsoft.NET\Framework\v4.0.30319", |
||||
@"Microsoft.NET\Framework\v2.0.50727" |
||||
}; |
||||
|
||||
foreach (var possiblePath in frameworkPaths) |
||||
{ |
||||
string fullPath = string.Empty; |
||||
|
||||
if (Environment.Is64BitProcess) |
||||
{ |
||||
fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), possiblePath.Replace(@"\Framework\", @"\Framework64\")); |
||||
if (Directory.Exists(fullPath)) |
||||
{ |
||||
yield return fullPath; |
||||
} |
||||
} |
||||
|
||||
fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), possiblePath); |
||||
if (Directory.Exists(fullPath)) |
||||
{ |
||||
yield return fullPath; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.Decompiler.Tests |
||||
{ |
||||
public class NotUsingBlock |
||||
{ |
||||
public void ThisIsNotAUsingBlock() |
||||
{ |
||||
object obj = File.OpenRead("..."); |
||||
IDisposable disposable; |
||||
try |
||||
{ |
||||
(obj as FileStream).WriteByte(2); |
||||
Console.WriteLine("some text"); |
||||
} |
||||
finally |
||||
{ |
||||
disposable = (obj as IDisposable); |
||||
if (disposable != null) |
||||
{ |
||||
disposable.Dispose(); |
||||
} |
||||
} |
||||
Console.WriteLine(disposable); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,269 @@
@@ -0,0 +1,269 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.ILSpy.AddIn |
||||
{ |
||||
/// <summary>
|
||||
/// Provides XML documentation tags for Visual Studio CodeElements.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Used to support the "/navigateTo" command line option when opening ILSpy. Must match
|
||||
/// the logic of ICSharpCode.ILSpy.XmlDoc.XmlDocKeyProvider, which does the same thing for
|
||||
/// a Mono.Cecil.MemberReference. See "ID string format" in Appendix A of the C# language
|
||||
/// specification for formatting requirements, and Samples/ILSpyAddInSamples.cs for examples.
|
||||
/// </remarks>
|
||||
public static class CodeElementXmlDocKeyProvider |
||||
{ |
||||
#region GetKey
|
||||
public static string GetKey(EnvDTE.CodeElement member) |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
if ((member.Kind == EnvDTE.vsCMElement.vsCMElementDelegate) || |
||||
(member.Kind == EnvDTE.vsCMElement.vsCMElementEnum) || |
||||
(member.Kind == EnvDTE.vsCMElement.vsCMElementInterface) || |
||||
(member.Kind == EnvDTE.vsCMElement.vsCMElementStruct) || |
||||
(member.Kind == EnvDTE.vsCMElement.vsCMElementClass)) { |
||||
b.Append("T:"); |
||||
AppendTypeName(b, member.FullName, true, false); |
||||
} |
||||
else if (member.Kind == EnvDTE.vsCMElement.vsCMElementNamespace){ |
||||
b.Append("N:"); |
||||
b.Append(member.FullName); |
||||
} |
||||
else { |
||||
if (member.Kind == EnvDTE.vsCMElement.vsCMElementVariable) |
||||
b.Append("F:"); |
||||
else if (member.Kind == EnvDTE.vsCMElement.vsCMElementProperty) |
||||
b.Append("P:"); |
||||
else if (member.Kind == EnvDTE.vsCMElement.vsCMElementEvent) |
||||
b.Append("E:"); |
||||
else if (member.Kind == EnvDTE.vsCMElement.vsCMElementFunction) |
||||
b.Append("M:"); |
||||
|
||||
int nameIndex = member.FullName.LastIndexOf(member.Name); |
||||
string typeName = member.FullName.Substring(0, nameIndex - 1); |
||||
string memberName = member.FullName.Substring(nameIndex); |
||||
|
||||
// Name substitutions for special cases.
|
||||
if (member.Kind == EnvDTE.vsCMElement.vsCMElementFunction) { |
||||
EnvDTE80.CodeFunction2 mr = (EnvDTE80.CodeFunction2)member; |
||||
if (mr.FunctionKind == EnvDTE.vsCMFunction.vsCMFunctionConstructor) { |
||||
memberName = memberName.Replace(member.Name, "#ctor"); |
||||
} |
||||
else if (mr.FunctionKind == EnvDTE.vsCMFunction.vsCMFunctionDestructor) { |
||||
memberName = memberName.Replace(member.Name, "Finalize"); |
||||
} |
||||
else if (mr.FunctionKind == EnvDTE.vsCMFunction.vsCMFunctionOperator) { |
||||
if (memberName.StartsWith("implicit operator")) { |
||||
memberName = "op_Implicit"; |
||||
} |
||||
else if (memberName.StartsWith("explicit operator")) { |
||||
memberName = "op_Explicit"; |
||||
} |
||||
else { |
||||
// NRefactory has a handy mapping we can make use of, just need to extract the operator sybol first.
|
||||
string[] memberNameWords = member.Name.Split(' '); |
||||
if (memberNameWords.Length >= 2) { |
||||
string operatorSymbol = memberNameWords[1]; |
||||
string operatorName = ICSharpCode.NRefactory.MonoCSharp.Operator.GetMetadataName(operatorSymbol); |
||||
if (operatorName != null) { |
||||
memberName = memberName.Replace(member.Name, operatorName); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
else if (member.Kind == EnvDTE.vsCMElement.vsCMElementProperty) { |
||||
if (member.Name == "this") { |
||||
memberName = memberName.Replace(member.Name, "Item"); |
||||
} |
||||
} |
||||
|
||||
string[] genericTypeParameters = AppendTypeName(b, typeName, true, false); |
||||
b.Append('.'); |
||||
string[] genericMethodParameters = AppendTypeName(b, memberName.Replace('.', '#'), true, true); |
||||
EnvDTE.CodeElements parameters; |
||||
EnvDTE.CodeTypeRef explicitReturnType = null; |
||||
if (member.Kind == EnvDTE.vsCMElement.vsCMElementProperty) { |
||||
parameters = ((EnvDTE.CodeProperty)member).Getter.Parameters; |
||||
} |
||||
else if (member.Kind == EnvDTE.vsCMElement.vsCMElementFunction) { |
||||
EnvDTE80.CodeFunction2 mr = (EnvDTE80.CodeFunction2)member; |
||||
parameters = mr.Parameters; |
||||
if (memberName == "op_Implicit" || memberName == "op_Explicit") { |
||||
explicitReturnType = mr.Type; |
||||
} |
||||
} |
||||
else { |
||||
parameters = null; |
||||
} |
||||
if (parameters != null && parameters.Count > 0) { |
||||
b.Append('('); |
||||
int i = 0; |
||||
foreach (EnvDTE80.CodeParameter2 parameter in parameters) { |
||||
if (i > 0) b.Append(','); |
||||
AppendParameterTypeName(b, parameter, genericTypeParameters, genericMethodParameters); |
||||
++i; |
||||
} |
||||
b.Append(')'); |
||||
} |
||||
if (explicitReturnType != null) { |
||||
b.Append('~'); |
||||
AppendTypeName(b, explicitReturnType.AsFullName, true, false); |
||||
} |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
|
||||
static string[] AppendTypeName(StringBuilder b, string typeName, bool appendGenericParameterCount, bool isMethod) |
||||
{ |
||||
List<string> allGenericParameters = new List<string>(); |
||||
StringBuilder genericParameterName = new StringBuilder(); |
||||
|
||||
bool inGenericParameters = false; |
||||
int genericParameterCount = 0; |
||||
foreach (char ch in typeName) { |
||||
if (inGenericParameters) { |
||||
switch (ch) { |
||||
case ',': |
||||
++genericParameterCount; |
||||
allGenericParameters.Add(genericParameterName.ToString()); |
||||
genericParameterName.Clear(); |
||||
break; |
||||
case '>': |
||||
++genericParameterCount; |
||||
allGenericParameters.Add(genericParameterName.ToString()); |
||||
genericParameterName.Clear(); |
||||
if (appendGenericParameterCount) { |
||||
b.Append(genericParameterCount); |
||||
} |
||||
inGenericParameters = false; |
||||
break; |
||||
case ' ': |
||||
break; |
||||
default: |
||||
genericParameterName.Append(ch); |
||||
break; |
||||
} |
||||
} |
||||
else { |
||||
switch (ch) { |
||||
case '<': |
||||
if (appendGenericParameterCount) { |
||||
b.Append('`'); |
||||
if (isMethod) { |
||||
b.Append('`'); |
||||
} |
||||
} |
||||
inGenericParameters = true; |
||||
genericParameterCount = 0; |
||||
break; |
||||
case '[': |
||||
case ']': |
||||
break; |
||||
default: |
||||
b.Append(ch); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
return allGenericParameters.ToArray(); |
||||
} |
||||
|
||||
private static void AppendParameterTypeName(StringBuilder b, EnvDTE80.CodeParameter2 parameter, string[] genericTypeParameters, string[] genericMethodParameters) |
||||
{ |
||||
EnvDTE80.CodeTypeRef2 parameterTypeRef = (EnvDTE80.CodeTypeRef2)parameter.Type; |
||||
string parameterTypeString = parameterTypeRef.AsFullName; |
||||
|
||||
int substringStart = 0; |
||||
for (int i = 0; i < parameterTypeString.Length; ++i) { |
||||
char ch = parameterTypeString[i]; |
||||
switch (ch) { |
||||
case '<': |
||||
AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters); |
||||
substringStart = i + 1; |
||||
b.Append('{'); |
||||
break; |
||||
case '>': |
||||
AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters); |
||||
substringStart = i + 1; |
||||
b.Append('}'); |
||||
break; |
||||
|
||||
case '[': |
||||
AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters); |
||||
b.Append('['); |
||||
|
||||
// Skip ahead to the closing bracket, counting commas to determine array rank.
|
||||
int rank = 1; |
||||
do { |
||||
++i; |
||||
ch = parameterTypeString[i]; |
||||
if (ch == ',') { |
||||
++rank; |
||||
} |
||||
} |
||||
while (ch != ']'); |
||||
substringStart = i + 1; |
||||
|
||||
// For multi-dimensional arrays, add "0:" default array bounds. Note that non-standard bounds are not possible via C# declaration.
|
||||
if (rank > 1) { |
||||
for (int r = 0; r < rank; ++r) { |
||||
if (r != 0) { |
||||
b.Append(','); |
||||
} |
||||
b.Append("0:"); |
||||
} |
||||
} |
||||
|
||||
b.Append(']'); |
||||
break; |
||||
|
||||
case ',': |
||||
AppendParameterTypeSubstring(b, parameterTypeString, substringStart, i, genericTypeParameters, genericMethodParameters); |
||||
substringStart = i + 1; |
||||
// Skip space after comma if present. (e.g. System.Collections.Generic.KeyValuePair`2{System.String,System.String}.)
|
||||
if (parameterTypeString[substringStart] == ' ') { |
||||
++substringStart; |
||||
} |
||||
b.Append(','); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
AppendParameterTypeSubstring(b, parameterTypeString, substringStart, parameterTypeString.Length, genericTypeParameters, genericMethodParameters); |
||||
|
||||
// Append ref / out indicator if needed.
|
||||
if ((parameter.ParameterKind == EnvDTE80.vsCMParameterKind.vsCMParameterKindRef) || |
||||
(parameter.ParameterKind == EnvDTE80.vsCMParameterKind.vsCMParameterKindOut)) { |
||||
b.Append('@'); |
||||
} |
||||
|
||||
// Note there is no need to append a '*' for pointers, as this is included in the full name of the type.
|
||||
// Multi-dimensional and jagged arrays are handled above during string parsing.
|
||||
} |
||||
|
||||
private static void AppendParameterTypeSubstring(StringBuilder b, string parameterTypeString, int substringStart, int substringStop, string[] genericTypeParameters, string[] genericMethodParameters) |
||||
{ |
||||
if (substringStart < substringStop) { |
||||
string substring = parameterTypeString.Substring(substringStart, substringStop - substringStart); |
||||
int indexOfGenericTypeParameter = Array.IndexOf(genericTypeParameters, substring); |
||||
int indexOfGenericMethodParameter = Array.IndexOf(genericMethodParameters, substring); |
||||
if (indexOfGenericTypeParameter >= 0) { |
||||
b.Append("`"); |
||||
b.Append(indexOfGenericTypeParameter); |
||||
} |
||||
else if (indexOfGenericMethodParameter >= 0) { |
||||
b.Append("``"); |
||||
b.Append(indexOfGenericMethodParameter); |
||||
} |
||||
else { |
||||
b.Append(substring); |
||||
} |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,414 @@
@@ -0,0 +1,414 @@
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
/// Sample source file indicating a wide variety of code elements that should work
|
||||
/// with the "Open code in ILSpy" Visual Studio add-in feature. Each code element is
|
||||
/// commented with the string generated by CodeElementXmlDocKeyProvider.GetKey and
|
||||
/// used with the ILSpy /navigateTo command line option.
|
||||
///
|
||||
/// Note that this code is not compiled or used in the project in any way, it is
|
||||
/// only provided for reference.
|
||||
|
||||
|
||||
// N:ILSpy.AddIn.Tests
|
||||
namespace ILSpy.AddIn.Tests |
||||
{ |
||||
// T:ILSpy.AddIn.Tests.SomeClass
|
||||
public class SomeClass |
||||
{ |
||||
// E:ILSpy.AddIn.Tests.SomeClass.OnEvent
|
||||
public event Action OnEvent; |
||||
|
||||
// F:ILSpy.AddIn.Tests.SomeClass.mField
|
||||
private int mField; |
||||
|
||||
// P:ILSpy.AddIn.Tests.SomeClass.Property
|
||||
private int Property |
||||
{ |
||||
get |
||||
{ |
||||
return mField; |
||||
} |
||||
set |
||||
{ |
||||
mField = value; |
||||
} |
||||
} |
||||
|
||||
// P:ILSpy.AddIn.Tests.SomeClass.Item(System.Int32,System.Int32)
|
||||
public int this[int x, int y] |
||||
{ |
||||
get { return x + y + mField; } |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.#ctor
|
||||
public SomeClass() |
||||
{ |
||||
mField = 0; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.#ctor(System.Int32)
|
||||
public SomeClass(int x) |
||||
{ |
||||
mField = x; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.#ctor(System.Int32,System.Int32)
|
||||
public SomeClass(int x, int y) |
||||
{ |
||||
mField = x + y; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.Method
|
||||
public int Method() |
||||
{ |
||||
return mField; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.MethodWithGenericParameter(System.IEquatable{System.String})
|
||||
public void MethodWithGenericParameter(IEquatable<string> x) |
||||
{ |
||||
|
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.MethodWithGenericParameter(System.IEquatable{System.String},System.Int32)
|
||||
public void MethodWithGenericParameter(IEquatable<string> x, int y) |
||||
{ |
||||
|
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.GenericMethod``1(``0)
|
||||
public int GenericMethod<T>(T x) |
||||
{ |
||||
return mField + x.GetHashCode(); |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.GenericOverloadedMethod``1(System.Int32,``0)
|
||||
public int GenericOverloadedMethod<T1>(int x, T1 y) |
||||
{ |
||||
return mField + x + y.GetHashCode(); |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.GenericOverloadedMethod``2(System.Int32,``0,``1)
|
||||
public int GenericOverloadedMethod<T1, T2>(int x, T1 y, T2 z) |
||||
{ |
||||
return mField + x + y.GetHashCode() + z.GetHashCode(); |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedMethod
|
||||
public int OverloadedMethod() |
||||
{ |
||||
return mField * mField; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedMethod(System.Int32)
|
||||
public int OverloadedMethod(int m) |
||||
{ |
||||
return mField * m; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedMethod(System.Int32,System.Int32)
|
||||
public int OverloadedMethod(int m1, int m2) |
||||
{ |
||||
return mField * m1 * m2; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1
|
||||
public int OverloadedGenericMethod<T>() |
||||
{ |
||||
return mField * mField; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(System.Int32)
|
||||
public int OverloadedGenericMethod<T>(int m) |
||||
{ |
||||
return mField * m; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(System.Int32,System.Int32)
|
||||
public int OverloadedGenericMethod<T>(int m1, int m2) |
||||
{ |
||||
return mField * m1 * m2; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(System.Int32,System.Int32,System.Collections.IEnumerable)
|
||||
public int OverloadedGenericMethod<T>(int m1, int m2, IEnumerable m3) |
||||
{ |
||||
return mField * m1 * m2; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(System.Int32,System.Int32,System.Collections.Generic.IEnumerable{``0})
|
||||
public int OverloadedGenericMethod<T>(int m1, int m2, IEnumerable<T> m3) |
||||
{ |
||||
return mField * m1 * m2; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(System.Int32,System.Int32,System.Collections.Generic.IEnumerable{System.String})
|
||||
public int OverloadedGenericMethod<T>(int m1, int m2, IEnumerable<string> m3) |
||||
{ |
||||
return mField * m1 * m2; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(System.Collections.Generic.IEnumerable{System.Collections.Generic.IEnumerable{ILSpy.AddIn.Tests.SomeGenericClass{System.String,``0}}})
|
||||
public int OverloadedGenericMethod<T>(IEnumerable<IEnumerable<SomeGenericClass<string, T>>> m3) |
||||
{ |
||||
return mField; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.OverloadedGenericMethod``1(ILSpy.AddIn.Tests.SomeGenericClass{``0,ILSpy.AddIn.Tests.SomeGenericClass{``0,``0}}.NestedGeneric{System.String,``0})
|
||||
public void OverloadedGenericMethod<T>(SomeGenericClass<T, SomeGenericClass<T, T>>.NestedGeneric<string, T> wow) |
||||
{ |
||||
} |
||||
|
||||
// T:ILSpy.AddIn.Tests.SomeClass.NestedEnum
|
||||
public enum NestedEnum |
||||
{ |
||||
// F:ILSpy.AddIn.Tests.SomeClass.NestedEnum.First
|
||||
First = 1, |
||||
Second = 2, |
||||
Third = 3 |
||||
} |
||||
|
||||
// T:ILSpy.AddIn.Tests.SomeClass.NestedInterface
|
||||
public interface NestedInterface |
||||
{ |
||||
// P:ILSpy.AddIn.Tests.SomeClass.NestedInterface.SomeProperty
|
||||
int SomeProperty { get; } |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.NestedInterface.SomeMethod
|
||||
int SomeMethod(); |
||||
} |
||||
|
||||
// T:ILSpy.AddIn.Tests.SomeClass.NestedClass
|
||||
public class NestedClass : NestedInterface |
||||
{ |
||||
// F:ILSpy.AddIn.Tests.SomeClass.NestedClass.mX
|
||||
private int mX; |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.NestedClass.#ctor(System.Int32)
|
||||
public NestedClass(int x) |
||||
{ |
||||
mX = x; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.NestedClass.#ctor(ILSpy.AddIn.Tests.SomeClass.NestedEnum)
|
||||
public NestedClass(NestedEnum x) |
||||
{ |
||||
mX = (int)x; |
||||
} |
||||
|
||||
// P:ILSpy.AddIn.Tests.SomeClass.NestedClass.SomeProperty
|
||||
public int SomeProperty |
||||
{ |
||||
get { return mX; } |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.NestedClass.SomeMethod
|
||||
public int SomeMethod() |
||||
{ |
||||
return mX * mX; |
||||
} |
||||
} |
||||
|
||||
// T:ILSpy.AddIn.Tests.SomeClass.NestedStruct
|
||||
public struct NestedStruct : NestedInterface |
||||
{ |
||||
// F:ILSpy.AddIn.Tests.SomeClass.NestedStruct.X
|
||||
public int X; |
||||
// F:ILSpy.AddIn.Tests.SomeClass.NestedStruct.Y
|
||||
public int Y; |
||||
|
||||
// P:ILSpy.AddIn.Tests.SomeClass.NestedStruct.SomeProperty
|
||||
public int SomeProperty |
||||
{ |
||||
get { return X + Y; } |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeClass.NestedStruct.SomeMethod
|
||||
public int SomeMethod() |
||||
{ |
||||
return X * Y; |
||||
} |
||||
} |
||||
} |
||||
|
||||
// T:ILSpy.AddIn.Tests.SomeGenericClass`2
|
||||
public class SomeGenericClass<T1, T2> |
||||
{ |
||||
// F:ILSpy.AddIn.Tests.SomeGenericClass`2.mField1
|
||||
T1 mField1; |
||||
// F:ILSpy.AddIn.Tests.SomeGenericClass`2.mField2
|
||||
T2 mField2; |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.#ctor(`0,`1)
|
||||
public SomeGenericClass(T1 a, T2 b) |
||||
{ |
||||
mField1 = a; |
||||
mField2 = b; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.#ctor(`0)
|
||||
public SomeGenericClass(T1 a) |
||||
{ |
||||
mField1 = a; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.#ctor
|
||||
public SomeGenericClass() |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.Finalize
|
||||
~SomeGenericClass() |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassMethod(`0,`1)
|
||||
public void GenericClassMethod(T1 a, T2 b) |
||||
{ |
||||
mField1 = a; |
||||
mField2 = b; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassMethod(System.Int32*)
|
||||
unsafe public void GenericClassMethod(int* x) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassMethod(System.Int32*[])
|
||||
unsafe public void GenericClassMethod(int*[] x) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassMethod(`0[]@)
|
||||
unsafe public void GenericClassMethod(out T1[] x) |
||||
{ |
||||
x = null; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassMethod(System.Int32@)
|
||||
public void GenericClassMethod(ref int a) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``1(``0@)
|
||||
public T3 GenericClassGenericMethod<T3>(ref T3 x) |
||||
{ |
||||
return x; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``1
|
||||
public T3 GenericClassGenericMethod<T3>() |
||||
{ |
||||
return default(T3); |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``1(System.Int32)
|
||||
public void GenericClassGenericMethod<T3>(int x) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``1,System.Int32,`1@)
|
||||
public T4 GenericClassGenericMethod<T3, T4>(T1 x, T4 y, int z, out T2 result) |
||||
{ |
||||
mField1 = x; |
||||
string foo = y.ToString() + z.ToString(); |
||||
result = mField2; |
||||
return y; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,System.Int32[])
|
||||
public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, int[] z) |
||||
{ |
||||
mField1 = x; |
||||
string foo = y.ToString() + z.ToString(); |
||||
return y; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(`0[],System.Int32[])
|
||||
public void ArrayMethod(T1[] x, int[] y) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(`0[0:,0:],System.Int32[0:,0:])
|
||||
public void ArrayMethod(T1[,] x, int[,] y) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(System.Int32[0:,0:],System.Int32[0:,0:])
|
||||
public void ArrayMethod(int[,] x, int[,] y) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.ArrayMethod(`0[][],System.Int32[][])
|
||||
public void ArrayMethod(T1[][] x, int[][] y) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,ILSpy.AddIn.Tests.SomeClass)
|
||||
public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, SomeClass z) |
||||
{ |
||||
return y; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(`0,``0,ILSpy.AddIn.Tests.SomeClass[]@)
|
||||
public T3 GenericClassGenericMethod<T3, T4>(T1 x, T3 y, out SomeClass[] z) |
||||
{ |
||||
z = null; |
||||
return y; |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.GenericClassGenericMethod``2(System.Int32[],ILSpy.AddIn.Tests.SomeGenericClass{``0[],``1[0:,0:,0:]}[0:,0:,0:])
|
||||
public void GenericClassGenericMethod<T3, T4>(int[] x, SomeGenericClass<T3[], T4[,,]>[,,] y) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.op_Addition(ILSpy.AddIn.Tests.SomeGenericClass{`0,`1},ILSpy.AddIn.Tests.SomeGenericClass{`0,`1})
|
||||
public static SomeGenericClass<T1, T2> operator +(SomeGenericClass<T1, T2> a, SomeGenericClass<T1, T2> b) |
||||
{ |
||||
return new SomeGenericClass<T1, T2>(); |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.op_Explicit(ILSpy.AddIn.Tests.SomeGenericClass{`0,`1})~ILSpy.AddIn.Tests.SomeGenericClass`2.NestedGeneric`2
|
||||
public static explicit operator NestedGeneric<T1, T2>(SomeGenericClass<T1, T2> sgc) |
||||
{ |
||||
return new NestedGeneric<T1, T2>(); |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.op_Implicit(ILSpy.AddIn.Tests.SomeGenericClass{`0,`1})~ILSpy.AddIn.Tests.SomeGenericClass`2.NestedGeneric`2
|
||||
public static implicit operator NestedGeneric<T2, T1>(SomeGenericClass<T1, T2> sgc) |
||||
{ |
||||
return new NestedGeneric<T2, T1>(); |
||||
} |
||||
|
||||
// T:ILSpy.AddIn.Tests.SomeGenericClass`2.NestedGeneric`2
|
||||
public class NestedGeneric<T3, T4> |
||||
{ |
||||
// T:ILSpy.AddIn.Tests.SomeGenericClass`2.NestedGeneric`2.NestedDelegate
|
||||
public delegate int NestedDelegate(T3 x, IEnumerable<T4> y); |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.NestedGeneric`2.NestedGenericMethod``1(`0,``0)
|
||||
public void NestedGenericMethod<T5>(T1 x, T5 y) |
||||
{ |
||||
} |
||||
|
||||
// M:ILSpy.AddIn.Tests.SomeGenericClass`2.NestedGeneric`2.NestedGenericMethod``3(`0,`3,``0[],System.Collections.Generic.IEnumerable{``2})
|
||||
public void NestedGenericMethod<T5, T6, T7>(T1 x, T4 y, T5[] z, IEnumerable<T7> w) |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// T:SpaceFreeClass
|
||||
class SpaceFreeClass |
||||
{ |
||||
// F:SpaceFreeClass.mField
|
||||
int mField; |
||||
|
||||
// M:SpaceFreeClass.Method
|
||||
private void Method() |
||||
{ |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
[ExportMainMenuCommand(Menu = "_Help", Header = "_Check for Updates", MenuOrder = 5000)] |
||||
sealed class CheckForUpdatesCommand : SimpleCommand |
||||
{ |
||||
public override void Execute(object parameter) |
||||
{ |
||||
MainWindow.Instance.ShowMessageIfUpdatesAvailableAsync(ILSpySettings.Load(), forceCheck: true); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
[ExportMainMenuCommand(Menu = "_View", Header = "Sort assembly list by name", MenuIcon = "Images/Sort.png", MenuCategory = "View")] |
||||
[ExportToolbarCommand(ToolTip = "Sort assembly list by name", ToolbarIcon = "Images/Sort.png", ToolbarCategory = "View")] |
||||
class SortAssemblyListCommand : SimpleCommand, IComparer<LoadedAssembly> |
||||
{ |
||||
public override void Execute(object parameter) |
||||
{ |
||||
using (MainWindow.Instance.treeView.LockUpdates()) |
||||
MainWindow.Instance.CurrentAssemblyList.Sort(this); |
||||
} |
||||
|
||||
int IComparer<LoadedAssembly>.Compare(LoadedAssembly x, LoadedAssembly y) |
||||
{ |
||||
return string.Compare(x.ShortName, y.ShortName, StringComparison.CurrentCulture); |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 380 B |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.ILSpy |
||||
{ |
||||
public interface IResourceFileHandler |
||||
{ |
||||
string EntryType { get; } |
||||
bool CanHandle(string name, DecompilationOptions options); |
||||
string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options); |
||||
} |
||||
} |
@ -1 +1 @@
@@ -1 +1 @@
|
||||
Subproject commit 2d65653491ba5a804dd2b44b946b1d33b00c0623 |
||||
Subproject commit a2b55de351be2119b6f0c3a17c36b5b9adbd7c59 |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
// Information about this assembly is defined by the following
|
||||
// attributes.
|
||||
//
|
||||
// change them to the information which is associated with the assembly
|
||||
// you compile.
|
||||
|
||||
[assembly: AssemblyTitle("NRefactory Test")] |
||||
[assembly: AssemblyDescription("Unit tests for the parser and refactoring library for C# and VB.NET")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("ic#code")] |
||||
[assembly: AssemblyProduct("SharpDevelop")] |
||||
[assembly: AssemblyCopyright("2004-2006 AlphaSierraPapa")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all values by your own or you can build default build and revision
|
||||
// numbers with the '*' character (the default):
|
||||
|
||||
[assembly: AssemblyVersion("2.0.0.1")] |
||||
|
||||
// The following attributes specify the key for the sign of your assembly. See the
|
||||
// .NET Framework documentation for more information about signing.
|
||||
// This is not required, if you don't want signing let these attributes like they're.
|
||||
[assembly: AssemblyDelaySign(false)] |
||||
[assembly: AssemblyKeyFile("")] |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class StructuralTest |
||||
{ |
||||
// [Test]
|
||||
// public void TestToStringMethods()
|
||||
// {
|
||||
// Type[] allTypes = typeof(INode).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null) {
|
||||
// MethodInfo methodInfo = type.GetMethod("ToString", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
|
||||
// Assert.IsNotNull(methodInfo, "ToString() not found in " + type.FullName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestUnitTests()
|
||||
// {
|
||||
// Type[] allTypes = typeof(StructuralTest).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.GetCustomAttributes(typeof(TestFixtureAttribute), true).Length > 0) {
|
||||
// foreach (MethodInfo m in type.GetMethods()) {
|
||||
// if (m.IsPublic && m.ReturnType == typeof(void) && m.GetParameters().Length == 0) {
|
||||
// if (m.GetCustomAttributes(typeof(TestAttribute), true).Length == 0) {
|
||||
// Assert.Fail(type.Name + "." + m.Name + " should have the [Test] attribute!");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestAcceptVisitorMethods()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && type.GetInterface(typeof(INode).FullName) != null) {
|
||||
// MethodInfo methodInfo = type.GetMethod("AcceptVisitor", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
|
||||
// Assertion.AssertNotNull("AcceptVisitor() not found in " + type.FullName, methodInfo);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestIAstVisitor()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
// Type visitor = typeof(IAstVisitor);
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) {
|
||||
// MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null);
|
||||
// Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found");
|
||||
// Assert.AreEqual(2, methodInfo.GetParameters().Length);
|
||||
// ParameterInfo first = methodInfo.GetParameters()[0];
|
||||
// Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name);
|
||||
//
|
||||
// ParameterInfo second = methodInfo.GetParameters()[1];
|
||||
// Assert.AreEqual(typeof(System.Object), second.ParameterType);
|
||||
// Assert.AreEqual("data", second.Name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void TestAbstractAstVisitorVisitor()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
// Type visitor = typeof(AbstractAstVisitor);
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) {
|
||||
// MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null);
|
||||
// Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found");
|
||||
//
|
||||
// Assert.AreEqual(2, methodInfo.GetParameters().Length);
|
||||
// ParameterInfo first = methodInfo.GetParameters()[0];
|
||||
// Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name);
|
||||
//
|
||||
// ParameterInfo second = methodInfo.GetParameters()[1];
|
||||
// Assert.AreEqual(typeof(System.Object), second.ParameterType);
|
||||
// Assert.AreEqual("data", second.Name);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
} |
||||
} |
@ -0,0 +1,109 @@
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>8.0.50215</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{870115DD-960A-4406-A6B9-600BCDC36A03}</ProjectGuid> |
||||
<RootNamespace>ICSharpCode.NRefactory.VB.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.VB.Tests</AssemblyName> |
||||
<OutputTarget>Library</OutputTarget> |
||||
<NoStdLib>False</NoStdLib> |
||||
<NoConfig>False</NoConfig> |
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> |
||||
<OutputType>Library</OutputType> |
||||
<OutputPath>bin\$(Configuration)\</OutputPath> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors> |
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> |
||||
<NoWin32Manifest>False</NoWin32Manifest> |
||||
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<DebugType>Full</DebugType> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<StartAction>Project</StartAction> |
||||
<BaseIntermediateOutputPath>obj\</BaseIntermediateOutputPath> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<PlatformTarget>AnyCPU</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="nunit.framework"> |
||||
<HintPath>..\..\ICSharpCode.Decompiler\Tests\nunit.framework.dll</HintPath> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="General\UnitTest.cs" /> |
||||
<Compile Include="Lexer\CustomLexerTests.cs" /> |
||||
<Compile Include="Lexer\ImplicitLineContinuationTests.cs" /> |
||||
<Compile Include="Lexer\LATextReaderTests.cs" /> |
||||
<Compile Include="Lexer\LexerContextTests.cs" /> |
||||
<Compile Include="Lexer\LexerPositionTests.cs" /> |
||||
<Compile Include="Lexer\LexerTests.cs" /> |
||||
<Compile Include="Lexer\LiteralsTests.cs" /> |
||||
<Compile Include="Lexer\TokenTests.cs" /> |
||||
<Compile Include="Lexer\XmlModeLexerTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\AttributeSectionTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\NamespaceDeclarationTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\ImportsStatementTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\TypeDeclarationTests.cs" /> |
||||
<Compile Include="Parser\SnippetParserTests.cs" /> |
||||
<Compile Include="Parser\ParseUtil.cs" /> |
||||
<Compile Include="Parser\GlobalScope\OptionStatementTests.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\ICSharpCode.NRefactory.VB\ICSharpCode.NRefactory.VB.csproj"> |
||||
<Project>{7b82b671-419f-45f4-b778-d9286f996efa}</Project> |
||||
<Name>ICSharpCode.NRefactory.VB</Name> |
||||
</ProjectReference> |
||||
<ProjectReference Include="..\..\NRefactory\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3b2a5653-ec97-4001-bb9b-d90f1af2c371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> |
||||
</Project> |
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class CustomLexerTests |
||||
{ |
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleEOLForMulitpleLines() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("Stop\n\n\nEnd")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleEOLForMulitpleLinesWithContinuation() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("Stop\n _\n\nEnd")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void EscapedIdentifier() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("[Stop]")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdentifierWithTypeCharacter() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("Stop$")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsTypeCharacter() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a!=b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Assign)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsTypeCharacter2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a! b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsIdentifier() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a!b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsIdentifier2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a![b]")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemCommentTest() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("a rem b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemCommentTest2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("REM c")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,230 @@
@@ -0,0 +1,230 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class ImplicitLineContinuationTests |
||||
{ |
||||
[Test] |
||||
public void Example1() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print( |
||||
Param1 As Integer, |
||||
Param2 As Integer) |
||||
|
||||
If (Param1 < Param2) Or |
||||
(Param1 > Param2) Then |
||||
Console.WriteLine(""Not equal"") |
||||
End If |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, |
||||
Tokens.Identifier, Tokens.As, Tokens.Integer, Tokens.Comma, |
||||
Tokens.Identifier, Tokens.As, Tokens.Integer, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.If, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.LessThan, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.Or, |
||||
Tokens.OpenParenthesis, Tokens.Identifier, Tokens.GreaterThan, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.Then, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.End, Tokens.If, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void QualifierInWith() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print |
||||
With xml |
||||
Dim a = b. |
||||
d |
||||
Dim c = . |
||||
Count |
||||
End With |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.With, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Dot, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.With, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Example2() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print |
||||
Dim a = _ |
||||
|
||||
y |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.EOL, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Query() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub A |
||||
Dim q = From x In a |
||||
Select x |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Query1() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub A |
||||
Dim actions = From a in b Select Sub() |
||||
Dim i = 1 |
||||
Select Case i |
||||
End Select |
||||
End Sub |
||||
End Sub |
||||
End Module";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Select, Tokens.Sub, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Select, Tokens.Case, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Select, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
/// <remarks>tests http://community.sharpdevelop.net/forums/p/12068/32893.aspx#32893</remarks>
|
||||
[Test] |
||||
public void Bug_Thread12068() |
||||
{ |
||||
string code = @"Class MainClass
|
||||
Public Shared Sub Main() |
||||
Dim categoryNames = From p In AList _ |
||||
Select p.AFunction(1,2,3) _ |
||||
Distinct |
||||
End Sub |
||||
End Class";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Public, Tokens.Shared, Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.LiteralInteger, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis, |
||||
Tokens.Distinct, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void LineContinuationAfterAttributes() |
||||
{ |
||||
string code = @"<TestFixture>
|
||||
Public Class TestContinuation |
||||
<Test> |
||||
Public Sub TestMethod |
||||
Assert.Fail |
||||
End Sub |
||||
|
||||
<Test> _ |
||||
Public Sub TestMethod2 |
||||
Assert.Fail |
||||
End Sub |
||||
End Class";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoILCAfterGlobalAttributes() |
||||
{ |
||||
string code = "<Assembly: AssemblyTitle(\"My.UnitTests\")>" + Environment.NewLine + |
||||
"<Assembly: AssemblyDescription(\"\")>"; |
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.LessThan, Tokens.Assembly, Tokens.Colon, |
||||
Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.CloseParenthesis, Tokens.GreaterThan, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Assembly, Tokens.Colon, |
||||
Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.CloseParenthesis, Tokens.GreaterThan |
||||
); |
||||
} |
||||
|
||||
#region Helpers
|
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
void CheckTokens(VBLexer lexer, params int[] tokens) |
||||
{ |
||||
for (int i = 0; i < tokens.Length; i++) { |
||||
int token = tokens[i]; |
||||
Token t = lexer.NextToken(); |
||||
int next = t.Kind; |
||||
Assert.AreEqual(token, next, "{2} of {3}: {0} != {1}; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LATextReaderTests |
||||
{ |
||||
[Test] |
||||
public void TestPeek() |
||||
{ |
||||
LATextReader reader = new LATextReader(new StringReader("abcd")); |
||||
|
||||
CheckPeek(reader, 0, 'a'); |
||||
CheckPeek(reader, 2, 'c'); |
||||
CheckPeek(reader, 3, 'd'); |
||||
CheckPeek(reader, 1, 'b'); |
||||
CheckPeek(reader, 0, 'a'); |
||||
Assert.AreEqual((int)'a', reader.Read()); |
||||
CheckPeek(reader, 1, 'c'); |
||||
CheckPeek(reader, 2, 'd'); |
||||
CheckPeek(reader, 0, 'b'); |
||||
} |
||||
|
||||
void CheckPeek(LATextReader reader, int num1, char char2) |
||||
{ |
||||
Assert.AreEqual((int)char2, reader.Peek(num1)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,575 @@
@@ -0,0 +1,575 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LexerContextTests |
||||
{ |
||||
[Test] |
||||
public void SimpleGlobal() |
||||
{ |
||||
RunTest( |
||||
@"Option Explicit", |
||||
@"enter Global
|
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void VariableWithXmlLiteral() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
Dim x = <a /> |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberWithXmlLiteral() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Private xml As XElement = <b /> |
||||
|
||||
Public Sub New() |
||||
Dim x = <a /> |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Member |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void GlobalAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"<assembly: CLSCompliant(True)>
|
||||
Class Test |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter Attribute |
||||
exit Attribute |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"<Serializable>
|
||||
Class Test |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter Attribute |
||||
exit Attribute |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
<Test> |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Attribute |
||||
exit Attribute |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithBlockTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
With x |
||||
|
||||
End With |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void StatementsTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
For i As Integer = 0 To 10 |
||||
|
||||
Next |
||||
|
||||
For Each x As Integer In list |
||||
|
||||
Next |
||||
|
||||
Try |
||||
|
||||
Catch e As Exception |
||||
|
||||
End Try |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
enter Body |
||||
exit Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassTest() |
||||
{ |
||||
RunTest( |
||||
@"Class MainClass ' a comment
|
||||
Dim under_score_field As Integer |
||||
Sub SomeMethod() |
||||
simple += 1 |
||||
For Each loopVarName In collection |
||||
Next |
||||
End Sub |
||||
End Class",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
exit Member |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
[Test] |
||||
public void CollectionInitializer() |
||||
{ |
||||
RunTest(@"'
|
||||
' Created by SharpDevelop. |
||||
' User: Siegfried |
||||
' Date: 22.06.2010 |
||||
' Time: 21:29 |
||||
' |
||||
' To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
' |
||||
|
||||
Option Infer On |
||||
|
||||
Imports System.Linq |
||||
Imports System.Xml.Linq |
||||
|
||||
Module Program |
||||
Sub Main() |
||||
Console.WriteLine(""Hello World!"") |
||||
|
||||
Dim name = ""Test"" |
||||
Dim content = { 4, 5, New XAttribute(""a"", 3) } |
||||
|
||||
Dim xml = <<%= name %> <%= content %> /> |
||||
|
||||
Console.ReadKey() |
||||
End Sub |
||||
End Module",
|
||||
@"enter Global
|
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter ObjectCreation |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit ObjectCreation |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
[Test] |
||||
public void Imports() |
||||
{ |
||||
RunTest(@"Imports System
|
||||
Imports System.Linq |
||||
Imports System.Collections.Generic",
|
||||
@"enter Global
|
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
void RunTest(string code, string expectedOutput) |
||||
{ |
||||
ExpressionFinder p = new ExpressionFinder(); |
||||
VBLexer lexer = new VBLexer(new StringReader(code)); |
||||
Token t; |
||||
|
||||
do { |
||||
t = lexer.NextToken(); |
||||
p.InformToken(t); |
||||
} while (t.Kind != Tokens.EOF); |
||||
|
||||
Console.WriteLine(p.Output); |
||||
|
||||
Assert.IsEmpty(p.Errors); |
||||
|
||||
Assert.AreEqual(expectedOutput.Replace("\r", ""), |
||||
p.Output.Replace("\r", "")); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LexerPositionTests |
||||
{ |
||||
VBLexer GenerateLexer(string s) |
||||
{ |
||||
return new VBLexer(new StringReader(s)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestNewLine() |
||||
{ |
||||
VBLexer l = GenerateLexer("public\nstatic"); |
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Public, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Static, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 7), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCarriageReturnNewLine() |
||||
{ |
||||
VBLexer l = GenerateLexer("public\r\nstatic"); |
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Public, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Static, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 1), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 7), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestPositionOfEOF1() |
||||
{ |
||||
VBLexer l = GenerateLexer("public"); |
||||
l.NextToken(); // public
|
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
|
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOF, t.Kind); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.Location); |
||||
Assert.AreEqual(new TextLocation(1, 7), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestPositionOfEOF2() |
||||
{ |
||||
VBLexer l = GenerateLexer("public _\n "); |
||||
l.NextToken(); // public
|
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.EndLocation); |
||||
|
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOF, t.Kind); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.Location); |
||||
Assert.AreEqual(new TextLocation(2, 2), t.EndLocation); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,194 @@
@@ -0,0 +1,194 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public sealed class LiteralsTests |
||||
{ |
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
Token GetSingleToken(string text) |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(text)); |
||||
Token t = lexer.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, lexer.NextToken().Kind, "Tokens.EOL"); |
||||
Assert.AreEqual(Tokens.EOF, lexer.NextToken().Kind, "Tokens.EOF"); |
||||
Assert.AreEqual("", lexer.Errors.ErrorOutput); |
||||
return t; |
||||
} |
||||
|
||||
void CheckToken(string text, int tokenType, object val) |
||||
{ |
||||
Token t = GetSingleToken(text); |
||||
Assert.AreEqual(tokenType, t.Kind, "Tokens.Literal"); |
||||
Assert.IsNotNull(t.LiteralValue, "literalValue is null"); |
||||
Assert.AreEqual(val.GetType(), t.LiteralValue.GetType(), "literalValue.GetType()"); |
||||
Assert.AreEqual(val, t.LiteralValue, "literalValue"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleDigit() |
||||
{ |
||||
CheckToken("5", Tokens.LiteralInteger, 5); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestZero() |
||||
{ |
||||
CheckToken("0", Tokens.LiteralInteger, 0); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestInteger() |
||||
{ |
||||
CheckToken("15", Tokens.LiteralInteger, 15); |
||||
CheckToken("8581", Tokens.LiteralInteger, 8581); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidTypeCharacter() |
||||
{ |
||||
// just check that we don't get exceptions:
|
||||
GenerateLexer(new StringReader(".5s")).NextToken(); |
||||
GenerateLexer(new StringReader(".5ul")).NextToken(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestHexadecimalInteger() |
||||
{ |
||||
CheckToken("&H10", Tokens.LiteralInteger, 0x10); |
||||
CheckToken("&H10&", Tokens.LiteralInteger, (long)0x10); |
||||
CheckToken("&h3ff%", Tokens.LiteralInteger, 0x3ff); |
||||
CheckToken("&h8000s", Tokens.LiteralInteger, short.MinValue); |
||||
CheckToken("&h8000us", Tokens.LiteralInteger, (ushort)0x8000); |
||||
CheckToken("&HffffFFFF", Tokens.LiteralInteger, -1); |
||||
CheckToken("&HffffFFFF%", Tokens.LiteralInteger, -1); |
||||
CheckToken("&HffffFFFFui", Tokens.LiteralInteger, uint.MaxValue); |
||||
CheckToken("&HffffFFFF&", Tokens.LiteralInteger, (long)uint.MaxValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestLongHexadecimalInteger() |
||||
{ |
||||
CheckToken("&H4244636f446c6d58", Tokens.LiteralInteger, 0x4244636f446c6d58); |
||||
CheckToken("&hf244636f446c6d58", Tokens.LiteralInteger, -989556688574190248); |
||||
CheckToken("&hf244636f446c6d58&", Tokens.LiteralInteger, -989556688574190248); |
||||
CheckToken("&hf244636f446c6d58ul", Tokens.LiteralInteger, 0xf244636f446c6d58); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvalidHexadecimalInteger() |
||||
{ |
||||
// just check that we don't get exceptions:
|
||||
GenerateLexer(new StringReader("&H")).NextToken(); |
||||
// >ulong.MaxValue
|
||||
GenerateLexer(new StringReader("&hff244636f446c6d58")).NextToken(); |
||||
// needs an ulong, but "i" postfix specified integer
|
||||
GenerateLexer(new StringReader("&hf244636f446c6d58i")).NextToken(); |
||||
GenerateLexer(new StringReader("&hf244636f446c6d58ui")).NextToken(); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestIncompleteHexadecimal() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader("&H\r\nabc")); |
||||
Token t = lexer.NextToken(); |
||||
Assert.AreEqual(Tokens.LiteralInteger, t.Kind); |
||||
Assert.AreEqual(0, (int)t.LiteralValue); |
||||
Assert.AreEqual(Tokens.EOL, lexer.NextToken().Kind, "Tokens.EOL (1)"); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind, "Tokens.Identifier"); |
||||
Assert.AreEqual(Tokens.EOL, lexer.NextToken().Kind, "Tokens.EOL (2)"); |
||||
Assert.AreEqual(Tokens.EOF, lexer.NextToken().Kind, "Tokens.EOF"); |
||||
Assert.AreNotEqual("", lexer.Errors.ErrorOutput); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestStringLiterals() |
||||
{ |
||||
CheckToken("\"\"", Tokens.LiteralString, ""); |
||||
CheckToken("\"Hello, World!\"", Tokens.LiteralString, "Hello, World!"); |
||||
CheckToken("\"\"\"\"", Tokens.LiteralString, "\""); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCharacterLiterals() |
||||
{ |
||||
CheckToken("\" \"c", Tokens.LiteralCharacter, ' '); |
||||
CheckToken("\"!\"c", Tokens.LiteralCharacter, '!'); |
||||
CheckToken("\"\"\"\"c", Tokens.LiteralCharacter, '"'); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDateLiterals() |
||||
{ |
||||
CheckToken("# 8/23/1970 #", Tokens.LiteralDate, new DateTime(1970, 8, 23, 0, 0, 0)); |
||||
CheckToken("#8/23/1970#", Tokens.LiteralDate, new DateTime(1970, 8, 23, 0, 0, 0)); |
||||
CheckToken("# 8/23/1970 3:45:39AM #", Tokens.LiteralDate, new DateTime(1970, 8, 23, 3, 45, 39)); |
||||
CheckToken("# 3:45:39AM #", Tokens.LiteralDate, new DateTime(1, 1, 1, 3, 45, 39)); |
||||
CheckToken("# 3:45:39 PM #", Tokens.LiteralDate, new DateTime(1, 1, 1, 15, 45, 39)); |
||||
CheckToken("# 3:45:39 #", Tokens.LiteralDate, new DateTime(1, 1, 1, 3, 45, 39)); |
||||
CheckToken("# 13:45:39 #", Tokens.LiteralDate, new DateTime(1, 1, 1, 13, 45, 39)); |
||||
CheckToken("# 1AM #", Tokens.LiteralDate, new DateTime(1, 1, 1, 1, 0, 0)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDouble() |
||||
{ |
||||
CheckToken("1.0", Tokens.LiteralDouble, 1.0); |
||||
CheckToken("1.1", Tokens.LiteralDouble, 1.1); |
||||
CheckToken("2e-5", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2.0e-5", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2e5", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e5", Tokens.LiteralDouble, 2.2e5); |
||||
CheckToken("2e+5", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e+5", Tokens.LiteralDouble, 2.2e5); |
||||
|
||||
CheckToken("1r", Tokens.LiteralDouble, 1.0); |
||||
CheckToken("1.0r", Tokens.LiteralDouble, 1.0); |
||||
CheckToken("1.1r", Tokens.LiteralDouble, 1.1); |
||||
CheckToken("2e-5r", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2.0e-5r", Tokens.LiteralDouble, 2e-5); |
||||
CheckToken("2e5r", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e5r", Tokens.LiteralDouble, 2.2e5); |
||||
CheckToken("2e+5r", Tokens.LiteralDouble, 2e5); |
||||
CheckToken("2.2e+5r", Tokens.LiteralDouble, 2.2e5); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingle() |
||||
{ |
||||
CheckToken("1f", Tokens.LiteralSingle, 1.0f); |
||||
CheckToken("1.0f", Tokens.LiteralSingle, 1.0f); |
||||
CheckToken("1.1f", Tokens.LiteralSingle, 1.1f); |
||||
CheckToken("2e-5f", Tokens.LiteralSingle, 2e-5f); |
||||
CheckToken("2.0e-5f", Tokens.LiteralSingle, 2e-5f); |
||||
CheckToken("2e5f", Tokens.LiteralSingle, 2e5f); |
||||
CheckToken("2.2e5f", Tokens.LiteralSingle, 2.2e5f); |
||||
CheckToken("2e+5f", Tokens.LiteralSingle, 2e5f); |
||||
CheckToken("2.2e+5f", Tokens.LiteralSingle, 2.2e5f); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestDecimal() |
||||
{ |
||||
CheckToken("1d", Tokens.LiteralDecimal, 1m); |
||||
CheckToken("1.0d", Tokens.LiteralDecimal, 1.0m); |
||||
CheckToken("1.1d", Tokens.LiteralDecimal, 1.1m); |
||||
CheckToken("2e-5d", Tokens.LiteralDecimal, 2e-5m); |
||||
CheckToken("2.0e-5d", Tokens.LiteralDecimal, 2.0e-5m); |
||||
CheckToken("2e5d", Tokens.LiteralDecimal, 2e5m); |
||||
CheckToken("2.2e5d", Tokens.LiteralDecimal, 2.2e5m); |
||||
CheckToken("2e+5d", Tokens.LiteralDecimal, 2e5m); |
||||
CheckToken("2.2e+5d", Tokens.LiteralDecimal, 2.2e5m); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class TokenTests |
||||
{ |
||||
[Test] |
||||
public void TokenToStringDoesNotThrowException() |
||||
{ |
||||
Assert.DoesNotThrow( |
||||
() => { |
||||
string text = new Token(71, 1, 1).ToString(); |
||||
} |
||||
); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,993 @@
@@ -0,0 +1,993 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class XmlModeLexerTests |
||||
{ |
||||
#region Xml Tests
|
||||
[Test] |
||||
public void TagWithContent() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <Test>Hello World</Test>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
Assert.AreEqual(Tokens.Dim, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Assign, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void HtmlText() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <div><h1>Title</h1>" + |
||||
"<p>test test <br /> test</p></div>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
Assert.AreEqual(Tokens.Dim, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Assign, lexer.NextToken().Kind); |
||||
|
||||
// <div>
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// <h1>
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// Title
|
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
|
||||
// </h1>
|
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// <p>
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// test test
|
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
|
||||
// <br />
|
||||
Assert.AreEqual(Tokens.XmlOpenTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTagEmptyElement, lexer.NextToken().Kind); |
||||
|
||||
// test
|
||||
Assert.AreEqual(Tokens.XmlContent, lexer.NextToken().Kind); |
||||
|
||||
// </p>
|
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
// </div>
|
||||
Assert.AreEqual(Tokens.XmlOpenEndTag, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.Identifier, lexer.NextToken().Kind); |
||||
Assert.AreEqual(Tokens.XmlCloseTag, lexer.NextToken().Kind); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlLiteralsExample1() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim xml = <menu>\n" + |
||||
" <course name=\"appetizer\">\n" + |
||||
" <dish>Shrimp Cocktail</dish>\n" + |
||||
" <dish>Escargot</dish>\n" + |
||||
" </course>\n" + |
||||
" <course name=\"main\">\n" + |
||||
" <dish>Filet Mignon</dish>\n" + |
||||
" <dish>Garlic Potatoes</dish>\n" + |
||||
" <dish>Broccoli</dish>\n" + |
||||
" </course>\n" + |
||||
" <course name=\"dessert\">\n" + |
||||
" <dish>Chocolate Cheesecake</dish>\n" + |
||||
" </course>\n" + |
||||
" </menu>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
// <menu>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <course name=\"appetizer\">
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Shrimp Cocktail</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Escargot</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </course>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <course name=\"main\">
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Filet Mignon</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Garlic Potatoes</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Broccoli</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </course>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <course name=\"dessert\">
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// <dish>Chocolate Cheesecake</dish>
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </course>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
// whitespaces
|
||||
Tokens.XmlContent, |
||||
// </menu>
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleXmlWithComments() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim x = <?xml version=""1.0""?> <!-- Test file -->
|
||||
<Test> |
||||
<!-- Test data --> |
||||
<Data /> |
||||
</Test> |
||||
<!-- eof --> |
||||
<!-- hey, wait! --> |
||||
<?target some data?>")));
|
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlProcessingInstruction, Tokens.XmlContent, Tokens.XmlComment, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlComment, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlComment, Tokens.XmlComment, Tokens.XmlProcessingInstruction); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleEmptyTag() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <Test />"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleTag() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim x = <Test></Test>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlImport() |
||||
{ |
||||
string code = @"Imports System
|
||||
Imports System.Linq |
||||
|
||||
Imports <xmlns='http://icsharpcode.net/sharpdevelop/avalonedit'>
|
||||
Imports <xmlns:h='http://www.w3.org/TR/html4/'>
|
||||
|
||||
Class TestClass |
||||
Sub TestSub() |
||||
Dim xml = <h:table> |
||||
<h:tr> |
||||
<h:td>1. Cell</h:td> |
||||
</h:tr> |
||||
</h:table> |
||||
End Sub |
||||
End Class";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Imports, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Imports, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Imports, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.EOL, |
||||
Tokens.Imports, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.EOL, |
||||
Tokens.Class, Tokens.Identifier, Tokens.EOL, Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.EOL, Tokens.End, Tokens.Sub, Tokens.EOL, Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void CDataSection() |
||||
{ |
||||
string xml = @"Dim xml = <template>
|
||||
<name>test</name> |
||||
<language>VB</languge> |
||||
<file language='XAML'> |
||||
<![CDATA[<Window x:Class='DefaultNamespace.Window1' |
||||
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
|
||||
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
|
||||
Title='DefaultNamespace' Height='300' Width='300'> |
||||
<Grid> |
||||
|
||||
</Grid> |
||||
</Window>]]> |
||||
</file> |
||||
<file language='CSharp'> |
||||
<![CDATA[using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
|
||||
namespace DefaultNamespace |
||||
{ |
||||
/// <summary>
|
||||
/// Interaction logic for Window1.xaml
|
||||
/// </summary>
|
||||
public partial class Window1 : Window |
||||
{ |
||||
public Window1() |
||||
{ |
||||
InitializeComponent(); |
||||
} |
||||
} |
||||
}]]> |
||||
</file> |
||||
</template> |
||||
";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(xml))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, // 2
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 6
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 10
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 14
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 18
|
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, // 22
|
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, // 28
|
||||
Tokens.XmlContent, Tokens.XmlCData, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, // 34
|
||||
Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlCData, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void InlineVB() |
||||
{ |
||||
string code = @"Dim xml = <?xml version='1.0'?>
|
||||
<menu> |
||||
<course name=""appetizer""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""appetizer"" _ |
||||
Select <dish><%= m.Food %></dish> _ |
||||
%> |
||||
</course> |
||||
<course name=""main""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""main"" _ |
||||
Select <dish><%= m.Food %></dish> _ |
||||
%> |
||||
</course> |
||||
<course name=""dessert""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""dessert"" _ |
||||
Select <dish><%= m.Food %></dish> _ |
||||
%> |
||||
</course> |
||||
</menu>";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(code))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlProcessingInstruction, Tokens.XmlContent, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlStartInlineVB, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Where, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.Select, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlEndInlineVB, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlStartInlineVB, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Where, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.Select, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlEndInlineVB, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlStartInlineVB, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Where, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.LiteralString, Tokens.Select, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlEndInlineVB, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void InlineVB2() |
||||
{ |
||||
string code = @"Dim contact As XElement = <<%=elementName %>>
|
||||
<name><%= MyName %></name> |
||||
</>";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(code))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.As, Tokens.Identifier, Tokens.Assign, Tokens.XmlOpenTag, |
||||
Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.XmlEndInlineVB, Tokens.XmlCloseTag, Tokens.XmlContent, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlStartInlineVB, Tokens.Identifier, Tokens.XmlEndInlineVB, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, Tokens.XmlCloseTag); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlAccessOperators() |
||||
{ |
||||
string code = @"Dim childAxis = xml.<menu>.<course>
|
||||
Dim course3 = xml...<course>(2) |
||||
Dim childAxis = xml...<course> |
||||
For Each item In childAxis |
||||
Console.WriteLine(item.@name) |
||||
Next";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(code))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.Dot, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.Dot, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, |
||||
Tokens.EOL, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.TripleDot, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.OpenParenthesis, Tokens.LiteralInteger, Tokens.CloseParenthesis, |
||||
Tokens.EOL, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.TripleDot, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag, Tokens.EOL, Tokens.For, Tokens.Each, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.DotAt, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Next); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetXmlNamespace() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim name = GetXmlNamespace(x)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.GetXmlNamespace, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetXmlNamespace2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim name = GetXmlNamespace(db-name)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.GetXmlNamespace, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.CloseParenthesis); |
||||
|
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlInSelect() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim data = From x In list Select <test>x</test>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Select, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, Tokens.XmlOpenEndTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTag); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfExpressionTest() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Dim name = If(a <> 2, 4, 8)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.If, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.NotEqual, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.LiteralInteger, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfStatementTest() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("If a <> 2 Then Return"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.If, Tokens.Identifier, Tokens.NotEqual, Tokens.LiteralInteger, |
||||
Tokens.Then, Tokens.Return); |
||||
|
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug1() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim xml = <!-- test -->"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.XmlComment); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim xml = <?xml?><Data /><!-- test -->"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlProcessingInstruction, Tokens.XmlOpenTag, Tokens.Identifier, |
||||
Tokens.XmlCloseTagEmptyElement, Tokens.XmlComment); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug3() |
||||
{ |
||||
VBLexer lexer = GenerateLexerForSnippet(new StringReader("New String() {}"), SnippetType.Expression); |
||||
|
||||
CheckTokens(lexer, Tokens.New, Tokens.String, Tokens.OpenParenthesis, |
||||
Tokens.CloseParenthesis, Tokens.OpenCurlyBrace, Tokens.CloseCurlyBrace); |
||||
} |
||||
|
||||
[Test] |
||||
public void Bug4() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim x = From kvp As KeyValuePair(Of String, DataGridViewCellStyle) In styleCache.CellStyleCache _
|
||||
Select includeStyle(kvp.Key, kvp.Value)")));
|
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.As, Tokens.Identifier, |
||||
Tokens.OpenParenthesis, Tokens.Of, Tokens.String, Tokens.Comma, Tokens.Identifier, Tokens.CloseParenthesis, |
||||
Tokens.In, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.Dot, Tokens.Key, Tokens.Comma, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void LessThanCheck() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(@"Dim xml = <!-- test --><Data"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Dim, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.XmlComment, Tokens.LessThan, Tokens.Identifier); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Context Tests
|
||||
[Test] |
||||
public void MethodInvocation() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("DoSomething(<Test />, True)"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, Tokens.True, |
||||
Tokens.CloseParenthesis); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddHandlerStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("AddHandler <Test />, True"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.AddHandler, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, Tokens.True); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddHandlerStatement2() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("AddHandler <x />, <y />"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.AddHandler, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemoveHandlerStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("RemoveHandler <x />, <Data>5</Data>"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.RemoveHandler, Tokens.XmlOpenTag, |
||||
Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlContent, |
||||
Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorHandlingStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("On Error Resume Next\n" + |
||||
"On Error GoTo -1\n" + |
||||
"On Error GoTo 0\n" + |
||||
"On Error GoTo Test\n" + |
||||
"Error 5\n" + |
||||
"Error <Test />\n" + |
||||
"Resume Next\n" + |
||||
"Resume Label\n" + |
||||
"Resume 4"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.On, Tokens.Error, Tokens.Resume, Tokens.Next, Tokens.EOL, |
||||
Tokens.On, Tokens.Error, Tokens.GoTo, Tokens.Minus, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.On, Tokens.Error, Tokens.GoTo, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.On, Tokens.Error, Tokens.GoTo, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Error, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Error, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Resume, Tokens.Next, Tokens.EOL, |
||||
Tokens.Resume, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Resume, Tokens.LiteralInteger |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForLoopStatement() |
||||
{ |
||||
string statement = @"For <Test /> = <Test /> To <Test /> Step <Test />
|
||||
Next <Test />, <Test /> |
||||
|
||||
For Each <Test /> In <Test /> |
||||
Next <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.For, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.Assign, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.To, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.Step, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Next, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.For, Tokens.Each, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, |
||||
Tokens.In, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Next, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileLoopStatement() |
||||
{ |
||||
string statement = @"While <Test />
|
||||
End While";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.While, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.End, Tokens.While |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileLoopStatement2() |
||||
{ |
||||
string statement = @"Do While <Test />
|
||||
Loop";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.While, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Loop |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void WhileLoopStatement3() |
||||
{ |
||||
string statement = @"Do
|
||||
Loop While <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.EOL, |
||||
Tokens.Loop, Tokens.While, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntilLoopStatement() |
||||
{ |
||||
string statement = @"Do Until <Test />
|
||||
Loop";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.Until, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Loop |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntilLoopStatement2() |
||||
{ |
||||
string statement = @"Do
|
||||
Loop Until <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Do, Tokens.EOL, |
||||
Tokens.Loop, Tokens.Until, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfStatementLarge() |
||||
{ |
||||
string statement = @"If <Test /> Then
|
||||
Else If <Test /> Then |
||||
ElseIf <Test></Test> Then |
||||
Else |
||||
End If";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.If, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Then, Tokens.EOL, |
||||
Tokens.Else, Tokens.If, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Then, Tokens.EOL, |
||||
Tokens.ElseIf, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.XmlOpenEndTag, Tokens.Identifier, Tokens.XmlCloseTag, Tokens.Then, Tokens.EOL, |
||||
Tokens.Else, Tokens.EOL, |
||||
Tokens.End, Tokens.If |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectStatement() |
||||
{ |
||||
string statement = @"Select Case <Test />
|
||||
Case <Test />, <Test /> |
||||
Case Else |
||||
End Select";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Select, Tokens.Case, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Case, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Case, Tokens.Else, Tokens.EOL, |
||||
Tokens.End, Tokens.Select |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void TryStatement() |
||||
{ |
||||
string statement = @"Try
|
||||
Catch x |
||||
Catch y As Exception |
||||
Catch When <Test /> |
||||
Finally |
||||
End Try";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Try, Tokens.EOL, |
||||
Tokens.Catch, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Catch, Tokens.Identifier, Tokens.As, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Catch, Tokens.When, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Finally, Tokens.EOL, |
||||
Tokens.End, Tokens.Try |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ThrowStatement() |
||||
{ |
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement("Throw <Test />"))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Throw, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void BranchStatements() |
||||
{ |
||||
string statement = @"GoTo 5
|
||||
GoTo LabelName |
||||
Exit Do |
||||
Exit For |
||||
Exit While |
||||
Exit Select |
||||
Exit Sub |
||||
Exit Function |
||||
Exit Property |
||||
Exit Try |
||||
Continue Do |
||||
Continue For |
||||
Continue While |
||||
Stop |
||||
End |
||||
Return |
||||
Return 5 |
||||
Return <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.GoTo, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.GoTo, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Do, Tokens.EOL, |
||||
Tokens.Exit, Tokens.For, Tokens.EOL, |
||||
Tokens.Exit, Tokens.While, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Select, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Sub, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Function, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Property, Tokens.EOL, |
||||
Tokens.Exit, Tokens.Try, Tokens.EOL, |
||||
Tokens.Continue, Tokens.Do, Tokens.EOL, |
||||
Tokens.Continue, Tokens.For, Tokens.EOL, |
||||
Tokens.Continue, Tokens.While, Tokens.EOL, |
||||
Tokens.Stop, Tokens.EOL, |
||||
Tokens.End, Tokens.EOL, |
||||
Tokens.Return, Tokens.EOL, |
||||
Tokens.Return, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Return, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayHandlingStatements() |
||||
{ |
||||
string statement = @"Erase <Test />
|
||||
Erase <Test />, <Test /> |
||||
ReDim Preserve <Test />";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Erase, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.Erase, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.Comma, |
||||
Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.ReDim, Tokens.Preserve, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void UsingStatement() |
||||
{ |
||||
string statement = @"Using <Test />
|
||||
End Using";
|
||||
|
||||
VBLexer lexer = GenerateLexer(new StringReader(TestStatement(statement))); |
||||
|
||||
CheckHead(lexer); |
||||
|
||||
CheckTokens(lexer, Tokens.Using, Tokens.XmlOpenTag, Tokens.Identifier, Tokens.XmlCloseTagEmptyElement, Tokens.EOL, |
||||
Tokens.End, Tokens.Using |
||||
); |
||||
|
||||
CheckFoot(lexer); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewExpressionWithObjectInitializer() |
||||
{ |
||||
string code = @"New Common.ComboBoxItem With {.Item = _
|
||||
Localizer.GetString(""Month"" & initParameters.SelectedDate.FirstDayOfPreviousMonth.Month) & "" "" & |
||||
initParameters.SelectedDate.FirstDayOfPreviousMonth.Year, .Value = New Date(2010, initParameters.SelectedDate.FirstDayOfPreviousMonth.Month, 1)}";
|
||||
|
||||
VBLexer lexer = GenerateLexerForSnippet(new StringReader(code), SnippetType.Expression); |
||||
|
||||
CheckTokens(lexer, Tokens.New, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, |
||||
Tokens.With, Tokens.OpenCurlyBrace, Tokens.Dot, Tokens.Identifier, Tokens.Assign, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.ConcatString, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.ConcatString, |
||||
Tokens.LiteralString, Tokens.ConcatString, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, |
||||
Tokens.Dot, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Comma, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Assign, Tokens.New, Tokens.Date, Tokens.OpenParenthesis, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.Dot, |
||||
Tokens.Identifier, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis, Tokens.CloseCurlyBrace); |
||||
} |
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
VBLexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return new VBLexer(sr); |
||||
} |
||||
|
||||
VBLexer GenerateLexerForSnippet(StringReader sr, SnippetType type) |
||||
{ |
||||
var lexer = new VBLexer(sr); |
||||
lexer.SetInitialContext(type); |
||||
return lexer; |
||||
} |
||||
|
||||
string TestStatement(string stmt) |
||||
{ |
||||
return "Class Test\n" + |
||||
"Sub A\n" + |
||||
stmt + "\n" + |
||||
"End Sub\n" + |
||||
"End Class"; |
||||
} |
||||
|
||||
void CheckFoot(VBLexer lexer) |
||||
{ |
||||
CheckTokens(lexer, Tokens.EOL, Tokens.End, Tokens.Sub, Tokens.EOL, Tokens.End, Tokens.Class); |
||||
} |
||||
|
||||
void CheckHead(VBLexer lexer) |
||||
{ |
||||
CheckTokens(lexer, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL); |
||||
} |
||||
|
||||
void CheckTokens(VBLexer lexer, params int[] tokens) |
||||
{ |
||||
for (int i = 0; i < tokens.Length; i++) { |
||||
int token = tokens[i]; |
||||
Token t = lexer.NextToken(); |
||||
int next = t.Kind; |
||||
Assert.IsEmpty(lexer.Errors.ErrorOutput); |
||||
Assert.AreEqual(token, next, "{2} of {3}: expected: \"{0}\", was: \"{1}\"; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class CodeDOMParenthesizedExpressionTest |
||||
{ |
||||
[Test] |
||||
public void TestParenthesizedExpression() |
||||
{ |
||||
object output = new ParenthesizedExpression(new PrimitiveExpression(5, "5")).AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodePrimitiveExpression); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class CodeDOMPrimitiveExpressionsTests |
||||
{ |
||||
[Test] |
||||
public void TestPrimitiveExpression() |
||||
{ |
||||
object output = new PrimitiveExpression(5, "5").AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodePrimitiveExpression); |
||||
Assert.AreEqual(((CodePrimitiveExpression)output).Value, 5); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class CodeDOMTypeReferenceTest |
||||
{ |
||||
[TestAttribute] |
||||
public void InnerClassTypeReferencTest() |
||||
{ |
||||
InnerClassTypeReference ictr = new InnerClassTypeReference( |
||||
new TypeReference("OuterClass", new List<TypeReference> { new TypeReference("String") }), |
||||
"InnerClass", |
||||
new List<TypeReference> { new TypeReference("Int32"), new TypeReference("Int64") }); |
||||
Assert.AreEqual("OuterClass<String>+InnerClass<Int32,Int64>", ictr.ToString()); |
||||
CodeTypeOfExpression result = (CodeTypeOfExpression)new TypeOfExpression(ictr).AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.AreEqual("OuterClass`1+InnerClass`2", result.Type.BaseType); |
||||
Assert.AreEqual(3, result.Type.TypeArguments.Count); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Output.CodeDom.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class InvocationExpressionsTests |
||||
{ |
||||
[Test] |
||||
public void IdentifierOnlyInvocation() |
||||
{ |
||||
// InitializeComponents();
|
||||
SimpleNameExpression identifier = new SimpleNameExpression("InitializeComponents"); |
||||
InvocationExpression invocation = new InvocationExpression(identifier, new List<Expression>()); |
||||
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodeMethodInvokeExpression); |
||||
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; |
||||
Assert.AreEqual("InitializeComponents", mie.Method.MethodName); |
||||
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodOnThisReferenceInvocation() |
||||
{ |
||||
// InitializeComponents();
|
||||
MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents"); |
||||
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); |
||||
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodeMethodInvokeExpression); |
||||
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; |
||||
Assert.AreEqual("InitializeComponents", mie.Method.MethodName); |
||||
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression); |
||||
} |
||||
|
||||
[Test] |
||||
public void InvocationOfStaticMethod() |
||||
{ |
||||
// System.Drawing.Color.FromArgb();
|
||||
MemberReferenceExpression field = new MemberReferenceExpression(new SimpleNameExpression("System"), "Drawing"); |
||||
field = new MemberReferenceExpression(field, "Color"); |
||||
field = new MemberReferenceExpression(field, "FromArgb"); |
||||
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>()); |
||||
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null); |
||||
Assert.IsTrue(output is CodeMethodInvokeExpression); |
||||
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output; |
||||
Assert.AreEqual("FromArgb", mie.Method.MethodName); |
||||
Assert.IsTrue(mie.Method.TargetObject is CodeTypeReferenceExpression); |
||||
Assert.AreEqual("System.Drawing.Color", (mie.Method.TargetObject as CodeTypeReferenceExpression).Type.BaseType); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
|
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.PrettyPrinter |
||||
{ |
||||
[TestFixture] |
||||
public class SpecialOutputVisitorTest |
||||
{ |
||||
void TestProgram(string program) |
||||
{ |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); |
||||
outputVisitor.Options.IndentationChar = ' '; |
||||
outputVisitor.Options.TabSize = 2; |
||||
outputVisitor.Options.IndentSize = 2; |
||||
using (SpecialNodesInserter.Install(parser.Lexer.SpecialTracker.RetrieveSpecials(), |
||||
outputVisitor)) { |
||||
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); |
||||
} |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(program.Replace("\r", ""), outputVisitor.Text.TrimEnd().Replace("\r", "")); |
||||
parser.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void Enum() |
||||
{ |
||||
TestProgram("Enum Test\n" + |
||||
" ' a\n" + |
||||
" m1\n" + |
||||
" ' b\n" + |
||||
" m2\n" + |
||||
" ' c\n" + |
||||
"End Enum\n" + |
||||
"' d"); |
||||
} |
||||
|
||||
[Test] |
||||
public void CommentsInsideMethod() |
||||
{ |
||||
TestProgram(@"Public Class Class1
|
||||
Private Function test(l As Integer, lvw As Integer) As Boolean |
||||
' Begin |
||||
Dim i As Integer = 1 |
||||
Return False |
||||
' End of method |
||||
End Function |
||||
End Class");
|
||||
} |
||||
|
||||
[Test] |
||||
public void BlankLines() |
||||
{ |
||||
TestProgram("Imports System\n" + |
||||
"\n" + |
||||
"Imports System.IO"); |
||||
TestProgram("Imports System\n" + |
||||
"\n" + |
||||
"\n" + |
||||
"Imports System.IO"); |
||||
TestProgram("\n" + |
||||
"' Some comment\n" + |
||||
"\n" + |
||||
"Imports System.IO"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,670 @@
@@ -0,0 +1,670 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Ast; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.PrettyPrinter |
||||
{ |
||||
[TestFixture] |
||||
public class VBNetOutputTest |
||||
{ |
||||
void TestProgram(string program) |
||||
{ |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(program)); |
||||
parser.Parse(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); |
||||
outputVisitor.Options.OutputByValModifier = true; |
||||
outputVisitor.VisitCompilationUnit(parser.CompilationUnit, null); |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(StripWhitespace(program), StripWhitespace(outputVisitor.Text)); |
||||
} |
||||
|
||||
string StripWhitespace(string text) |
||||
{ |
||||
text = text.Trim().Replace("\t", "").Replace("\r", "").Replace("\n", " ").Replace(" ", " "); |
||||
while (text.Contains(" ")) { |
||||
text = text.Replace(" ", " "); |
||||
} |
||||
return text; |
||||
} |
||||
|
||||
void TestTypeMember(string program) |
||||
{ |
||||
TestProgram("Class A\n" + program + "\nEnd Class"); |
||||
} |
||||
|
||||
void TestStatement(string statement) |
||||
{ |
||||
TestTypeMember("Sub Method()\n" + statement + "\nEnd Sub"); |
||||
} |
||||
|
||||
void TestExpression(string expression) |
||||
{ |
||||
VBParser parser = ParserFactory.CreateParser(new StringReader(expression)); |
||||
Expression e = parser.ParseExpression(); |
||||
Assert.AreEqual("", parser.Errors.ErrorOutput); |
||||
VBNetOutputVisitor outputVisitor = new VBNetOutputVisitor(); |
||||
e.AcceptVisitor(outputVisitor, null); |
||||
Assert.AreEqual("", outputVisitor.Errors.ErrorOutput); |
||||
Assert.AreEqual(StripWhitespace(expression), StripWhitespace(outputVisitor.Text)); |
||||
} |
||||
|
||||
[Test] |
||||
public void Field() |
||||
{ |
||||
TestTypeMember("Private a As Integer"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Method() |
||||
{ |
||||
TestTypeMember("Sub Method()\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumWithBaseType() |
||||
{ |
||||
TestProgram("Public Enum Foo As UShort\nEnd Enum"); |
||||
} |
||||
|
||||
[Test] |
||||
public void PartialModifier() |
||||
{ |
||||
TestProgram("Public Partial Class Foo\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MustInheritClass() |
||||
{ |
||||
TestProgram("Public MustInherit Class Foo\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericClassDefinition() |
||||
{ |
||||
TestProgram("Public Class Foo(Of T As {IDisposable, ICloneable})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericClassDefinitionWithBaseType() |
||||
{ |
||||
TestProgram("Public Class Foo(Of T As IDisposable)\nInherits BaseType\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodDefinition() |
||||
{ |
||||
TestTypeMember("Public Sub Foo(Of T As {IDisposable, ICloneable})(ByVal arg As T)\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayRank() |
||||
{ |
||||
TestStatement("Dim a As Object(,,)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArrayInitialization() |
||||
{ |
||||
TestStatement("Dim a As Object() = New Object(10) {}"); |
||||
TestTypeMember("Private MultiDim As Integer(,) = {{1, 2}, {1, 3}}"); |
||||
TestExpression("New Integer(, ) {{1, 1}, {1, 1}}"); |
||||
TestTypeMember("Private _titles As String() = New String() {}"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodCallWithOptionalArguments() |
||||
{ |
||||
TestExpression("M(, )"); |
||||
} |
||||
|
||||
[Test] |
||||
public void IfStatement() |
||||
{ |
||||
TestStatement("If a Then\n" + |
||||
"\tm1()\n" + |
||||
"ElseIf b Then\n" + |
||||
"\tm2()\n" + |
||||
"Else\n" + |
||||
"\tm3()\n" + |
||||
"End If"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForNextLoop() |
||||
{ |
||||
TestStatement("For i = 0 To 10\n" + |
||||
"Next"); |
||||
TestStatement("For i As Long = 10 To 0 Step -1\n" + |
||||
"Next"); |
||||
} |
||||
|
||||
[Test] |
||||
public void DoLoop() |
||||
{ |
||||
TestStatement("Do\n" + |
||||
"Loop"); |
||||
TestStatement("Do\n" + |
||||
"Loop While Not (i = 10)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SelectCase() |
||||
{ |
||||
TestStatement(@"Select Case i
|
||||
Case 0 |
||||
Case 1 To 4 |
||||
Case Else |
||||
End Select");
|
||||
} |
||||
|
||||
[Test] |
||||
public void UsingStatement() |
||||
{ |
||||
TestStatement(@"Using nf As New Font(), nf2 As New List(Of Font)(), nf3 = Nothing
|
||||
Bla(nf) |
||||
End Using");
|
||||
} |
||||
|
||||
[Test] |
||||
public void UntypedVariable() |
||||
{ |
||||
TestStatement("Dim x = 0"); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntypedField() |
||||
{ |
||||
TestTypeMember("Dim x = 0"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Assignment() |
||||
{ |
||||
TestExpression("a = b"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SpecialIdentifiers() |
||||
{ |
||||
// Assembly, Ansi and Until are contextual keywords
|
||||
// Custom is valid inside methods, but not valid for field names
|
||||
TestExpression("Assembly = Ansi * [For] + Until - [Custom]"); |
||||
} |
||||
|
||||
[Test] |
||||
public void DictionaryAccess() |
||||
{ |
||||
TestExpression("c!key"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericMethodInvocation() |
||||
{ |
||||
TestExpression("GenericMethod(Of T)(arg)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SpecialIdentifierName() |
||||
{ |
||||
TestExpression("[Class]"); |
||||
} |
||||
|
||||
[Test] |
||||
public void GenericDelegate() |
||||
{ |
||||
TestProgram("Public Delegate Function Predicate(Of T)(ByVal item As T) As String"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Enum() |
||||
{ |
||||
TestProgram("Enum MyTest\nRed\n Green\n Blue\nYellow\n End Enum"); |
||||
} |
||||
|
||||
[Test] |
||||
public void EnumWithInitializers() |
||||
{ |
||||
TestProgram("Enum MyTest\nRed = 1\n Green = 2\n Blue = 4\n Yellow = 8\n End Enum"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SyncLock() |
||||
{ |
||||
TestStatement("SyncLock a\nWork()\nEnd SyncLock"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Using() |
||||
{ |
||||
TestStatement("Using a As New A()\na.Work()\nEnd Using"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Cast() |
||||
{ |
||||
TestExpression("CType(a, T)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void DirectCast() |
||||
{ |
||||
TestExpression("DirectCast(a, T)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TryCast() |
||||
{ |
||||
TestExpression("TryCast(a, T)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void PrimitiveCast() |
||||
{ |
||||
TestExpression("CStr(a)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeOfIs() |
||||
{ |
||||
TestExpression("TypeOf a Is String"); |
||||
} |
||||
|
||||
[Test] |
||||
public void PropertyWithAccessorAccessModifiers() |
||||
{ |
||||
TestTypeMember("Public Property ExpectsValue() As Boolean\n" + |
||||
"\tPublic Get\n" + |
||||
"\tEnd Get\n" + |
||||
"\tProtected Set\n" + |
||||
"\tEnd Set\n" + |
||||
"End Property"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AutoProperty() |
||||
{ |
||||
TestTypeMember("Public Property Value()"); |
||||
TestTypeMember("Public Property Value() As Integer"); |
||||
TestTypeMember("Public Property Value() As Integer = 5"); |
||||
TestTypeMember("Public Property Value() As New List()"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AbstractProperty() |
||||
{ |
||||
TestTypeMember("Public MustOverride Property ExpectsValue() As Boolean"); |
||||
TestTypeMember("Public MustOverride ReadOnly Property ExpectsValue() As Boolean"); |
||||
TestTypeMember("Public MustOverride WriteOnly Property ExpectsValue() As Boolean"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AbstractMethod() |
||||
{ |
||||
TestTypeMember("Public MustOverride Sub Run()"); |
||||
TestTypeMember("Public MustOverride Function Run() As Boolean"); |
||||
} |
||||
|
||||
[Test] |
||||
public void InterfaceImplementingMethod() |
||||
{ |
||||
TestTypeMember("Public Sub Run() Implements SomeInterface.Run\nEnd Sub"); |
||||
TestTypeMember("Public Function Run() As Boolean Implements SomeInterface.Bla\nEnd Function"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NamedAttributeArgument() |
||||
{ |
||||
TestProgram("<Attribute(ArgName := \"value\")> _\n" + |
||||
"Class Test\n" + |
||||
"End Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReturnTypeAttribute() |
||||
{ |
||||
TestTypeMember("Function A() As <Attribute> String\n" + |
||||
"End Function"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AssemblyAttribute() |
||||
{ |
||||
TestProgram("<Assembly: CLSCompliant>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ModuleAttribute() |
||||
{ |
||||
TestProgram("<Module: SuppressMessageAttribute>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Interface() |
||||
{ |
||||
TestProgram("Interface ITest\n" + |
||||
"Property GetterAndSetter() As Boolean\n" + |
||||
"ReadOnly Property GetterOnly() As Boolean\n" + |
||||
"WriteOnly Property SetterOnly() As Boolean\n" + |
||||
"Sub InterfaceMethod()\n" + |
||||
"Function InterfaceMethod2() As String\n" + |
||||
"End Interface"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnErrorStatement() |
||||
{ |
||||
TestStatement("On Error Resume Next"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverloadedConversionOperators() |
||||
{ |
||||
TestTypeMember("Public Shared Narrowing Operator CType(ByVal xmlNode As XmlNode) As TheBug\nEnd Operator"); |
||||
TestTypeMember("Public Shared Widening Operator CType(ByVal bugNode As TheBug) As XmlNode\nEnd Operator"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverloadedTrueFalseOperators() |
||||
{ |
||||
TestTypeMember("Public Shared Operator IsTrue(ByVal a As TheBug) As Boolean\nEnd Operator"); |
||||
TestTypeMember("Public Shared Operator IsFalse(ByVal a As TheBug) As Boolean\nEnd Operator"); |
||||
} |
||||
|
||||
[Test] |
||||
public void OverloadedOperators() |
||||
{ |
||||
TestTypeMember("Public Shared Operator +(ByVal bugNode As TheBug, ByVal bugNode2 As TheBug) As TheBug\nEnd Operator"); |
||||
TestTypeMember("Public Shared Operator >>(ByVal bugNode As TheBug, ByVal b As Integer) As TheBug\nEnd Operator"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AttributeOnParameter() |
||||
{ |
||||
TestTypeMember("Sub Main(ByRef one As Integer, ByRef two As Integer, <Out> ByRef three As Integer)\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FieldWithoutType() |
||||
{ |
||||
TestTypeMember("Dim X"); |
||||
} |
||||
|
||||
[Test] |
||||
public void UsingStatementForExistingVariable() |
||||
{ |
||||
TestStatement("Using obj\nEnd Using"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ContinueFor() |
||||
{ |
||||
TestStatement("Continue For"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ForNextStatementWithFieldLoopVariable() |
||||
{ |
||||
TestStatement("For Me.Field = 0 To 10\n" + |
||||
"Next Me.Field"); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithStatement() |
||||
{ |
||||
TestStatement("With Ejes\n" + |
||||
"\t.AddLine(New Point(Me.ClientSize.Width / 2, 0), (New Point(Me.ClientSize.Width / 2, Me.ClientSize.Height)))\n" + |
||||
"End With"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewConstraint() |
||||
{ |
||||
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), New})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void StructConstraint() |
||||
{ |
||||
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), Structure})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassConstraint() |
||||
{ |
||||
TestProgram("Public Class Rational(Of T, O As {IRationalMath(Of T), Class})\nEnd Class"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Integer() |
||||
{ |
||||
TestExpression("16"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Double() |
||||
{ |
||||
TestExpression("1.0"); |
||||
} |
||||
|
||||
[Test] |
||||
public void HexadecimalInteger() |
||||
{ |
||||
TestExpression("&H10"); |
||||
} |
||||
|
||||
[Test] |
||||
public void HexadecimalMinusOne() |
||||
{ |
||||
TestExpression("&Hffffffff"); |
||||
} |
||||
|
||||
[Test] |
||||
public void TypeCharacters() |
||||
{ |
||||
TestExpression("347S"); |
||||
TestExpression("347L"); |
||||
TestExpression("347D"); |
||||
TestExpression("347F"); |
||||
TestExpression("347US"); |
||||
TestExpression("347UI"); |
||||
TestExpression("347UL"); |
||||
TestExpression("\".\"C"); |
||||
} |
||||
|
||||
[Test] |
||||
public void AddressOf() |
||||
{ |
||||
TestExpression("AddressOf Abc"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ChainedConstructorCall() |
||||
{ |
||||
TestExpression("MyBase.New()"); |
||||
TestExpression("Me.New()"); |
||||
TestExpression("MyClass.New()"); |
||||
} |
||||
|
||||
[Test] |
||||
public void NewMethodCall() |
||||
{ |
||||
TestExpression("something.[New]()"); |
||||
} |
||||
|
||||
[Test] |
||||
public void ObjectInitializer() |
||||
{ |
||||
TestExpression("New StringWriter() With { _\n" + |
||||
" .NewLine = Environment.NewLine, _\n" + |
||||
" .Encoding = Encoding.UTF8 _\n" + |
||||
"}"); |
||||
} |
||||
|
||||
[Test] |
||||
public void EventDefinition() |
||||
{ |
||||
TestTypeMember("Public Event MyEvent(ByVal sender As Object)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Options() |
||||
{ |
||||
TestProgram("Option Strict On\n" + |
||||
"Option Explicit On\n" + |
||||
"Option Infer On\n" + |
||||
"Option Compare Text"); |
||||
} |
||||
|
||||
[Test] |
||||
public void UntypedForeach() |
||||
{ |
||||
TestStatement("For Each x In myGuidArray\nNext"); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodDefinitionWithOptionalParameter() |
||||
{ |
||||
TestTypeMember("Sub M(Optional ByVal msg As String = Nothing, Optional ByRef output As String = Nothing)\nEnd Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void Module() |
||||
{ |
||||
TestProgram("Module Test\n" + |
||||
" Sub M()\n" + |
||||
" End Sub\n" + |
||||
"End Module"); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithEvents() |
||||
{ |
||||
TestTypeMember("Dim WithEvents a As Button"); |
||||
} |
||||
|
||||
[Test] |
||||
public void FriendWithEventsField() |
||||
{ |
||||
TestTypeMember("Friend WithEvents Button1 As System.Windows.Forms.Button"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleFunctionLambda() |
||||
{ |
||||
TestExpression("Function(x) x * x"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleFunctionLambdaWithType() |
||||
{ |
||||
TestExpression("Function(x As Integer) x * x"); |
||||
} |
||||
|
||||
[Test] |
||||
public void SimpleSubLambdaWithType() |
||||
{ |
||||
TestExpression("Sub(x As Integer) Console.WriteLine(x)"); |
||||
} |
||||
|
||||
[Test] |
||||
public void BlockSubLambdaWithType() |
||||
{ |
||||
TestExpression("Sub(x As Integer)\n" + |
||||
" Console.WriteLine(x)\n" + |
||||
"End Sub"); |
||||
} |
||||
|
||||
[Test] |
||||
public void BlockFunctionLambdaWithType() |
||||
{ |
||||
TestExpression("Function(x As Integer) As Integer\n" + |
||||
" If x < 2 Then\n" + |
||||
" Return x\n" + |
||||
" End If\n" + |
||||
" Return x * x\n" + |
||||
"End Function"); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlSimple() |
||||
{ |
||||
TestExpression("<?xml?>\n" + |
||||
"<!-- test -->\n" + |
||||
"<Test>\n" + |
||||
" <A />\n" + |
||||
" <B test='a' <%= test %> />\n" + |
||||
"</Test>"); |
||||
} |
||||
|
||||
[Test] |
||||
public void XmlNested() |
||||
{ |
||||
TestExpression(@"<menu>
|
||||
<course name=""appetizer""> |
||||
<dish>Shrimp Cocktail</dish> |
||||
<dish>Escargot</dish> |
||||
</course> |
||||
<course name=""main""> |
||||
<dish>Filet Mignon</dish> |
||||
<dish>Garlic Potatoes</dish> |
||||
<dish>Broccoli</dish> |
||||
</course> |
||||
<course name=""dessert""> |
||||
<dish>Chocolate Cheesecake</dish> |
||||
</course> |
||||
</menu>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void XmlDocument() |
||||
{ |
||||
TestExpression(@"<?xml version=""1.0""?>
|
||||
<menu> |
||||
<course name=""appetizer""> |
||||
<dish>Shrimp Cocktail</dish> |
||||
<dish>Escargot</dish> |
||||
</course> |
||||
</menu>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void XmlNestedWithExpressions() |
||||
{ |
||||
TestExpression(@"<?xml version=""1.0""?>
|
||||
<menu> |
||||
<course name=""appetizer""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""appetizer"" _ |
||||
Select <dish><%= m.Food %></dish> %> |
||||
</course> |
||||
<course name=""main""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""main"" _ |
||||
Select <dish><%= m.Food %></dish> %> |
||||
</course> |
||||
<course name=""dessert""> |
||||
<%= From m In menu _ |
||||
Where m.Course = ""dessert"" _ |
||||
Select <dish><%= m.Food %></dish> %> |
||||
</course> |
||||
</menu>");
|
||||
} |
||||
|
||||
[Test] |
||||
public void XmlAccessExpressions() |
||||
{ |
||||
TestExpression("xml.<menu>.<course>"); |
||||
TestExpression("xml...<course>"); |
||||
TestExpression("xml...<course>(2)"); |
||||
TestExpression("item.@name"); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue