-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeScriptAnalyzerTests.cs
More file actions
88 lines (74 loc) · 2.9 KB
/
TypeScriptAnalyzerTests.cs
File metadata and controls
88 lines (74 loc) · 2.9 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.IO;
using Xunit;
using TypeScriptParser.Tests;
namespace TypeScriptParser.Tests
{
public class TypeScriptAnalyzerTests
{
[Fact]
public void AnalyzeFile_SimpleExportFunction_ShouldReturnExportedFunction()
{
// Arrange
var analyzer = new TypeScriptAnalyzer();
string sourceCode = "export function hello(): string { return 'world'; }";
// Act
var exportedFunctions = analyzer.AnalyzeFile(sourceCode);
// Assert
Assert.Single(exportedFunctions);
Assert.Equal("hello", exportedFunctions[0].Name);
Assert.Equal("string", exportedFunctions[0].ReturnType);
Assert.Empty(exportedFunctions[0].Parameters);
}
[Fact]
public void AnalyzeFile_FunctionWithParameters_ShouldParseParametersCorrectly()
{
// Arrange
var analyzer = new TypeScriptAnalyzer();
string sourceCode = "export function add(a: number, b: number): number { return a + b; }";
// Act
var exportedFunctions = analyzer.AnalyzeFile(sourceCode);
// Assert
Assert.Single(exportedFunctions);
var func = exportedFunctions[0];
Assert.Equal("add", func.Name);
Assert.Equal("number", func.ReturnType);
Assert.Equal(2, func.Parameters.Count);
Assert.Equal("a", func.Parameters[0].Name);
Assert.Equal("number", func.Parameters[0].Type);
Assert.Equal("b", func.Parameters[1].Name);
Assert.Equal("number", func.Parameters[1].Type);
}
[Fact]
public void AnalyzeFile_EmptyFile_ShouldReturnEmptyList()
{
// Arrange
var analyzer = new TypeScriptAnalyzer();
string sourceCode = "";
// Act
var exportedFunctions = analyzer.AnalyzeFile(sourceCode);
// Assert
Assert.Empty(exportedFunctions);
}
[Fact]
public void AnalyzeFile_NoExportedFunctions_ShouldReturnEmptyList()
{
// Arrange
var analyzer = new TypeScriptAnalyzer();
string sourceCode = "function internal(): void { console.log('internal'); }";
// Act
var exportedFunctions = analyzer.AnalyzeFile(sourceCode);
// Assert
Assert.Empty(exportedFunctions);
}
[Fact]
public void Dispose_AfterDispose_AnalyzeFileShouldThrowObjectDisposedException()
{
// Arrange
var analyzer = new TypeScriptAnalyzer();
analyzer.Dispose();
// Act & Assert
Assert.Throws<ObjectDisposedException>(() => analyzer.AnalyzeFile("export function test() {}"));
}
}
}