Skip to content

Commit 1ad0cea

Browse files
committed
Abstraction for TextFile
1 parent 5eadc6c commit 1ad0cea

File tree

5 files changed

+187
-6
lines changed

5 files changed

+187
-6
lines changed

MonoDevelop.Debugger.Tests/DebugTests.MonoDevelop.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ protected string TargetProjectSourceDir
4545
}
4646
}
4747

48-
protected DebuggerSession CreateSession (string test)
48+
protected DebuggerSession CreateSession (string test, string engineId)
4949
{
50-
switch (EngineId) {
50+
switch (engineId) {
5151
case "MonoDevelop.Debugger.Win32":
5252
runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
5353
break;
@@ -76,7 +76,7 @@ protected DebuggerSession CreateSession (string test)
7676
}
7777

7878
if (runtime == null) {
79-
Assert.Ignore ("Runtime not found for: {0}", EngineId);
79+
Assert.Ignore ("Runtime not found for: {0}", engineId);
8080
}
8181

8282
Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version + " " + (IntPtr.Size == 8 ? "64bit" : "32bit"));

MonoDevelop.Debugger.Tests/DebugTests.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
using Mono.Debugging.Soft;
3434
using Mono.Debugging.Client;
3535

36-
using MonoDevelop.Projects.Text;
37-
3836
using NUnit.Framework;
3937

4038
namespace MonoDevelop.Debugger.Tests
@@ -77,6 +75,35 @@ public void IgnoreSoftDebugger (string message = "")
7775
}
7876
}
7977

