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
203 lines
4.7 KiB
TypeScript
203 lines
4.7 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 C', () => {
|
|
test('should parse C correctly', async () => {
|
|
const fileContent = `
|
|
/**
|
|
* A simple C program demonstrating various language features
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
/* Define a constant */
|
|
#define MAX_SIZE 100
|
|
|
|
/**
|
|
* Structure representing a person
|
|
*/
|
|
struct Person {
|
|
char* name;
|
|
int age;
|
|
};
|
|
|
|
/**
|
|
* Union for different number types
|
|
*/
|
|
union Number {
|
|
int i;
|
|
float f;
|
|
double d;
|
|
};
|
|
|
|
/**
|
|
* Enum for status codes
|
|
*/
|
|
enum Status {
|
|
SUCCESS = 0,
|
|
ERROR = 1,
|
|
PENDING = 2
|
|
};
|
|
|
|
/* Type definition for a pointer to function returning int */
|
|
typedef int (*IntFunctionPtr)(int, int);
|
|
|
|
/**
|
|
* Add two integers
|
|
* @param a First integer
|
|
* @param b Second integer
|
|
* @return Sum of a and b
|
|
*/
|
|
int add(int a, int b) {
|
|
// Add two numbers
|
|
return a + b;
|
|
}
|
|
|
|
/**
|
|
* Main function
|
|
* @return Exit status
|
|
*/
|
|
int main(int argc, char** argv) {
|
|
// Create a person
|
|
struct Person person;
|
|
person.name = "John";
|
|
person.age = 30;
|
|
|
|
// Print info
|
|
printf("Name: %s, Age: %d\\n", person.name, person.age);
|
|
|
|
// Use union
|
|
union Number num;
|
|
num.i = 42;
|
|
printf("Integer: %d\\n", num.i);
|
|
|
|
// Function pointer
|
|
IntFunctionPtr operation = add;
|
|
printf("Result: %d\\n", operation(5, 3));
|
|
|
|
return SUCCESS;
|
|
}
|
|
`;
|
|
const filePath = 'sample.c';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
// Comments
|
|
'A simple C program demonstrating various language features',
|
|
'Define a constant',
|
|
|
|
// Struct
|
|
'struct Person',
|
|
'Structure representing a person',
|
|
|
|
// Union
|
|
'Union for different number types',
|
|
|
|
// Enum
|
|
'enum Status',
|
|
'Enum for status codes',
|
|
|
|
// Type definition comment
|
|
'Type definition for a pointer to function returning int',
|
|
|
|
// Functions
|
|
'int add(int a, int b)',
|
|
'Add two integers',
|
|
'@param a First integer',
|
|
'@param b Second integer',
|
|
'@return Sum of a and b',
|
|
|
|
// Main function
|
|
'int main(int argc, char** argv)',
|
|
'Main function',
|
|
'@return Exit status',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should handle function declarations and definitions', async () => {
|
|
const fileContent = `
|
|
/* Function declaration */
|
|
void print_message(const char* message);
|
|
|
|
/* Function definition */
|
|
int calculate_sum(int values[], int count) {
|
|
int sum = 0;
|
|
for (int i = 0; i < count; i++) {
|
|
sum += values[i];
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
/* Function with no params */
|
|
void init(void) {
|
|
// Initialize something
|
|
}
|
|
`;
|
|
const filePath = 'functions.c';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
'Function declaration',
|
|
'Function definition',
|
|
'int calculate_sum(int values[], int count)',
|
|
'Function with no params',
|
|
'void init(void)',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
|
|
test('should handle complex type definitions', async () => {
|
|
const fileContent = `
|
|
/* Simple typedef */
|
|
typedef unsigned long size_t;
|
|
|
|
/* Struct typedef */
|
|
typedef struct {
|
|
double x;
|
|
double y;
|
|
} Point;
|
|
|
|
/* Enum typedef */
|
|
typedef enum {
|
|
RED,
|
|
GREEN,
|
|
BLUE
|
|
} Color;
|
|
|
|
/* Function pointer typedef */
|
|
typedef void (*Callback)(void* data);
|
|
|
|
/* Array typedef */
|
|
typedef char String[256];
|
|
`;
|
|
const filePath = 'types.c';
|
|
const config = {};
|
|
const result = await parseFile(fileContent, filePath, createMockConfig(config));
|
|
expect(typeof result).toBe('string');
|
|
|
|
const expectContents = [
|
|
'Simple typedef',
|
|
'Struct typedef',
|
|
'Enum typedef',
|
|
'Function pointer typedef',
|
|
'Array typedef',
|
|
];
|
|
|
|
for (const expectContent of expectContents) {
|
|
expect(result).toContain(expectContent);
|
|
}
|
|
});
|
|
});
|