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
187 lines
4.4 KiB
TypeScript
187 lines
4.4 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
import { parseFile } from '../../../src/core/treeSitter/parseFile.js';
|
|
import { createMockConfig } from '../../testing/testUtils.js';
|
|
|
|
describe('parseFile for Go', () => {
|
|
test('should parse Go correctly', async () => {
|
|
const fileContent = `
|
|
// Package main is the entry point
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// User represents a person
|
|
type User struct {
|
|
Name string
|
|
Age int
|
|
}
|
|
|
|
// Greeter is something that can greet
|
|
type Greeter interface {
|
|
Greet() string
|
|
}
|
|
|
|
// Constants
|
|
const (
|
|
MaxUsers = 100
|
|
Version = "1.0.0"
|
|
)
|
|
|
|
// Variables
|
|
var (
|
|
debugMode = false
|
|
logLevel = "info"
|
|
)
|
|
|
|
// SayHello prints a greeting message
|
|
func SayHello(name string) {
|
|
fmt.Printf("Hello, %s!\\n", name)
|
|
}
|
|
|
|
// Greet implements the Greeter interface
|
|
func (u User) Greet() string {
|
|
return fmt.Sprintf("Hello, I'm %s!", u.Name)
|
|
}
|
|
|
|
// Main entry point
|
|
func main() {
|
|
user := User{Name: "John", Age: 30}
|
|
fmt.Println(user.Greet())
|
|
SayHello(os.Args[1])
|
|
}
|
|
`;
|
|
const filePath = 'sample.go';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
// Package declaration
|
|
'package main',
|
|
'Package main is the entry point',
|
|
|
|
// Imports
|
|
'import (',
|
|
'"fmt"',
|
|
'"os"',
|
|
|
|
// Struct definition
|
|
'type User struct',
|
|
'User represents a person',
|
|
'Name string',
|
|
'Age int',
|
|
|
|
// Interface definition
|
|
'type Greeter interface',
|
|
'Greeter is something that can greet',
|
|
'Greet() string',
|
|
|
|
// Constants
|
|
'const (',
|
|
'MaxUsers = 100',
|
|
'Version = "1.0.0"',
|
|
|
|
// Variables
|
|
'var (',
|
|
'debugMode = false',
|
|
'logLevel = "info"',
|
|
|
|
// Functions
|
|
'func SayHello(name string)',
|
|
'SayHello prints a greeting message',
|
|
|
|
// Methods
|
|
'func (u User) Greet() string',
|
|
'Greet implements the Greeter interface',
|
|
|
|
// Main function
|
|
'func main()',
|
|
'Main entry point',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should handle single imports', async () => {
|
|
const fileContent = `
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Println("Hello, world!")
|
|
}
|
|
`;
|
|
const filePath = 'simple.go';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = ['import "fmt"', 'func main()'];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should handle different comment styles', async () => {
|
|
const fileContent = `
|
|
// This is a line comment
|
|
package main
|
|
|
|
/* This is a block comment
|
|
spanning multiple lines */
|
|
func main() {
|
|
// Inside function comment
|
|
fmt.Println("Hello")
|
|
}
|
|
`;
|
|
const filePath = 'comments.go';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
'This is a line comment',
|
|
'This is a block comment\n spanning multiple lines',
|
|
'Inside function comment',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should handle type aliases', async () => {
|
|
const fileContent = `
|
|
package main
|
|
|
|
// UserID is a type alias for integer
|
|
type UserID int
|
|
|
|
// Result is a type alias for map
|
|
type Result map[string]interface{}
|
|
`;
|
|
const filePath = 'types.go';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
'type UserID int',
|
|
'UserID is a type alias for integer',
|
|
'type Result map[string]interface{}',
|
|
'Result is a type alias for map',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
});
|