-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsageDetectionTests.cs
More file actions
64 lines (54 loc) · 2.46 KB
/
UsageDetectionTests.cs
File metadata and controls
64 lines (54 loc) · 2.46 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Xunit;
using FluentAssertions;
using ZXBasicStudio.BuildSystem;
using System.IO;
using System.Collections.Generic;
using System.Linq;
namespace ZXBasicStudioTest
{
public class UsageDetectionTests
{
[Fact]
public void ZXBasicMap_ShouldDetectSigilVariableUsage()
{
// Arrange
string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempDir);
string mainFileContent = "dim a$ as string\na$ = \"Hello\"\nprint a$";
string mainPath = Path.Combine(tempDir, "main.bas");
File.WriteAllText(mainPath, mainFileContent);
var mainCodeFile = new ZXCodeFile(mainPath);
var allFiles = new List<ZXCodeFile> { mainCodeFile };
string buildLog = ""; // No unused warnings for now
// Act
var basicMap = new ZXBasicMap(mainCodeFile, allFiles, buildLog);
// Assert
basicMap.GlobalVariables.Should().Contain(v => v.Name == "a$");
var varA = basicMap.GlobalVariables.First(v => v.Name == "a$");
varA.Unused.Should().BeFalse("a$ is used later in the code");
// Cleanup
Directory.Delete(tempDir, true);
}
[Fact]
public void ZXBasicMap_ShouldDistinguishSigilAndNonSigilVariables()
{
// Arrange
string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(tempDir);
// a is used, a$ is NOT used (only defined)
string mainFileContent = "dim a as integer\ndim a$ as string\na = 10\nprint a";
string mainPath = Path.Combine(tempDir, "main.bas");
File.WriteAllText(mainPath, mainFileContent);
var mainCodeFile = new ZXCodeFile(mainPath);
var allFiles = new List<ZXCodeFile> { mainCodeFile };
string buildLog = "";
// Act
var basicMap = new ZXBasicMap(mainCodeFile, allFiles, buildLog);
// Assert
basicMap.GlobalVariables.Should().Contain(v => v.Name == "a");
basicMap.GlobalVariables.Should().NotContain(v => v.Name == "a$", "a$ is NOT used, so it should be skipped (if it's not marked as unused in buildLog, the local regex check should mark it as unused and it's skipped in GlobalVariables list generation)");
// Cleanup
Directory.Delete(tempDir, true);
}
}
}