diff --git a/core/autocomplete/test/filter.test.ts b/core/autocomplete/test/filter.test.ts deleted file mode 100644 index 171b1cb44..000000000 --- a/core/autocomplete/test/filter.test.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - AutocompleteFileringTestInput, - testAutocompleteFiltering, -} from "./util"; -import { TEST_CASES } from "./testCases"; - -const filterTestCases = (tests: AutocompleteFileringTestInput[]) => { - if (tests.some((test) => test.options?.only)) { - return tests.filter((test) => test.options?.only); - } - - return tests; -}; - -describe("llms/Mock", () => { - describe("Autocomplete Filtering Tests", () => { - beforeEach(async () => { - await new Promise((resolve) => setTimeout(resolve, 50)); - }); - - describe("Should return unmodified LLM output", () => { - it.each(filterTestCases(TEST_CASES))("$description", async (testCase) => { - await testAutocompleteFiltering(testCase); - }); - }); - - // TODO: Add test cases where modifying LLM output is desirable - describe.skip("Should return modified LLM output", () => {}); - }); -}); diff --git a/core/autocomplete/test/testCases.ts b/core/autocomplete/test/testCases.ts deleted file mode 100644 index 2deeec9de..000000000 --- a/core/autocomplete/test/testCases.ts +++ /dev/null @@ -1,2013 +0,0 @@ -import { dedent } from "../../util"; -import { AutocompleteFileringTestInput } from "./util"; - -export const TEST_CASES: AutocompleteFileringTestInput[] = [ - { - description: "should pass", - filename: "test.js", - input: "console.log('Hello <|fim|>!');", - llmOutput: "World", - expectedCompletion: "World", - }, - { - description: - "Should preserve closing brackets when the opening bracket is not a part of the completion.", - filename: "test.js", - input: dedent` - class Calculator { - constructor() { - this.result = 0; - } - - add(number) { - this.result += number; - return this; - } - - subtract(number) { - this.result -= number; - return this; - } - - multiply(number) { - this.result *= number; - return this; - } - - divide(number) { - <|fim|> - - getResult() { - return this.result; - } - - reset() { - this.result = 0; - return this; - } - } - `, - llmOutput: dedent`if (number === 0) { - throw new Error("Cannot divide by zero"); - } - this.result /= number; - return this; - }`, - expectedCompletion: dedent`if (number === 0) { - throw new Error("Cannot divide by zero"); - } - this.result /= number; - return this; - }`, - }, - { - description: "Should multiline-autocomplete CSS blocks", - input: `body { - font-family: Arial, sans-serif; - font-size: 16px; - color: #333333; -} - -h1 { - font-size: 24px; - font-weight: bold; - color: #000000; -} - -h4<|fim|> - -a { - text-decoration: none; - color: #007bff; -} - -.container { - width: 100%; - max-width: 1200px; - margin: 0 auto; - padding: 20px; -} - -.button { - display: inline-block; - padding: 10px 20px; - background-color: #007bff; - color: #ffffff;`, - llmOutput: ` { - font-size: 18px; - font-weight: bold; - color: #000000; -}`, - expectedCompletion: ` { - font-size: 18px; - font-weight: bold; - color: #000000; -}`, - filename: "test.css", - }, - { - description: "Should complete CSS rules inside a nested selector", - filename: "styles.css", - input: ` -.container { - display: flex; - justify-content: center; - align-items: center; - width: 100%; - height: 100vh; - - .inner { - <|fim|> - } -} -`, - llmOutput: `width: 50%; - height: 50%; - background-color: #f0f0f0;`, - expectedCompletion: `width: 50%; - height: 50%; - background-color: #f0f0f0;`, - }, - - { - description: - "Should complete a CSS rule when the property is partially typed", - filename: "styles.css", - input: ` -button { - border: 2px solid #000; - border-radius<|fim|> -}`, - llmOutput: `: 5px;`, - expectedCompletion: `: 5px;`, - }, - - { - description: "Should handle CSS autocomplete with a single bracket present", - filename: "styles.css", - input: ` -.card { - box-shadow: 0 4px 8px rgba(0,0,0,0.2); - transition: 0.3s; - padding: 16px; - border-bottom-left-radius: <|fim|>px; - border-bottom-right-radius: 8px; -} -`, - llmOutput: `8`, - expectedCompletion: `8`, - }, - - { - description: "Should autocomplete CSS pseudoclass", - filename: "pseudoClass.css", - input: ` -input:focus { - outline: none; - border: 2px solid <|fim|>; -} -`, - llmOutput: `#4CAF50;`, - expectedCompletion: `#4CAF50;`, - }, - - { - description: "Should handle CSS variable syntax", - filename: "variables.css", - input: ` -:root { - --primary-color: #3498db; - --padding: 10px; -} - -.section { - background-color: var(<|fim|>); - padding: var(--padding); -} -`, - llmOutput: `--primary-color`, - expectedCompletion: `--primary-color`, - }, - { - description: "Should complete CSS grid template columns", - filename: "grid.css", - input: ` -.grid-container { - display: grid; - grid-template-columns: repeat(<|fim|>); - grid-gap: 10px; -} -`, - llmOutput: `3, 1fr`, - expectedCompletion: `3, 1fr`, - }, - - { - description: "Should complete PHP function inside a class with comments", - input: `name = $name; - $this->email = $email; - } - - public function <|fim|> - - public function setEmail($email) { - $this->email = $email; - } -}`, - llmOutput: `getDetails() { - return "Name: " . $this->name . ", Email: " . $this->email; - }`, - expectedCompletion: `getDetails() { - return "Name: " . $this->name . ", Email: " . $this->email; - }`, - filename: "User.php", - }, - - { - description: "Should autocomplete PHP function with inline logic", - input: ` -} - -echo calculateArea(5, 3);`, - llmOutput: `return $length * $width;`, - expectedCompletion: `return $length * $width;`, - filename: "areaCalculator.php", - }, - - { - description: "Should handle PHP completion in the middle of an array", - input: `); - -echo "First color is: " . $colors[0];`, - llmOutput: `"Blue"`, - expectedCompletion: `"Blue"`, - filename: "colors.php", - }, - { - description: "Should autocomplete React return statements (jsx)", - input: `import React from "react"; - -export const Button = ({ - onClick, - children, -}: { - children: React.ReactNode; - onClick: () => void; -}) => { - return ( -<|fim|> - ); -};`, - llmOutput: ``, - expectedCompletion: ``, - filename: "Button.tsx", - }, - { - description: "Should autocomplete React state initialization", - input: `import React, { useState } from "react"; - -export const Counter = () => { - const [count, setCount] = useState(<|fim|>); - - return ( -
-

You clicked {count} times

- -
- ); -};`, - llmOutput: `0`, - expectedCompletion: `0`, - filename: "Counter.tsx", - }, - - { - description: "Should autocomplete React effect hook", - input: `import React, { useState, useEffect } from "react"; - -export const Timer = () => { - const [seconds, setSeconds] = useState(0); - - useEffect(() => { - const interval = setInterval(() => { - setSeconds(seconds + 1); - }, 1000); - - <|fim|>; - - return () => clearInterval(interval); - }, [seconds]); - - return ( -
-

{seconds} seconds have passed.

-
- ); -};`, - llmOutput: `return () => clearInterval(interval);`, - expectedCompletion: `return () => clearInterval(interval);`, - filename: "Timer.tsx", - }, - - { - description: "Should autocomplete React component methods", - input: `import React from "react"; - -class Form extends React.Component { - constructor(props) { - super(props); - this.state = { name: '' }; - } - - handleChange = (event) => { - <|fim|> - } - - handleSubmit = (event) => { - event.preventDefault(); - alert('A name was submitted: ' + this.state.name); - } - - render() { - return ( -
- - -
- ); - } -}`, - llmOutput: `this.setState({ name: event.target.value });`, - expectedCompletion: `this.setState({ name: event.target.value });`, - filename: "Form.tsx", - }, - { - description: "Should autocomplete Python function definition", - filename: "test.py", - input: `def calculate_area(length, width): - area = length * width - return area - -def calculate_perimeter(length, width): - <|fim|> -`, - llmOutput: `perimeter = 2 * (length + width) - return perimeter`, - expectedCompletion: `perimeter = 2 * (length + width) - return perimeter`, - }, - { - description: "Should complete Python class method with self", - filename: "test.py", - input: `class BankAccount: - def __init__(self, owner, balance=0): - self.owner = owner - self.balance = balance - - def deposit(self, amount): - self.balance += amount - return self.balance - - def withdraw(self, amount): - <|fim|> -`, - llmOutput: `if amount > self.balance: - return "Insufficient funds" - self.balance -= amount - return self.balance`, - expectedCompletion: `if amount > self.balance: - return "Insufficient funds" - self.balance -= amount - return self.balance`, - }, - { - description: "Should autocomplete Python list comprehension", - filename: "test.py", - input: `squares = [x**2 for x in range(10)] -even_squares = [x for x in squares if x % 2 == 0] -print(even_squares) - -odd_squares = [<|fim|> -print(odd_squares) -`, - llmOutput: `x for x in squares if x % 2 != 0`, - expectedCompletion: `x for x in squares if x % 2 != 0`, - }, - { - description: "Should handle python multi-line string", - filename: "test.py", - input: `def create_greeting(name): - greeting = """Hello, """ + name + """! -Welcome to our community. We hope you have a great time here. -If you have any questions, feel free to reach out.""" - return greeting - -message = create_greeting("Alice") -print(message) - -multi_line_message = """<|fim|> -print(multi_line_message) -`, - llmOutput: `This is a multi-line message. -It continues across multiple lines, -which allows for easy reading and formatting. -""" -`, - expectedCompletion: `This is a multi-line message. -It continues across multiple lines, -which allows for easy reading and formatting. -""" -`, - }, - { - description: "Should autocomplete a simple Go function declaration", - filename: "simpleFunction.go", - input: `package main - -import ( - "fmt" -) - -func main() { - fmt.Println("Hello, World!") -} - -func calculateArea<|fim|>`, - llmOutput: `(length float64, width float64) float64 { - return length * width -}`, - expectedCompletion: `(length float64, width float64) float64 { - return length * width -}`, - }, - - { - description: - "Should handle autocomplete in the middle of a Go struct definition", - filename: "structDefinition.go", - input: `package main - -type Person struct { - FirstName string - LastName string - Age int - Address Address -} - -type Address struct { - Street string - City <|fim|> -} - -func main() {}`, - llmOutput: `string - State string - ZipCode string -}`, - expectedCompletion: `string - State string - ZipCode string -}`, - }, - - { - description: "Should autocomplete a missing Go function body bracket", - filename: "missingBracket.go", - input: `package main - -func add(a int, b int) int { - return a + b<|fim|> - -func multiply(a int, b int) int { - return a * b -} - -func main() { - result1 := add(2, 3) - result2 := multiply(4, 5) - println(result1, result2) -}`, - llmOutput: ` -}`, - expectedCompletion: ` -}`, - }, - { - description: - "Should autocomplete SQL query with subquery and alias in SELECT clause", - filename: "complex_query.sql", - input: `SELECT u.id, - u.name, - (SELECT COUNT(*) FROM orders o WHERE o.user_id = u.id) AS order_count - FROM users u - WHERE u.active = 1 - <|fim|>`, - llmOutput: ` AND EXISTS (SELECT 1 FROM transactions t WHERE t.user_id = u.id AND t.amount > 100)`, - expectedCompletion: ` AND EXISTS (SELECT 1 FROM transactions t WHERE t.user_id = u.id AND t.amount > 100)`, - }, - { - description: - "Should autocomplete SQL query with nested functions and missing bracket", - filename: "_nested_function.sql", - input: `SELECT name, ROUND(AVG(rating), 2) as avg_rating - FROM movies - WHERE release_year > 2000 AND director = 'Christopher Nolan' - GROUP BY name - HAVING avg_rating > <|fim|>`, - llmOutput: `8.5)`, - expectedCompletion: `8.5)`, - }, - { - description: - "Should autocomplete multi-line SQL query with CASE statements", - filename: "case_statement.sql", - input: `SELECT order_id, - order_date, - CASE - WHEN status = 'shipped' THEN 'Completed' - WHEN status = 'pending' THEN 'Pending Approval' - <|fim|> - ELSE 'Unknown' - END as order_status - FROM orders`, - llmOutput: `WHEN status = 'cancelled' THEN 'Cancelled'`, - expectedCompletion: `WHEN status = 'cancelled' THEN 'Cancelled'`, - }, - { - description: "Should autocomplete HTML paragraph content", - input: ` - - Document - - -

<|fim|>

- -`, - llmOutput: `This is a paragraph with some sample text.`, - expectedCompletion: `This is a paragraph with some sample text.`, - filename: "test.html", - }, - { - description: "Should autocomplete HTML attributes within a tag", - input: `
- > -
-

Title

-

Description text.

-
-
`, - llmOutput: `alt="Description of image"`, - expectedCompletion: `alt="Description of image"`, - filename: "test.html", - }, - { - description: "Should autocomplete HTML nested tags", - input: ``, - llmOutput: `>Item 4`, - expectedCompletion: `>Item 4`, - filename: "test.html", - }, - - { - description: "Should complete a class method in Ruby", - input: ` -class Greeter - def initialize(name) - @name = name - end - - def greet - puts "Hello, <|fim|> - end -end - -g = Greeter.new("World") -g.greet -`, - llmOutput: "#{@name}!", - expectedCompletion: "#{@name}!", - filename: "greeter.rb", - }, - { - description: "Should complete Ruby if-else block", - input: ` -number = 10 - -if number > 5 - puts "Number is greater than 5" -<|fim|> -end -`, - llmOutput: `else - puts "Number is 5 or less"`, - expectedCompletion: `else - puts "Number is 5 or less"`, - filename: "conditional.rb", - }, - { - description: "Should complete Ruby array method", - input: ` -numbers = [1, 2, 3, 4, 5] -squared_numbers = numbers.<|fim|> -`, - llmOutput: `map { |n| n ** 2 }`, - expectedCompletion: `map { |n| n ** 2 }`, - filename: "array_methods.rb", - }, - { - description: "Should autocomplete a Java method within a class", - filename: "Calculator.java", - input: ` -public class Calculator { - private double result; - - public Calculator() { - this.result = 0.0; - } - - public void add(double number) { - result += number; -<|fim|>`, - llmOutput: ` - } - - public void subtract(double number) { - result -= number; - } -`, - expectedCompletion: ` - } - - public void subtract(double number) { - result -= number; - } -`, - }, - { - description: "Should autocomplete Java when inside a block", - filename: "Main.java", - input: ` -public class Main { - public static void main(String[] args) { - for (int i = 0; i < 10; i++) { - if (i % 2 == 0) { - System.out.println("Even: " + i); - } else { -<|fim|> - } - } - } -}`, - llmOutput: ` - System.out.println("Odd: " + i); -`, - expectedCompletion: ` - System.out.println("Odd: " + i); -`, - }, - { - description: "Should autocomplete Java within a string", - filename: "App.java", - input: ` -public class App { - public static void main(String[] args) { - String message = "Hello, <|fim|>"; - System.out.println(message); - } -}`, - llmOutput: `World`, - expectedCompletion: `World`, - }, - { - description: - "Should autocomplete a C++ class definition with a constructor", - filename: "test.cpp", - input: "class Vehicle { public: Vehicle(<|fim|>); };", - llmOutput: "int wheels, double weight", - expectedCompletion: "int wheels, double weight", - }, - { - description: "Should complete a C++ method declaration inside a class", - filename: "test.cpp", - input: - "class Calculator { public: int add(int a, int b); int subtract(int a, int b);<|fim|> };", - llmOutput: " int multiply(int a, int b);", - expectedCompletion: " int multiply(int a, int b);", - }, - - { - description: "Should autocomplete C++ for loop syntax", - filename: "test.cpp", - input: ` - int sum = 0; - for (int i = 0; i < 10; <|fim|>) { - sum += i; - } - `, - llmOutput: "i++", - expectedCompletion: "i++", - }, - { - description: "Should autocomplete a Markdown list with nested items", - filename: "test.md", - input: ` -- Item 1 -- Item 2 - - Subitem 1 - <|fim|> -- Item 3 -`, - llmOutput: ` - Subitem 2 - - Subitem 3 -`, - expectedCompletion: ` - Subitem 2 - - Subitem 3 -`, - }, - { - description: - "Should autocomplete a Markdown heading and preserve formatting", - filename: "test.md", - input: `# My Document - -## Introduction -This is a sample document for testing. - -## <|fim|> -### Conclusion -Thank you for reading. -`, - llmOutput: `Features -Here is a list of features: -- Feature 1 -- Feature 2 -`, - expectedCompletion: `Features -Here is a list of features: -- Feature 1 -- Feature 2 -`, - }, - { - description: "Should complete a Markdown code block", - filename: "test.md", - input: ` -Here is a sample JavaScript function: - -\`\`\`javascript -function sayHello() { - console.log("Hello, <|fim|> -} -\`\`\` -`, - llmOutput: `world!"); -`, - expectedCompletion: `world!"); -`, - }, - { - description: "Should autocomplete JSON object inside an array", - filename: "data.json", - input: `{ - "users": [ - { "id": 1, "name": "Alice" }, - { "id": 2, "name": "Bob" } - <|fim|> - ] -}`, - llmOutput: `, { "id": 3, "name": "Charlie" }`, - expectedCompletion: `, { "id": 3, "name": "Charlie" }`, - }, - { - description: "Should autocomplete nested JSON objects", - filename: "config.json", - input: `{ - "server": { - "host": "localhost", - "port": 8080, - "features": { - "enableLogging": true, - "maxConnections": 100 - <|fim|> - } -}`, - llmOutput: `, - "timeout": 5000 - }`, - expectedCompletion: `, - "timeout": 5000 - }`, - }, - { - description: "Should autocomplete JSON object with missing bracket", - filename: "settings.json", - input: `{ - "theme": "dark", - "language": "en"<|fim|> - `, - llmOutput: `, - "notifications": true - }`, - expectedCompletion: `, - "notifications": true - }`, - }, - { - description: "Should autocomplete within a CSV record", - filename: "test.csv", - input: `Name, Age, City -John Doe, 30, New York -Jane Smith<|fim|>`, - llmOutput: `, 25, Los Angeles`, - expectedCompletion: `, 25, Los Angeles`, - }, - { - description: - "Should complete CSV record when starting in the middle of a word", - filename: "test.csv", - input: `Product, Price, Quantity -Laptop, 1200, 5 -Smart<|fim|>`, - llmOutput: `phone, 800, 10`, - expectedCompletion: `phone, 800, 10`, - }, - { - description: "Should complete CSV structure adding closing brackets", - filename: "test.csv", - input: `ID, Name, JoiningDate -1, Alice, 2023-01-10 -2, B<|fim|>`, - llmOutput: `ob, 2023-02-10`, - expectedCompletion: `ob, 2023-02-10`, - }, - { - description: "Should complete YAML list item and preserve structure", - filename: "test.yaml", - input: ` - services: - - name: web - image: nginx - - name: app<|fim|> - volumes: - - volume1 - - volume2 - `, - llmOutput: ` - image: node - `, - expectedCompletion: ` - image: node - `, - }, - { - description: - "Should complete YAML key-value pair inside a nested structure", - filename: "test.yaml", - input: ` - version: '3' - services: - db: - image: postgres - environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: pass - POSTGRES_DB: mydb<|fim|> - `, - llmOutput: ` - PGDATA: /var/lib/postgresql/data/pgdata - `, - expectedCompletion: ` - PGDATA: /var/lib/postgresql/data/pgdata - `, - }, - { - description: "Should complete YAML block within an existing block", - filename: "test.yaml", - input: ` - pipelines: - branches: - master: - - step: - name: Build and Test - script: - - npm install - - npm run test - - step: - name: Deploy<|fim|> - `, - llmOutput: ` - script: - - npm run deploy - `, - expectedCompletion: ` - script: - - npm run deploy - `, - }, - { - description: - "Should autocomplete a Rust function implementation inside a struct", - filename: "main.rs", - input: ` -struct Calculator { - result: f64, -} - -impl Calculator { - fn new() -> Self { - Calculator { result: 0.0 } - } - - fn add(&mut self, number: f64) { - self.result += number; - } - - fn subtract(&mut self, number: f64) { - self.result -= number; - } - - fn multiply(&mut self, number: f64) { - self.result *= number; - } - - fn divide(&mut self, number: f64) { - if number != 0.0 { - self.result /= number; - } else { - println!("Cannot divide by zero."); - } - } - - fn reset(&mut self) { - self.result = 0.0; - } - - fn get_result(&self) -> f64 { - self.result - } - - fn<|fim|> -} -`, - llmOutput: ` divide(&mut self, number: f64) { - if number != 0.0 { - self.result /= number; - } else { - println!("Cannot divide by zero."); - } -}`, - expectedCompletion: ` divide(&mut self, number: f64) { - if number != 0.0 { - self.result /= number; - } else { - println!("Cannot divide by zero."); - } -}`, - }, - { - description: "Should autocomplete Rust match arms", - filename: "main.rs", - input: ` -fn get_status_code_description(code: u16) -> &'static str { - match code { - 200 => "OK", - 404 => "Not Found", - 500 => "Internal Server Error", - <|fim|> - } -} -`, - llmOutput: `403 => "Forbidden", - 401 => "Unauthorized", - _ => "Unknown Status", -`, - expectedCompletion: `403 => "Forbidden", - 401 => "Unauthorized", - _ => "Unknown Status", -`, - }, - { - description: "Should autocomplete Rust struct definition", - filename: "main.rs", - input: ` -struct User { - id: u32, - username: String, - email: String, - is_active: bool, - <|fim|> -} - -impl User { - fn new(id: u32, username: String, email: String) -> Self { - User { - id, - username, - email, - is_active: true, - } - } -} -`, - llmOutput: `created_at: String, - updated_at: String,`, - expectedCompletion: `created_at: String, - updated_at: String,`, - }, - { - description: "Haskell: Nested pattern matching with let bindings", - filename: "NestedPattern.hs", - input: `module NestedPattern where - -data Tree a = Leaf a | Node (Tree a) (Tree a) - -sumTree :: Num a => Tree a -> a -sumTree (Leaf x) = x -sumTree (Node left right) = - let leftSum = <|fim|> - rightSum = sumTree right - in leftSum + rightSum`, - llmOutput: `sumTree left`, - expectedCompletion: `sumTree left`, - }, - { - description: "Haskell: Complex function with where clause and guards", - filename: "QuadraticSolver.hs", - input: `module QuadraticSolver where - -solveQuadratic :: (Ord a, Floating a) => a -> a -> a -> Maybe (a, a) -solveQuadratic a b c - | discriminant < 0 = Nothing - | otherwise = Just (x1, x2) - where - discriminant = b^2 - 4*a*c - sqrtD = sqrt discriminant - x1 = (-b + sqrtD) / (2*a) - <|fim|> = (-b - sqrtD) / (2*a)`, - llmOutput: `x2`, - expectedCompletion: `x2`, - }, - { - description: "Haskell: List comprehension with complex filter", - filename: "PrimeNumbers.hs", - input: `module PrimeNumbers where - -primesUpTo :: Int -> [Int] -primesUpTo n = [x | x <- [2..n], isPrime x] - where isPrime num = <|fim|> && all (\d -> num \`mod\` d /= 0) [2..(floor . sqrt $ fromIntegral num)]`, - llmOutput: `num > 1`, - expectedCompletion: `num > 1`, - }, - { - description: "Should autocomplete Dart class methods", - filename: "calculator.dart", - input: ` -class Calculator { - double result = 0.0; - - void add(double number) { - result += number; - } - - void multiply(double number) { - result *= number; - } - - <|fim|> - - double getResult() { - return result; - } -}`, - llmOutput: `void subtract(double number) { - result -= number; - }`, - expectedCompletion: `void subtract(double number) { - result -= number; - }`, - }, - { - description: "Should handle string interpolation in Dart", - filename: "greetings.dart", - input: ` -void main() { - var name = "World"; - print('Hello, <|fim|>!'); -}`, - llmOutput: `\${name}`, - expectedCompletion: `\${name}`, - }, - { - description: "Should autocomplete within a Dart function body", - filename: "counter.dart", - input: ` -class Counter { - int count = 0; - - void increment() { - count++; - } - - void decrement() { - <|fim|> - - void reset() { - count = 0; - } -}`, - llmOutput: `count--;`, - expectedCompletion: `count--;`, - }, - { - description: - "Should autocomplete Clojure function definition with missing closing parenthesis", - input: `(defn calculate-sum [a b] - (let [sum (+ a b)] - (println "The sum is" sum) - sum<|fim|>`, - llmOutput: `))`, - expectedCompletion: `))`, - filename: "test.clj", - }, - { - description: - "Should autocomplete missing part of a Clojure map within a function", - input: `(defn get-user [] - {:username "johndoe" - :email "johndoe@example.com" - :age 30 - <|fim|> - (println "User information loaded"))`, - llmOutput: `:location "Unknown"}`, - expectedCompletion: `:location "Unknown"}`, - filename: "test.clj", - }, - { - description: - "Should autocomplete inside a Clojure vector within a looping construct", - input: `(defn odd-numbers [] - (loop [nums [1 3 5<|fim|> 9 11]] - (when (seq nums) - (println (first nums)) - (recur (rest nums)))))`, - llmOutput: ` 7,`, - expectedCompletion: ` 7,`, - filename: "test.clj", - }, - { - description: "Should autocomplete R function definition", - filename: "calculate.R", - input: ` -calculate_mean <- function(numbers) { - total <- sum(numbers) - <|fim|> -}`, - llmOutput: `mean_value <- total / length(numbers) - return(mean_value)`, - expectedCompletion: `mean_value <- total / length(numbers) - return(mean_value)`, - }, - { - description: "Should complete R loop and print statement", - filename: "loopPrint.R", - input: ` -numbers <- c(1, 2, 3, 4, 5) -for (number in numbers) { - print(<|fim|>) -}`, - llmOutput: `number)`, - expectedCompletion: `number)`, - }, - { - description: "Should autocomplete R data frame creation", - filename: "dataFrame.R", - input: ` -data <- data.frame( - Name = c("Alice", "Bob", "Charlie"), - Age = c(25, 30, 35), - <|fim|> -)`, - llmOutput: `Height = c(165, 180, 175)`, - expectedCompletion: `Height = c(165, 180, 175)`, - }, - { - description: "Should autocomplete R if-else statement", - filename: "condition.R", - input: ` -grade <- 85 -if (grade >= 90) { - print("A") -} else if (grade >= 80) { - <|fim|> -} else { - print("C") -}`, - llmOutput: `print("B")`, - expectedCompletion: `print("B")`, - }, - { - description: "Should autocomplete R ggplot2 plot structure", - filename: "plot.R", - input: ` -library(ggplot2) - -ggplot(data=mtcars, aes(x=wt, y=mpg)) + - geom_point() + - <|fim|>`, - llmOutput: `geom_smooth(method='lm', se=FALSE)`, - expectedCompletion: `geom_smooth(method='lm', se=FALSE)`, - }, - { - description: "Should autocomplete Scala class with a method", - filename: "Person.scala", - input: `class Person(val name: String, val age: Int) { - def greet(): String = { - <|fim|> - } - }`, - llmOutput: `s"Hello, my name is $name and I am $age years old."`, - expectedCompletion: `s"Hello, my name is $name and I am $age years old."`, - }, - - { - description: "Should handle Scala case class with a missing field", - filename: "Person.scala", - input: `case class Address(city: String, postalCode: String) - case class Person(name: String, age: Int, address: Address) - - val alice = Person("Alice", 30, Address("Wonderland", <|fim|>))`, - llmOutput: `"12345")`, - expectedCompletion: `"12345")`, - }, - - { - description: "Should autocomplete Scala function with missing body bracket", - filename: "Math.scala", - input: `object MathUtils { - def add(a: Int, b: Int): Int = { - a + b<|fim|> - - def multiply(a: Int, b: Int): Int = { - a * b - } - } - - object Main extends App { - println(MathUtils.add(3, 5)) - println(MathUtils.multiply(4, 6)) - }`, - llmOutput: ` - }`, - expectedCompletion: ` - }`, - }, - { - description: "Should autocomplete C function definition", - filename: "math_utils.c", - input: `#include - -int add(int a, int b) { - return a + b; -} - -int multiply(int a, int b) { - return a * b; -} - -int subtract(int a, int b) { - <|fim|> -} - -int main() { - printf("Result: %d", add(2, 3)); - return 0; -}`, - llmOutput: `return a - b;`, - expectedCompletion: `return a - b;`, - }, - - { - description: "Should handle C struct with missing field initialization", - filename: "person.c", - input: `#include - -typedef struct { - char name[50]; - int age; - float height; -} Person; - -int main() { - Person alice = {"Alice", 30, <|fim|>}; - printf("Name: %s, Age: %d, Height: %.2f", alice.name, alice.age, alice.height); - return 0; -}`, - llmOutput: `5.5`, - expectedCompletion: `5.5`, - }, - - { - description: "Should autocomplete C function with missing body bracket", - filename: "area.c", - input: `#include - -double calculateCircleArea(double radius) { - const double pi = 3.14159; - return pi * radius * radius;<|fim|> - -double calculateRectangleArea(double length, double width) { - return length * width; -} - -int main() { - printf("Circle Area: %.2f", calculateCircleArea(5.0)); - printf("Rectangle Area: %.2f", calculateRectangleArea(4.0, 6.0)); - return 0; -}`, - llmOutput: ` -}`, - expectedCompletion: ` -}`, - }, - { - description: "Should autocomplete a simple Kotlin function declaration", - filename: "simpleFunction.kt", - input: ` -fun main() { - println("Hello, World!") -} - -fun calculateArea(length: Double, width: Double): Double <|fim|>`, - llmOutput: `{ - return length * width -}`, - expectedCompletion: `{ - return length * width -}`, - }, - { - description: "Should handle autocomplete inside a Kotlin data class", - filename: "dataClass.kt", - input: ` -data class User( - val id: Int, - val name: String, - val email: String, - <|fim|> -)`, - llmOutput: `val age: Int`, - expectedCompletion: `val age: Int`, - }, - { - description: - "Should complete Kotlin if-else structure with missing brackets", - filename: "controlStructure.kt", - input: ` -fun getMax(a: Int, b: Int): Int { - if (a > b<|fim|> - } else { - return b - } -}`, - llmOutput: `) { - return a`, - expectedCompletion: `) { - return a`, - }, - { - description: "Should autocomplete Solidity function definition", - filename: "SimpleStorage.sol", - input: ` -pragma solidity ^0.8.0; - -contract SimpleStorage { - uint private data; - - function set(uint x) public { - data = x; - } - - function get() public view returns (uint) { - <|fim|> - } -} - `, - llmOutput: `return data;`, - expectedCompletion: `return data;`, - }, - - { - description: "Should autocomplete Solidity event with parameters", - filename: "EventExample.sol", - input: ` -pragma solidity ^0.8.0; - -contract EventExample { - event DataStored(uint indexed id, string content); - - function storeData(uint id, string memory content) public { - emit DataStored(<|fim|>); - } -} - `, - llmOutput: `id, content`, - expectedCompletion: `id, content`, - }, - - { - description: "Should handle Solidity struct definition completion", - filename: "StructDefinition.sol", - input: ` -pragma solidity ^0.8.0; - -contract StructExample { - struct Person { - string name; - uint age; - address wallet; - } - - Person[] private people; - - function addPerson(string memory name, uint age, address wallet) public { - people.push(Person(name, age, wallet)); - } - - function getFirstPerson<|fim|> -} - `, - llmOutput: `() public view returns (string memory, uint, address) { - if (people.length > 0) { - Person storage person = people[0]; - return (person.name, person.age, person.wallet); - } - return ("", 0, address(0)); - }`, - expectedCompletion: `() public view returns (string memory, uint, address) { - if (people.length > 0) { - Person storage person = people[0]; - return (person.name, person.age, person.wallet); - } - return ("", 0, address(0)); - }`, - }, - { - description: "Should autocomplete TypeScript interface properties", - filename: "User.ts", - input: ` -interface User { - id: number; - name: string; - e<|fim|> -} -`, - llmOutput: `mail: string; - age: number; -}`, - expectedCompletion: `mail: string; - age: number; -}`, - }, - - { - description: - "Should autocomplete a TypeScript arrow function inside a variable assignment", - filename: "mathOperations.ts", - input: ` -const addNumbers = (a: number, b: number): number => { - return a + b; -}; - -const multiplyNumbers = (a: number, b: number): number => { - re<|fim|> -} - -console.log(multiplyNumbers(2, 3)); -`, - llmOutput: `turn a * b;`, - expectedCompletion: `turn a * b;`, - }, - - { - description: - "Should handle autocomplete inside a nested TypeScript class method", - filename: "Account.ts", - input: ` -class Account { - private balance: number = 0; - - deposit(amount: number) { - this.balance += amount; - return this.balance; - } - - withdraw(amount: number) { - if (amount > this.balance) { - throw new Error("Insufficient funds"); - } - this.balance -= amount; - return thi<|fim|> - } -} -`, - llmOutput: `s.balance;`, - expectedCompletion: `s.balance;`, - }, - - { - description: "Should autocomplete a TypeScript generic function", - filename: "GenericFunction.ts", - input: ` -function identity(arg: T): T { - return ar<|fim|> -} - -console.log(identity(5)); -`, - llmOutput: `g;`, - expectedCompletion: `g;`, - }, - - { - description: - "Should autocomplete a TypeScript promise within an asynchronous function", - filename: "asyncFunction.ts", - input: ` -async function fetchData(url: string): Promise { - const response = await fetch(url); - <|fim|> - return data; -} - -fetchData('https://api.example.com/data'); -`, - llmOutput: `const data = await response.json();`, - expectedCompletion: `const data = await response.json();`, - }, - - { - description: - "Should autocomplete a C# class with a constructor and property", - filename: "Person.cs", - input: `using System; - -public class Person -{ - public string Name { get; set; } - public int Age { get; set; } - - public Person(string name, int <|fim|> -}`, - llmOutput: `age) - { - Name = name; - Age = age; - }`, - expectedCompletion: `age) - { - Name = name; - Age = age; - }`, - }, - { - description: "Should autocomplete a C# interface method", - filename: "IGreetable.cs", - input: `public interface IGreetable -{ - void <|fim|> -}`, - llmOutput: `Greet();`, - expectedCompletion: `Greet();`, - }, - { - description: "Should autocomplete inside C# method with if condition", - filename: "Calculator.cs", - input: `using System; - -public class Calculator -{ - public int Add(int a, int b) - { - if(<|fim|>) - { - return a + b; - } - return 0; - } -}`, - llmOutput: `a > 0 && b > 0`, - expectedCompletion: `a > 0 && b > 0`, - }, - { - description: "Should complete a simple Julia function", - filename: "simpleFunction.jl", - input: `function calculate_area(length, width) - <|fim|> -end -`, - llmOutput: `return length * width`, - expectedCompletion: `return length * width`, - }, - { - description: "Should autocomplete Julia for loop", - filename: "loop.jl", - input: `numbers = [1, 2, 3, 4, 5] -squared_numbers = [] - -for num in numbers - <|fim|> -end - -println(squared_numbers) -`, - llmOutput: `push!(squared_numbers, num^2)`, - expectedCompletion: `push!(squared_numbers, num^2)`, - }, - { - description: "Should complete a Julia struct definition", - filename: "structDefinition.jl", - input: `struct Person - first_name::String - last_name::String - age::Int - address::Address -end - -struct Address - street::String - city::String - <|fim|> -end -`, - llmOutput: `state::String - zip_code::String`, - expectedCompletion: `state::String - zip_code::String`, - }, - { - description: "Should complete a Julia dictionary access", - filename: "dictionary.jl", - input: `grades = Dict("Alice" => 90, "Bob" => 85, "Eve" => 88) - -function get_grade(student_name) - return grades[<|fim|>] -end - -println(get_grade("Alice")) # Should print 90 -`, - llmOutput: `student_name`, - expectedCompletion: `student_name`, - }, - { - description: "Should complete a Julia module declaration", - filename: "moduleDeclaration.jl", - input: `module MathOperations - -export add, subtract - -function add(a, b) - return a + b -end - -function subtract(a, b) - return a - b -end - -<|fim|> -`, - llmOutput: `end`, - expectedCompletion: `end`, - }, - { - description: "Should complete F# let-binding with function definition", - filename: "mathModule.fs", - input: `module MathModule - -let calculateArea length width = - <|fim|>`, - llmOutput: `length * width`, - expectedCompletion: `length * width`, - }, - - { - description: "Should complete incomplete F# type definition", - filename: "personType.fs", - input: `type Person = { - FirstName: string - LastName: string - Age: int<|fim|> -} - -let john = { FirstName = "John"; LastName = "Doe"; Age = 30 }`, - llmOutput: ` - Address: string -}`, - expectedCompletion: ` - Address: string -}`, - }, - - { - description: "Should complete F# pattern matching expression", - filename: "patternMatching.fs", - input: `let describeNumber number = - match number with - | 0 -> "Zero" - | 1 -> "One" - | <|fim|>`, - llmOutput: `2 -> "Two" - | _ -> "Other"`, - expectedCompletion: `2 -> "Two" - | _ -> "Other"`, - }, - - { - description: "Should complete F# list comprehension expression", - filename: "listComprehension.fs", - input: `let squares = [ for x in 1..10 -> x * x ] -let evenSquares = [ for x in squares do if x % 2 = 0 then yield x ] -let oddSquares = [<|fim|>]`, - llmOutput: ` for x in squares do if x % 2 <> 0 then yield x ]`, - expectedCompletion: ` for x in squares do if x % 2 <> 0 then yield x ]`, - }, - - { - description: "Should complete an F# recursive function", - filename: "recursiveFunctions.fs", - input: `let rec factorial n = - if n <= 1 then 1 - else n <|fim|> factorial (n - 1)`, - llmOutput: ` * `, - expectedCompletion: ` * `, - }, - - { - description: "Should complete F# member method inside a class type", - filename: "bankAccount.fs", - input: `type BankAccount(owner: string, initialBalance: float) = - let mutable balance = initialBalance - - member this.Deposit amount = - balance <- balance + amount - this - <|fim|>`, - llmOutput: ` - member this.Withdraw amount = - if amount > balance then - failwith "Insufficient funds" - balance <- balance - amount - this`, - expectedCompletion: ` - member this.Withdraw amount = - if amount > balance then - failwith "Insufficient funds" - balance <- balance - amount - this`, - }, - - { - description: "Should complete F# async workflow function", - filename: "asyncWorkflow.fs", - input: `let fetchDataAsync url = - async { - use client = new System.Net.Http.HttpClient() - <|fim|> - }`, - llmOutput: `let! response = client.GetStringAsync(url) - return response`, - expectedCompletion: `let! response = client.GetStringAsync(url) - return response`, - }, - { - description: "Should autocomplete SCSS nested class starting inside a rule", - filename: "styles.scss", - input: `nav { - display: flex; - justify-content: space-between; - .logo { - font-size: 1.5rem; - color: #333; - - .brand<|fim|> - } - - ul { - list-style: none; - display: flex; - gap: 1rem; - } -}`, - llmOutput: `-name { - font-weight: bold; - text-transform: uppercase; -}`, - expectedCompletion: `-name { - font-weight: bold; - text-transform: uppercase; -}`, - }, - - { - description: "Should handle SCSS mixin within a class", - filename: "styles.scss", - input: `.card { - border: 1px solid #ccc; - padding: 10px; - - @include<|fim|> - - &:hover { - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); - } -}`, - llmOutput: ` transition(all 0.3s ease);`, - expectedCompletion: ` transition(all 0.3s ease);`, - }, - - { - description: - "Should autocomplete SCSS variable in the middle of a statement", - filename: "styles.scss", - input: `$primary-color: #007bff; -$secondary-color: #6c757d; - -.button { - background-color: <|fim|> color; - padding: 10px 15px; - border: none; - color: #fff; - border-radius: 4px; -}`, - llmOutput: `$primary-`, - expectedCompletion: `$primary-`, - }, - { - description: "Should autocomplete Vue component method", - filename: "MyComponent.vue", - input: ` - - -`, - llmOutput: `() { - this.count = 0; - }`, - expectedCompletion: `() { - this.count = 0; - }`, - }, - { - description: "Should autocomplete Vue computed property", - filename: "UserComponent.vue", - input: ` - - -`, - llmOutput: `() { - return this.firstName + ' ' + this.lastName; - }`, - expectedCompletion: `() { - return this.firstName + ' ' + this.lastName; - }`, - }, - { - description: "Should autocomplete Vue method using props", - filename: "TodoItem.vue", - input: ` - - -`, - llmOutput: `this.completed`, - expectedCompletion: `this.completed`, - }, - { - description: "Should autocomplete Svelte reactive statement", - filename: "Counter.svelte", - input: ` - - - -`, - llmOutput: `doubledCount = count * 2`, - expectedCompletion: `doubledCount = count * 2`, - }, - - { - description: "Should autocomplete Svelte component inside HTML", - filename: "NestedComponent.svelte", - input: ` - - -
-

Hello Svelte

- /> -
-`, - llmOutput: `name="World"`, - expectedCompletion: `name="World"`, - }, - - { - description: "Should handle autocomplete in Svelte each block", - filename: "List.svelte", - input: ` - - -
    - {#each items as item} -
  • {item}
  • - {/each<|fim|> -
-`, - llmOutput: `}`, - expectedCompletion: `}`, - }, -]; diff --git a/core/autocomplete/test/util.ts b/core/autocomplete/test/util.ts deleted file mode 100644 index bfcf31885..000000000 --- a/core/autocomplete/test/util.ts +++ /dev/null @@ -1,75 +0,0 @@ -import fs from "node:fs"; -import path from "node:path"; -import Mock from "../../llm/llms/Mock"; -import { testConfigHandler, testIde } from "../../test/util/fixtures"; -import { CompletionProvider } from "../CompletionProvider"; -import { AutocompleteInput } from "../util/types"; - -const FIM_DELIMITER = "<|fim|>"; - -function parseFimExample(text: string): { prefix: string; suffix: string } { - const [prefix, suffix] = text.split(FIM_DELIMITER); - return { prefix, suffix }; -} - -export interface AutocompleteFileringTestInput { - description: string; - filename: string; - input: string; - llmOutput: string; - expectedCompletion: string | null; - options?: { - only?: boolean; - }; -} - -export async function testAutocompleteFiltering( - test: AutocompleteFileringTestInput, -) { - const { prefix, suffix } = parseFimExample(test.input); - - // Setup necessary objects - const llm = new Mock({ - model: "mock", - }); - llm.completion = test.llmOutput; - const ide = testIde; - const configHandler = testConfigHandler; - - // Create a real file - const [workspaceDir] = await ide.getWorkspaceDirs(); - const filepath = path.join(workspaceDir, test.filename); - fs.writeFileSync(filepath, test.input.replace(FIM_DELIMITER, "")); - - // Prepare completion input and provider - const completionProvider = new CompletionProvider( - configHandler, - ide, - async () => llm, - () => {}, - async () => [], - ); - - const line = prefix.split("\n").length - 1; - const character = prefix.split("\n")[line].length; - const autocompleteInput: AutocompleteInput = { - clipboardText: "", - completionId: "test-completion-id", - filepath, - pos: { - line, - character, - }, - recentlyEditedFiles: [], - recentlyEditedRanges: [], - }; - - // Generate a completion - const result = await completionProvider.provideInlineCompletionItems( - autocompleteInput, - undefined, - ); - - // Ensure that we return the text that is wanted to be displayed - expect(result?.completion).toEqual(test.expectedCompletion); -}