Skip to content
Merged
Binary file added recipes/mojo-toml/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions recipes/mojo-toml/recipe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
context:
version: 0.5.1
mojo_version: "=0.26.1"

package:
name: mojo-toml
version: ${{ version }}

source:
git: https://github.com/DataBooth/mojo-toml.git
tag: v0.5.1

build:
number: 0
script:
- mkdir -p $PREFIX/lib/mojo/toml
- cp -r src/toml/* $PREFIX/lib/mojo/toml/

requirements:
build:
- mojo-compiler ${{ mojo_version }}
host:
- mojo-compiler ${{ mojo_version }}
run:
- ${{ pin_compatible('mojo-compiler') }}

tests:
- script:
- test -f $PREFIX/lib/mojo/toml/__init__.mojo
- test -f $PREFIX/lib/mojo/toml/lexer.mojo
- test -f $PREFIX/lib/mojo/toml/parser.mojo
- test -f $PREFIX/lib/mojo/toml/writer.mojo

about:
homepage: https://github.com/DataBooth/mojo-toml
license: Apache-2.0
license_file: LICENSE
summary: Native TOML 1.0 parser and writer for Mojo - Complete + Partial 1.1 🔥
description: |
mojo-toml is a native TOML 1.0 parser and writer for Mojo, enabling
fast and efficient parsing and writing of TOML configuration files with zero
Python dependencies.

Features:
- Complete TOML 1.0 specification support
- Array of tables [[section]] syntax
- Alternative number bases (hex 0xDEAD, octal 0o755, binary 0b1101)
- Partial TOML 1.1: \xHH and \e escape sequences
- TOML writer with full round-trip fidelity
- Nested table structures with proper Dict navigation
- Dotted keys for creating nested structures
- Duplicate key detection
- Clear error messages with line/column context
- 168 comprehensive tests (127 parser + 41 writer)
- Performance: 24μs for simple parses, 2ms for real-world files
- Comprehensive benchmark system

Perfect for configuration files, build systems, and any Mojo application
needing structured configuration.
documentation: https://github.com/DataBooth/mojo-toml/blob/main/README.md
repository: https://github.com/DataBooth/mojo-toml

extra:
recipe-maintainers:
- mjboothaus
54 changes: 54 additions & 0 deletions recipes/mojo-toml/test_package.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Test file for mojo-toml package installation.

This test verifies that mojo-toml is properly installed and can parse TOML.
"""

from toml import parse


fn main() raises:
"""Test basic TOML parsing functionality."""

print("Testing mojo-toml package installation...")

# Test 1: Simple key-value parsing
var config1 = parse('name = "mojo-toml"')
var name = config1["name"].as_string()
if name != "mojo-toml":
raise Error("Test failed: Expected 'mojo-toml', got: " + name)
print("✓ Test 1 passed: Simple key-value")

# Test 2: Integer parsing
var config2 = parse('port = 8080')
var port = config2["port"].as_int()
if port != 8080:
raise Error("Test failed: Expected 8080, got: " + String(port))
print("✓ Test 2 passed: Integer parsing")

# Test 3: Array parsing
var config3 = parse('items = [1, 2, 3]')
var items = config3["items"].as_array()
if len(items) != 3:
raise Error("Test failed: Expected 3 items, got: " + String(len(items)))
print("✓ Test 3 passed: Array parsing")

# Test 4: Nested table parsing
var config4 = parse('[database]\nhost = "localhost"\nport = 5432')
var db = config4["database"].as_table()
var host = db["host"].as_string()
if host != "localhost":
raise Error("Test failed: Expected 'localhost', got: " + host)
print("✓ Test 4 passed: Nested tables")

# Test 5: Dotted keys
var config5 = parse('a.b.c = "nested"')
var a_table = config5["a"].as_table()
var b_table = a_table["b"].as_table()
var c_value = b_table["c"].as_string()
if c_value != "nested":
raise Error("Test failed: Expected 'nested', got: " + c_value)
print("✓ Test 5 passed: Dotted keys")

print()
print("✅ All tests passed! mojo-toml is working correctly.")
print("Package version: 0.3.0")