Port a Function or Module to Another Language With Tests Proving Same Behavior
Lists the source code's behaviors and edge cases, writes tests in the target language first, ports the code idiomatically, and gives a table of library mappings and semantics that differ.
You getBehavior list, tests in one code block and ported code in one code block
The prompt
mkdir -p .agents/skills/port-a-function-or-module-to-another-language-with-tests-proving && curl -sL "https://prompts-gpt.com/prompts/port-a-function-or-module-to-another-language-with-tests-proving-same-behavior/raw" -o .agents/skills/port-a-function-or-module-to-another-language-with-tests-proving/SKILL.mdYou are a senior engineer fluent in both languages. Port this code to the target language and show that it behaves the same.
Source code: def chunk(items, size): return [items[i:i+size] for i in range(0, len(items), size)] (example value for {paste the source code})
Target language, version and allowed libraries: TypeScript 5.6, Node 22, standard library only (example value for {target language version and libraries})
Steps:
1. List the observable behaviors of the source, including edge cases: empty and null input, integer overflow and division, floating point, string encoding and Unicode, sort stability, time zones, errors, async and concurrency.
2. Write tests in the target language from those behaviors first. Mark any expected value you worked out by reasoning rather than by running the source.
3. Port idiomatically for the target language, not line by line, and map each library call to its equivalent.
4. Point out any behavior you could not match exactly and how callers would notice.
Rules: no dependencies beyond the ones I allowed; keep public names and signatures unless target conventions require a change, and say so.
Output format:
1. Behavior list
2. Tests in one code block
3. Ported code in one code block
4. Table: source construct | target equivalent | semantic difference
5. Mismatches and risks
If you cannot run code, tell me which tests to run first.Dashed parts are example values, so the prompt runs as copied. Change them in Fill in the blanks.
Paste into ChatGPT or Claude, or run in Claude Code, Cursor or Codex where it can run both versions. Works for one function or a small module; split larger code by module.
Keep exploring
More like this
Edge-Case Test Suite for One Function in Your Existing Test Framework
Writes tests for a single function that cover normal inputs, boundaries, bad input and error paths, in the test framework your project already uses.
Characterization Tests Before a Refactor
Writes tests that lock in a module's current behavior, including edge cases and quirks, so you can refactor safely.
Unit Test Plan and Test Code for an Existing Function
Builds a behavior-based test matrix for a function or module and then generates test code in your framework. Covers edge cases, failures, and mocking boundaries, with coverage gaps stated honestly.
Refactor Pasted Code for Readability Without Changing Its Behavior
Returns a cleaner version of your code plus a change log that explains each edit, why behavior is preserved, and which edge cases you should test.
Test-First Bug Fix Skill: Reproduce, Fix, Prove (SKILL.md)
A SKILL.md that forces your coding agent to reproduce a bug with a failing test before changing code, apply the smallest fix, and prove it with the test suite.
Speed Up a Slow Function with Big-O Analysis and a Benchmark
You get the exact bottleneck line, current vs. proposed Big-O, an optimized drop-in function, and a small benchmark that proves the speedup before you adopt it.
- Debug an Error From the Message and the Code Around It
- Plain-English Question to a Correct SQL Query for Your Schema
- Regex Builder With Match and No-Match Test Cases
- Failing Test First Bug Fix
- Batch Rename Files in a Folder with a Script You Can Preview First
- Build an Excel Formula from a Plain-English Description of What You Need