Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ jobs:
- name: Build package
run: |
magic run mojo package src/decimojo
magic run mojo package src/tomlmojo
cp decimojo.mojopkg tests/
cp decimojo.mojopkg benches/
mv tomlmojo.mojopkg tests/

- name: Run tests
run: |
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The core types are:

The library is expanding to include `BigDecimal` types that support arbitrary precision[^arbitrary], allowing for calculations with unlimited digits and decimal places. These extensions are currently under active development.

This repository includes [TOMLMojo](https://github.com/forfudan/decimojo/tree/main/src/tomlmojo), a lightweight TOML parser in pure Mojo. It parses configuration files and test data, supporting basic types, arrays, and nested tables. While created for DeciMojo's testing framework, it offers general-purpose structured data parsing with a clean, simple API.

## Installation

DeciMojo is available in the [modular-community](https://repo.prefix.dev/modular-community) package repository. You can install it using any of these methods:
Expand Down
7 changes: 5 additions & 2 deletions mojoproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ max = ">=25.2"
format = "magic run mojo format ./"

# compile the package
package = "magic run format && magic run mojo package src/decimojo && cp decimojo.mojopkg tests/ && cp decimojo.mojopkg benches/ && rm decimojo.mojopkg"
package_decimojo = "magic run mojo package src/decimojo && cp decimojo.mojopkg tests/ && cp decimojo.mojopkg benches/ && rm decimojo.mojopkg"
package_tomlmojo = "magic run mojo package src/tomlmojo && mv tomlmojo.mojopkg tests/"
package = "magic run format && magic run package_decimojo && magic run package_tomlmojo"
p = "clear && magic run package"

# clean the package files in tests folder
clean = "rm tests/decimojo.mojopkg && rm benches/decimojo.mojopkg"
clean = "rm tests/decimojo.mojopkg && rm benches/decimojo.mojopkg && rm tests/tomlmojo.mojopkg"
c = "clear && magic run clean"

# tests (use the mojo testing tool)
test = "magic run package && magic run mojo test tests --filter"
Expand Down
3 changes: 0 additions & 3 deletions src/decimojo/__init__.mojo
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# ===----------------------------------------------------------------------=== #
# DeciMojo: A fixed-point decimal arithmetic library in Mojo
# https://github.com/forfudan/decimojo
#
# Copyright 2025 Yuhao Zhu
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
55 changes: 55 additions & 0 deletions src/decimojo/tests.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# ===----------------------------------------------------------------------=== #
# Copyright 2025 Yuhao Zhu
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #

"""
Implement structs and functions for tests.
"""


struct TestCase:
"""Structure to hold test case data.

Attributes:
a: The first input value as numeric string.
b: The second input value as numeric string.
expected: The expected output value as numeric string.
description: A description of the test case.
"""

var a: String
var b: String
var expected: String
var description: String

fn __init__(
out self, a: String, b: String, expected: String, description: String
):
self.a = a
self.b = b
self.expected = expected
self.description = description + "\nx1 = " + self.a + "\nx2 = " + self.b

fn __copyinit__(out self, other: Self):
self.a = other.a
self.b = other.b
self.expected = other.expected
self.description = other.description

fn __moveinit__(out self, owned other: Self):
self.a = other.a^
self.b = other.b^
self.expected = other.expected^
self.description = other.description^
21 changes: 21 additions & 0 deletions src/tomlmojo/__init__.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ===----------------------------------------------------------------------=== #
# Copyright 2025 Yuhao Zhu
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===----------------------------------------------------------------------=== #

"""
A simple TOML parser for Mojo.
"""

from .parser import parse_file, TOMLValueType
Loading