Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created February 6, 2026 06:22
Show Gist options
  • Select an option

  • Save podhmo/d43b336505f05bafffeaf02a1b2d8a24 to your computer and use it in GitHub Desktop.

Select an option

Save podhmo/d43b336505f05bafffeaf02a1b2d8a24 to your computer and use it in GitHub Desktop.
foo

foo

一番シンプルなmoonbitでのテストの実行用の例

$ moon test
Total tests: 1, passed: 1, failed: 0.
test:
moon test
clean:
rm -rf _build target
.PHONY: test clean
{
"name": "username/foo",
"version": "0.1.0",
"readme": "README.mbt.md",
"repository": "",
"license": "Apache-2.0",
"keywords": [],
"description": ""
}
fn sum(data~ : Array[Int], start? : Int = 0, length? : Int) -> Int {
let end = if length is Some(length) { start + length } else { data.length() }
for i = start, sum = 0; i < end; i = i + 1, sum = sum + data[i] {
} else {
sum
}
}
test "sum" {
let array = [1, 2, 3, 4, 5]
inspect(sum(data=array), content="15")
inspect(sum(data=array, start=1), content="14")
inspect(sum(data=array, length=3), content="6")
let length = None
// Use `?` for punning
inspect(sum(data=array, length?), content="15")
}
@podhmo
Copy link
Author

podhmo commented Feb 6, 2026

moon newではじめても良い気がする。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment