|
| 1 | +"""Test file for mojo-toml package installation. |
| 2 | +
|
| 3 | +This test verifies that mojo-toml is properly installed and can parse TOML. |
| 4 | +""" |
| 5 | + |
| 6 | +from toml import parse |
| 7 | + |
| 8 | + |
| 9 | +fn main() raises: |
| 10 | + """Test basic TOML parsing functionality.""" |
| 11 | + |
| 12 | + print("Testing mojo-toml package installation...") |
| 13 | + |
| 14 | + # Test 1: Simple key-value parsing |
| 15 | + var config1 = parse('name = "mojo-toml"') |
| 16 | + var name = config1["name"].as_string() |
| 17 | + if name != "mojo-toml": |
| 18 | + raise Error("Test failed: Expected 'mojo-toml', got: " + name) |
| 19 | + print("✓ Test 1 passed: Simple key-value") |
| 20 | + |
| 21 | + # Test 2: Integer parsing |
| 22 | + var config2 = parse('port = 8080') |
| 23 | + var port = config2["port"].as_int() |
| 24 | + if port != 8080: |
| 25 | + raise Error("Test failed: Expected 8080, got: " + String(port)) |
| 26 | + print("✓ Test 2 passed: Integer parsing") |
| 27 | + |
| 28 | + # Test 3: Array parsing |
| 29 | + var config3 = parse('items = [1, 2, 3]') |
| 30 | + var items = config3["items"].as_array() |
| 31 | + if len(items) != 3: |
| 32 | + raise Error("Test failed: Expected 3 items, got: " + String(len(items))) |
| 33 | + print("✓ Test 3 passed: Array parsing") |
| 34 | + |
| 35 | + # Test 4: Nested table parsing |
| 36 | + var config4 = parse('[database]\nhost = "localhost"\nport = 5432') |
| 37 | + var db = config4["database"].as_table() |
| 38 | + var host = db["host"].as_string() |
| 39 | + if host != "localhost": |
| 40 | + raise Error("Test failed: Expected 'localhost', got: " + host) |
| 41 | + print("✓ Test 4 passed: Nested tables") |
| 42 | + |
| 43 | + # Test 5: Dotted keys |
| 44 | + var config5 = parse('a.b.c = "nested"') |
| 45 | + var a_table = config5["a"].as_table() |
| 46 | + var b_table = a_table["b"].as_table() |
| 47 | + var c_value = b_table["c"].as_string() |
| 48 | + if c_value != "nested": |
| 49 | + raise Error("Test failed: Expected 'nested', got: " + c_value) |
| 50 | + print("✓ Test 5 passed: Dotted keys") |
| 51 | + |
| 52 | + print() |
| 53 | + print("✅ All tests passed! mojo-toml is working correctly.") |
| 54 | + print("Package version: 0.3.0") |
0 commit comments