morganlinton/BeautifulRust / skills/rust-port
rust-port
VerifiedPort code from C, C++, Python, Go, JavaScript, or TypeScript into idiomatic Rust that keeps the original behavior: ownership instead of manual memory, Result instead of error codes and exceptions, enums instead of flag ints and magic strings, and tests that prove the port matches. Use this whenever the user asks to port, translate, convert, migrate, or rewrite code in Rust ("rewrite this in Rust", "what would this look like in Rust", "move this module to Rust"), even if they don't say "port". Pairs with the rust-best-practices skill, which covers the target code's style.
evals/port-c-config-parser/files/test_config.c
View on GitHub#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
static void test_basic(void) {
int code, line;
config_t *c = config_parse("name = app\n# comment\n; also comment\n\n[db]\nport=5432\nhost = localhost \n",
CONFIG_TRIM_VALUES, &code, &line);
assert(c && code == CONFIG_OK);
assert(config_count(c) == 3);
assert(strcmp(config_get(c, "name"), "app") == 0);
assert(strcmp(config_get(c, "db.host"), "localhost") == 0);
long port;
assert(config_get_int(c, "db.port", &port) == CONFIG_INT_OK && port == 5432);
assert(config_get(c, "missing") == NULL);
config_free(c);
}
static void test_untrimmed_values_keep_whitespace(void) {
config_t *c = config_parse("k = v \n", 0, NULL, NULL);
assert(c && strcmp(config_get(c, "k"), " v") == 0); /* line trim removes the trailing space */
config_free(c);
}
static void test_get_int_errors(void) {
config_t *c = config_parse("a=12x\nb=\nc=-7\nd=99999999999999999999\n", 0, NULL, NULL);
long n = 0;
assert(config_get_int(c, "a", &n) == CONFIG_INT_NOT_NUMBER);
assert(config_get_int(c, "b", &n) == CONFIG_INT_NOT_NUMBER);
assert(config_get_int(c, "c", &n) == CONFIG_INT_OK && n == -7);
assert(config_get_int(c, "d", &n) == CONFIG_INT_NOT_NUMBER);
assert(config_get_int(c, "zzz", &n) == CONFIG_INT_MISSING);
config_free(c);
}
static void test_duplicates(void) {
int code, line;
assert(config_parse("a=1\nb=2\na=3\n", 0, &code, &line) == NULL);
assert(code == CONFIG_ERR_DUPLICATE && line == 3);
config_t *c = config_parse("a=1\na=3\n", CONFIG_ALLOW_DUPLICATES, &code, &line);
assert(c && config_count(c) == 1 && strcmp(config_get(c, "a"), "3") == 0);
config_free(c);
}
static void test_case_insensitive(void) {
config_t *c = config_parse("[Server]\nPort=80\n", CONFIG_CASE_INSENSITIVE, NULL, NULL);
assert(strcmp(config_get(c, "server.port"), "80") == 0);
config_free(c);
int code;
assert(config_parse("A=1\na=2\n", CONFIG_CASE_INSENSITIVE, &code, NULL) == NULL && code == CONFIG_ERR_DUPLICATE);
}
static void test_syntax_errors(void) {
int code, line;
assert(config_parse("ok=1\nnot a pair\n", 0, &code, &line) == NULL && code == CONFIG_ERR_SYNTAX && line == 2);
assert(config_parse("[unclosed\n", 0, &code, &line) == NULL && code == CONFIG_ERR_SYNTAX && line == 1);
assert(config_parse("[]\n", 0, &code, &line) == NULL && code == CONFIG_ERR_SYNTAX);
assert(config_parse("=novalue\n", 0, &code, &line) == NULL && code == CONFIG_ERR_SYNTAX);
}
static void test_empty_input(void) {
config_t *c = config_parse("", 0, NULL, NULL);
assert(c && config_count(c) == 0);
config_free(c);
}
int main(void) {
test_basic();
test_untrimmed_values_keep_whitespace();
test_get_int_errors();
test_duplicates();
test_case_insensitive();
test_syntax_errors();
test_empty_input();
puts("all config tests passed");
return 0;
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |