Skip to content

Commit ee6bc00

Browse files
authored
Merge branch 'main' into pragma
2 parents 1e48da3 + dc28ec9 commit ee6bc00

File tree

7 files changed

+118
-57
lines changed

7 files changed

+118
-57
lines changed

.github/workflows/check.yml

Lines changed: 36 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -116,53 +116,42 @@ jobs:
116116
moon fmt
117117
git diff
118118
119-
# coverage-check-bleeding:
120-
# runs-on: macos-14
121-
# continue-on-error: true
122-
# permissions: write-all
123-
# # contents: read
124-
# # issues: write
125-
# # pull-requests: write
126-
# steps:
127-
# - uses: actions/checkout@v4
128-
129-
# - name: install
130-
# run: |
131-
# /bin/bash -c "$(curl -fsSL https://cli.moonbitlang.com/bleeding/mac_m1_moon_setup.sh)"
132-
# echo "$HOME/.moon/bin" >> $GITHUB_PATH
133-
134-
# - name: moon test
135-
# run: moon test --enable-coverage
136-
137-
# - name: moon_cove_report
138-
# run: moon_cove_report
139-
140-
# - name: bisect_ppx report
141-
# run: |
142-
# bisect-ppx-report html
143-
# bisect-ppx-report summary > coverage_summary.txt
144-
# echo "coverage_summary=$(cat coverage_summary.txt)" >> $GITHUB_ENV
145-
146-
# - name: upload coverage artifact
147-
# uses: actions/upload-artifact@v4
148-
# with:
149-
# name: code-coverage-report
150-
# path: _coverage
151-
152-
# - name: Add coverage comment to PR
153-
# if: github.event_name == 'pull_request'
154-
# uses: actions/github-script@v7
155-
# with:
156-
# script: |
157-
# const coverageReportLink = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
158-
# const prNumber = context.payload.pull_request.number;
159-
# const summary = process.env.coverage_summary;
160-
# await github.rest.issues.createComment({
161-
# owner: context.repo.owner,
162-
# repo: context.repo.repo,
163-
# issue_number: prNumber,
164-
# body: `${summary}\nCoverage report: ${coverageReportLink}`
165-
# });
119+
coverage-check-bleeding:
120+
runs-on: macos-14
121+
continue-on-error: true
122+
permissions:
123+
contents: read
124+
issues: write
125+
pull-requests: write
126+
steps:
127+
- uses: actions/checkout@v4
128+
129+
- name: install
130+
run: |
131+
/bin/bash -c "$(curl -fsSL https://cli.moonbitlang.com/bleeding/mac_m1_moon_setup.sh)"
132+
echo "$HOME/.moon/bin" >> $GITHUB_PATH
133+
134+
- name: moon test
135+
run: moon test --enable-coverage
136+
137+
- name: moon_cove_report
138+
run: moon_cove_report
139+
140+
- name: bisect_ppx report
141+
run: |
142+
bisect-ppx-report html
143+
bisect-ppx-report summary > coverage_summary.txt
144+
echo "coverage_summary=$(cat coverage_summary.txt)" >> $GITHUB_ENV
145+
# Put the coverage report in the pipline output
146+
cat coverage_summary.txt >> "$GITHUB_STEP_SUMMARY"
147+
bisect-ppx-report coveralls coverage.json --service-name github --service-job-id $GITHUB_RUN_NUMBER
148+
149+
- name: upload to codecov
150+
uses: codecov/codecov-action@v2
151+
with:
152+
file: coverage.json
153+
flags: bisect-ppx
154+
verbose: true
166155

167156
typo-check:
168157
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# moonbitlang/core
22

