refactor: move test code samples to fixture files

This commit is contained in:
Paul Gauthier (aider) 2024-11-27 07:05:36 -08:00
parent 8c218e9edc
commit 4580fac6fa

View file

@ -380,62 +380,17 @@ public class Test implements Greeting {
), ),
"javascript": ( "javascript": (
"test.js", "test.js",
"""// Class definition "", # Now reads from fixture file
class Person {
constructor(name) {
this.name = name;
}
sayHello() {
return `Hello, ${this.name}!`;
}
}
// Function declaration
function greet(person) {
return person.sayHello();
}
// Variables and constants
const DEFAULT_NAME = 'World';
let currentPerson = new Person(DEFAULT_NAME);
// Export for use in other modules
module.exports = {
Person,
greet,
DEFAULT_NAME
};
""",
"Person", # Key symbol to check "Person", # Key symbol to check
), ),
"ocaml": ( "ocaml": (
"test.ml", "test.ml",
"""(* Module definition *) "", # Now reads from fixture file
module Greeter = struct
type person = {
name: string;
age: int
}
let create_person name age =
{name; age}
let greet person =
Printf.printf "Hello, %s! You are %d years old.\\n"
person.name person.age
end
(* Outside the module *)
let () =
let person = Greeter.create_person "Alice" 30 in
Greeter.greet person
""",
"Greeter", # Key symbol to check "Greeter", # Key symbol to check
), ),
"php": ( "php": (
"test.php", "test.php",
'<?php\nfunction greet($name) {\n echo "Hello, $name!";\n}\n?>\n', "", # Now reads from fixture file
"greet", # Key symbol to check "greet", # Key symbol to check
), ),
"python": ( "python": (
@ -445,50 +400,17 @@ let () =
), ),
"ql": ( "ql": (
"test.ql", "test.ql",
'predicate greet(string name) {\n name = "World"\n}\n', "", # Now reads from fixture file
"greet", # Key symbol to check "greet", # Key symbol to check
), ),
"ruby": ( "ruby": (
"test.rb", "test.rb",
'def greet(name)\n puts "Hello, #{name}!"\nend\n', "", # Now reads from fixture file
"greet", # Key symbol to check "greet", # Key symbol to check
), ),
"rust": ( "rust": (
"test.rs", "test.rs",
"""// Define a trait "", # Now reads from fixture file
trait Greeting {
fn greet(&self) -> String;
}
// Define a struct
struct Person {
name: String,
age: u32,
}
// Implement the trait for Person
impl Greeting for Person {
fn greet(&self) -> String {
format!("Hello, {}! You are {} years old.", self.name, self.age)
}
}
// Implementation block for Person
impl Person {
fn new(name: String, age: u32) -> Self {
Person { name, age }
}
}
// Constants
const DEFAULT_NAME: &str = "World";
const MAX_AGE: u32 = 150;
fn main() {
let person = Person::new(DEFAULT_NAME.to_string(), 30);
println!("{}", person.greet());
}
""",
"Person", # Key symbol to check "Person", # Key symbol to check
), ),
"typescript": ( "typescript": (