-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathPosition.cs
46 lines (40 loc) · 1.59 KB
/
Position.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using DuetAPI.Commands;
using DuetControlServer.Files;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System.IO;
using System.Threading.Tasks;
namespace UnitTests.File
{
[TestFixture]
public class Position
{
[Test]
public async Task TestPosition()
{
// NOTE: This test fails if the project isn't checked out as-is (i.e. if NL is converted to CRNL) .
// In that case the positions and lengths below don't match
string filePath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "../../../File/GCodes/Cura.gcode");
CodeFile file = new(System.IO.Path.GetFileName(filePath), filePath, DuetAPI.CodeChannel.File);
Code code;
// Line 1
code = (await file.ReadCodeAsync())!;
ClassicAssert.AreEqual(0, code.FilePosition);
ClassicAssert.AreEqual(15, code.Length);
// Line 2
code = (await file.ReadCodeAsync())!;
ClassicAssert.AreEqual(15, code.FilePosition);
ClassicAssert.AreEqual(11, code.Length);
// Line 3
code = (await file.ReadCodeAsync())!;
ClassicAssert.AreEqual(26, code.FilePosition);
ClassicAssert.AreEqual(26, code.Length);
// Go back to the first char of line 2. May be 16 if CRLF instead of NL is used
file.Position = 15;
// Read it again
code = (await file.ReadCodeAsync())!;
ClassicAssert.AreEqual(15, code.FilePosition);
ClassicAssert.AreEqual(11, code.Length);
}
}
}