3-
[![check](https://github.com/moonbitlang/core/actions/workflows/check.yml/badge.svg)](https://github.com/moonbitlang/core/actions/workflows/check.yml)
3+
[![check](https://github.com/moonbitlang/core/actions/workflows/check.yml/badge.svg)](https://github.com/moonbitlang/core/actions/workflows/check.yml) [![codecov](https://codecov.io/gh/moonbitlang/core/graph/badge.svg?token=HRJPS16ZP9)](https://codecov.io/gh/moonbitlang/core)
44

55
moonbitlang/core is the standard library of the [MoonBit language](https://www.moonbitlang.com/). It is released alongside the compiler. You can view the documentation for the latest official release at <https://mooncakes.io/docs/#/moonbitlang/core/>. This repository serves as the development repository.
66

array/array.mbt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,8 @@ test "to_list" {
584584
let ls = [1, 2, 3, 4, 5].to_list()
585585
@assertion.assert_eq(ls, Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))))?
586586
}
587+
588+
test "op_equal" {
589+
inspect([1, 2] == [1], ~content="false")?
590+
inspect(starts_with([1, 2, 3], [1, 3]), ~content="false")?
591+
}

assertion/assertion.mbt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ test "assert_ne.eq" {
7171
}
7272
}
7373

74-
pub fn assert_false(x : Bool, ~loc : SourceLoc = _) -> Result[Unit, String] {
75-
if x == false {
76-
Ok(())
74+
pub fn assert_false[T : Debug + @bool.Boolean](
75+
x : T,
76+
~loc : SourceLoc = _
77+
) -> Result[Unit, String] {
78+
if x.to_bool() {
79+
let x = debug_string(x)
80+
Err("FAILED:\(loc) `\(x)` is not false")
7781
} else {
78-
Err("FAILED:\(loc)")
82+
Ok(())
7983
}
8084
}
8185

@@ -87,11 +91,15 @@ test "assert_false.true" {
8791
assert_ne(assert_false(true), Ok(()))?
8892
}
8993

90-
pub fn assert_true(x : Bool, ~loc : SourceLoc = _) -> Result[Unit, String] {
91-
if x {
94+
pub fn assert_true[T : Debug + @bool.Boolean](
95+
x : T,
96+
~loc : SourceLoc = _
97+
) -> Result[Unit, String] {
98+
if x.to_bool() {
9299
Ok(())
93100
} else {
94-
Err("FAILED:\(loc)")
101+
let x = debug_string(x)
102+
Err("FAILED:\(loc): `\(x)` is not true")
95103
}
96104
}
97105

assertion/moon.pkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"import": [
33
"moonbitlang/core/builtin",
4+
"moonbitlang/core/bool",
45
"moonbitlang/core/coverage"
56
]
67
}

bool/bool.mbt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
15+
pub trait Boolean {
16+
to_bool(Self) -> Bool
17+
}
18+
19+
pub fn Bool::to_bool(self : Bool) -> Bool {
20+
self
21+
}

deque/deque.mbt

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ pub fn Deque::with_capacity[T](cap : Int) -> Deque[T] {
3232
Deque::{ buf: UninitializedArray::make(cap), len: 0, head: 0, tail: 0 }
3333
}
3434

35+
test "with_capacity" {
36+
let d : Deque[Int] = Deque::with_capacity(0)
37+
@assertion.assert_eq(d.buf.length(), 0)?
38+
}
39+
40+
test "with_capacity_non_zero" {
41+
let d : Deque[Int] = Deque::with_capacity(10)
42+
@assertion.assert_eq(d.buf.length(), 10)?
43+
}
44+
3545
/// Creates a new deque from an array.
3646
pub fn Deque::from_array[T](arr : Array[T]) -> Deque[T] {
3747
let deq = Deque::{
@@ -138,6 +148,9 @@ test "front_and_back" {
138148
let dq = Deque::[1, 2, 3, 4, 5]
139149
@assertion.assert_eq(dq.back(), Some(5))?
140150
@assertion.assert_eq(dq.front(), Some(1))?
151+
let dq: Deque[Int] = Deque::[]
152+
@assertion.assert_eq(dq.back(), None)?
153+
@assertion.assert_eq(dq.front(), None)?
141154
}
142155
143156
/// Adds an element to the front of the deque.
@@ -260,6 +273,22 @@ test "push_and_pop" {
260273
@assertion.assert_eq(dq.length(), 6)?
261274
@assertion.assert_eq(dq.pop_back(), Some(8))?
262275
@assertion.assert_eq(dq.back(), Some(7))?
276+
277+
let dq = Deque::[1]
278+
@assertion.assert_eq(dq.pop_front(), Some(1))?
279+
@assertion.assert_eq(dq.pop_front(), None)?
280+
@assertion.assert_eq(dq.pop_back(), None)?
281+
}
282+
283+
test "push_realloc" {
284+
let dq: Deque[Int] = Deque::with_capacity(0)
285+
dq.push_front(1)
286+
@assertion.assert_eq(dq.pop_front(), Some(1))?
287+
@assertion.assert_true(dq.capacity() > 0)?
288+
let dq: Deque[Int] = Deque::with_capacity(0)
289+
dq.push_back(1)
290+
@assertion.assert_eq(dq.pop_back(), Some(1))?
291+
@assertion.assert_true(dq.capacity() > 0)?
263292
}
264293
265294
/// Retrieves the element at the specified index from the deque.
@@ -282,7 +311,7 @@ pub fn op_get[T](self : Deque[T], index : Int) -> T {
282311
if self.head + index < self.buf.length() {
283312
self.buf[self.head + index]
284313
} else {
285-
self.buf[index- self.head+1]
314+
self.buf[(self.head + index) % self.buf.length()]
286315
}
287316
}
288317
@@ -293,8 +322,9 @@ test "op_get" {
293322
@assertion.assert_eq(dq[2], 3)?
294323
@assertion.assert_eq(dq[3], 4)?
295324
@assertion.assert_eq(dq[4], 5)?
325+
let _ = dq.pop_front()
296326
dq.push_back(1)
297-
@assertion.assert_eq(dq[5], 1)?
327+
@assertion.assert_eq(dq[4], 1)?
298328
dq.push_front(2)
299329
@assertion.assert_eq(dq[0], 2)?
300330
}
@@ -324,6 +354,12 @@ pub fn op_set[T](self : Deque[T], index : Int, value : T) -> Unit {
324354
}
325355
}
326356
357+
test "op_set" {
358+
let dq = Deque::[1,2,3,4,5]
359+
dq[1] = 3
360+
@assertion.assert_eq(dq[1], 3)?
361+
}
362+
327363
/// Compares two deques for equality.
328364
pub fn op_equal[T : Eq](self : Deque[T], other : Deque[T]) -> Bool {
329365
if self.len != other.len {
@@ -337,6 +373,20 @@ pub fn op_equal[T : Eq](self : Deque[T], other : Deque[T]) -> Bool {
337373
true
338374
}
339375
376+
test "op_equal" {
377+
let dq1 = Deque::[1, 2, 3]
378+
let dq2 = Deque::[1, 2, 3]
379+
@assertion.assert_true(dq1 == dq2)?
380+
let dq1 = Deque::[1, 2, 3]
381+
let dq2 = Deque::[1, 2, 3]
382+
dq2[0] = 2
383+
@assertion.assert_false(dq1 == dq2)?
384+
let dq1 = Deque::[1, 2, 3]
385+
let dq2 = Deque::[1, 2, 3]
386+
dq2.push_front(1)
387+
@assertion.assert_false(dq1 == dq2)?
388+
}
389+
340390
/// Iterates over the elements of the deque.
341391
///
342392
/// # Example

0 commit comments

Comments
 (0)