Files
yamadashy--repomix/tests/core/treeSitter/parseFile.csharp.test.ts
T
wehub-resource-sync 719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:37 +08:00

332 lines
8.8 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { parseFile } from '../../../src/core/treeSitter/parseFile.js';
import { createMockConfig } from '../../../tests/testing/testUtils.js';
describe('parseFile for C#', () => {
test('should parse C# correctly', async () => {
const fileContent = `
// Program class containing the entry point
/// <summary>
/// The main program class
/// </summary>
class Program {
// The main entry point
/// <summary>
/// Writes a greeting to the console
/// </summary>
static void Main() {
Console.WriteLine("Hello, world!");
}
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = [
'// Program class containing the entry point',
'/// <summary>',
'class Program {',
'// The main program class',
'// The main entry point',
'/// Writes a greeting to the console',
'static void Main() {',
];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse class inheritance', async () => {
const fileContent = `
// Base class
public class BaseClass {
public virtual void Method() { }
}
// Derived class
public class DerivedClass : BaseClass {
public override void Method() { }
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = ['Base class', 'Derived class', 'class BaseClass', 'class DerivedClass', 'void Method()'];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse interface implementation', async () => {
const fileContent = `
// Interface definition
public interface IExample {
void DoSomething();
}
// Implementation
public class ExampleImpl : IExample {
public void DoSomething() {
Console.WriteLine("Doing something");
}
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = [
'Interface definition',
'Implementation',
'interface IExample',
'class ExampleImpl',
'void DoSomething()',
];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse generics without constraints', async () => {
const fileContent = `
// Generic class
public class GenericClass<T> {
public T Value { get; set; }
}
// Multiple type parameters
public class MultiGeneric<T, U> {
public T First { get; set; }
public U Second { get; set; }
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = ['Generic class', 'Multiple type parameters', 'class GenericClass', 'class MultiGeneric'];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse generics with constraints', async () => {
const fileContent = `
// Generic with class constraint
public class GenericClass<T> where T : class {
public T Value { get; set; }
}
// Multiple constraints
public class MultiConstraint<T, U>
where T : IComparable<T>
where U : new() {
public void Method<V>(V item) where V : struct {
Console.WriteLine(item);
}
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
// Should at least parse the classes and methods
const expectContents = [
'Generic with class constraint',
'Multiple constraints',
'class GenericClass',
'class MultiConstraint',
'void Method',
];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse properties and methods', async () => {
const fileContent = `
// Class with properties
public class Person {
// Name property
public string Name { get; set; }
// Age property
public int Age { get; set; }
// Method
public void Greet() {
Console.WriteLine("Hello");
}
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = [
'Class with properties',
'Name property',
'Age property',
'Method',
'class Person',
'void Greet()',
];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse nested classes', async () => {
const fileContent = `
// Outer class
public class OuterClass {
// Inner class
public class InnerClass {
public void InnerMethod() { }
}
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = ['Outer class', 'Inner class', 'class OuterClass', 'class InnerClass', 'void InnerMethod()'];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse multiple interface implementation', async () => {
const fileContent = `
// Multiple interfaces
public class MultiImpl : IDisposable, IComparable, ICloneable {
// Dispose method
public void Dispose() {
Console.WriteLine("Disposing");
}
// CompareTo method
public int CompareTo(object obj) {
return 0;
}
// Clone method
public object Clone() {
return this.MemberwiseClone();
}
}
`;
const filePath = 'dummy.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = [
'Multiple interfaces',
'class MultiImpl',
'IDisposable',
'IComparable',
'ICloneable',
'Dispose method',
'void Dispose()',
'CompareTo method',
'int CompareTo(',
'Clone method',
'object Clone()',
];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
test('should parse mixed inheritance with base class and interfaces', async () => {
const fileContent = `
// Base class
public class Animal {
public virtual void Speak() {
Console.WriteLine("Animal speaks");
}
}
// Interface for movement
public interface IMovable {
void Move();
}
// Interface for sound
public interface IAudible {
void Hear();
}
// Mixed inheritance: base class + multiple interfaces
public class Dog : Animal, IMovable, IAudible {
// Override Speak from Animal
public override void Speak() {
Console.WriteLine("Dog barks");
}
// Implementation of IMovable
public void Move() {
Console.WriteLine("Dog runs");
}
// Implementation of IAudible
public void Hear() {
Console.WriteLine("Dog listens");
}
}
`;
const filePath = 'inheritance.cs';
const config = {};
const result = await parseFile(fileContent, filePath, createMockConfig(config));
expect(typeof result).toBe('string');
const expectContents = [
// Base class
'Base class',
'class Animal',
'virtual void Speak()',
// Interfaces
'Interface for movement',
'interface IMovable',
'void Move()',
'Interface for sound',
'interface IAudible',
'void Hear()',
// Mixed inheritance class
'Mixed inheritance: base class + multiple interfaces',
'class Dog',
'Animal',
'IMovable',
'IAudible',
'void Move()',
'void Hear()',
'override void Speak()',
];
for (const expectContent of expectContents) {
expect(result).toContain(expectContent);
}
});
});