78+
// TODO: implement in another part of the class
79+
#region Partial Definitions
80+
81+
/// <summary>
82+
/// Returns parent directory of target executable
83+
/// </summary>
84+
//protected string TargetExeDirectory { get { throw new NotImplementedException (); } }
85+
86+
/// <summary>
87+
/// Returns parent directory of target project sources
88+
/// </summary>
89+
//protected string TargetProjectSourceDir { get { throw new NotImplementedException (); } }
90+
91+
/// <summary>
92+
/// Creates debugger session. The type of session is dependent on <paramref name="engineId"/>
93+
/// </summary>
94+
/// <param name="test">test name, usually used as entry point method in target exe</param>
95+
/// <param name="engineId">the ID of debugger engine</param>
96+
//protected DebuggerSession CreateSession (string test, string engineId);
97+
98+
/// <summary>
99+
/// Creates start info to run the app
100+
/// </summary>
101+
/// <param name="test">test name</param>
102+
//protected DebuggerStartInfo CreateStartInfo (string test);
103+
104+
#endregion
105+
106+
80107
[TestFixtureSetUp]
81108
public virtual void SetUp ()
82109
{
@@ -109,7 +136,7 @@ protected string TargetExePath
109136
protected void Start (string test)
110137
{
111138
TestName = test;
112-
Session = CreateSession (test);
139+
Session = CreateSession (test, EngineId);
113140

114141
var dsi = CreateStartInfo (test);
115142
var soft = dsi as SoftDebuggerStartInfo;

MonoDevelop.Debugger.Tests/MonoDevelop.Debugger.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
<Compile Include="CorBreakpointsAndSteppingTests.cs" />
5050
<Compile Include="SdbBreakpointsAndSteppingTests.cs" />
5151
<Compile Include="AdvancedEvaluationTests.cs" />
52+
<Compile Include="TextFile.cs" />
53+
<Compile Include="TextFile.MonoDevelop.cs" />
5254
</ItemGroup>
5355
<ItemGroup>
5456
<ProjectReference Include="..\MonoDevelop.Debugger.csproj">
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using MDTextFile = MonoDevelop.Projects.Text.TextFile;
2+
3+
namespace MonoDevelop.Debugger.Tests
4+
{
5+
public partial class TextFile
6+
{
7+
readonly MDTextFile file;
8+
9+
TextFile (MDTextFile file)
10+
{
11+
this.file = file;
12+
}
13+
14+
/// <summary>
15+
/// Reads file from given path
16+
/// </summary>
17+
/// <param name="sourcePath"></param>
18+
/// <returns></returns>
19+
public static TextFile ReadFile (string sourcePath)
20+
{
21+
return new TextFile(MDTextFile.ReadFile (sourcePath));
22+
}
23+
24+
/// <summary>
25+
/// Content of the file
26+
/// </summary>
27+
public string Text
28+
{
29+
get{
30+
return file.Text;
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Full path to file
36+
/// </summary>
37+
public string Name
38+
{
39+
get{
40+
return file.Name;
41+
}
42+
}
43+
44+
/// <summary>
45+
/// Returns line and column (1-based) by given offset (0-based)
46+
/// </summary>
47+
/// <param name="offset">0-based</param>
48+
/// <param name="line">1-based</param>
49+
/// <param name="col">1-based</param>
50+
public void GetLineColumnFromPosition (int offset, out int line, out int col)
51+
{
52+
file.GetLineColumnFromPosition (offset, out line, out col);
53+
}
54+
55+
/// <summary>
56+
/// Returns offset by given line and column (1-based)
57+
/// </summary>
58+
/// <param name="line">line (1-based)</param>
59+
/// <param name="column">column (1-based)</param>
60+
/// <returns>offset (0-based)</returns>
61+
public int GetPositionFromLineColumn (int line, int column)
62+
{
63+
return file.GetPositionFromLineColumn (line, column);
64+
}
65+
66+
/// <summary>
67+
/// Returns the text starting from <paramref name="offset"/> with length=<paramref name="length"/>
68+
/// </summary>
69+
/// <param name="offset">0-based starting offset</param>
70+
/// <param name="length">length of text</param>
71+
/// <returns></returns>
72+
public string GetText (int offset, int length)
73+
{
74+
return file.GetText (offset, length);
75+
}
76+
77+
/// <summary>
78+
/// Returns length of the given line (1-based)
79+
/// </summary>
80+
/// <param name="line">1-based line</param>
81+
/// <returns></returns>
82+
public int GetLineLength (int line)
83+
{
84+
return file.GetLineLength (line);
85+
}
86+
}
87+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#pragma warning disable 1587
2+
namespace MonoDevelop.Debugger.Tests
3+
{
4+
public partial class TextFile
5+
{
6+
// TODO: Implement in another part of the class
7+
8+
/// <summary>
9+
/// Reads file from given path
10+
/// </summary>
11+
/// <param name="sourcePath"></param>
12+
/// <returns></returns>
13+
// public static TextFile ReadFile (string sourcePath)
14+
// {
15+
// }
16+
17+
/// <summary>
18+
/// Content of the file
19+
/// </summary>
20+
// public string Text { get; }
21+
/// <summary>
22+
/// Full path to file
23+
/// </summary>
24+
// public string Name { get; }
25+
26+
/// <summary>
27+
/// Returns line and column (1-based) by given offset (0-based)
28+
/// </summary>
29+
/// <param name="offset">0-based</param>
30+
/// <param name="line">1-based</param>
31+
/// <param name="col">1-based</param>
32+
// public void GetLineColumnFromPosition (int offset, out int line, out int col)
33+
// {
34+
// }
35+
36+
/// <summary>
37+
/// Returns offset by given line and column (1-based)
38+
/// </summary>
39+
/// <param name="line">line (1-based)</param>
40+
/// <param name="column">column (1-based)</param>
41+
/// <returns>offset (0-based)</returns>
42+
// public int GetPositionFromLineColumn (int line, int column)
43+
// {
44+
// }
45+
46+
/// <summary>
47+
/// Returns the text starting from <paramref name="offset"/> with length=<paramref name="length"/>
48+
/// </summary>
49+
/// <param name="offset">0-based starting offset</param>
50+
/// <param name="length">length of text</param>
51+
/// <returns></returns>
52+
// public string GetText (int offset, int length)
53+
// {
54+
// }
55+
56+
/// <summary>
57+
/// Returns length of the given line (1-based)
58+
/// </summary>
59+
/// <param name="line">1-based line</param>
60+
/// <returns></returns>
61+
// public int GetLineLength (int line)
62+
// {
63+
// }
64+
}
65+
}

0 commit comments

Comments
 (0)