Skip to content

Commit

Permalink
Merge pull request #458 from moonbitlang/hongbo/no_list_conversions
Browse files Browse the repository at this point in the history
clean up ref
  • Loading branch information
bobzhang authored May 28, 2024
2 parents 675a596 + ca4c168 commit c4478b0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
5 changes: 4 additions & 1 deletion ref/moon.pkg.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"import": [
"moonbitlang/core/builtin",
"moonbitlang/core/assertion",

"moonbitlang/core/int",
"moonbitlang/core/coverage"
],
"test-import" : [
"moonbitlang/core/assertion"
]
}
13 changes: 0 additions & 13 deletions ref/ref.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ pub fn map[T, R](self : Ref[T], f : (T) -> R) -> Ref[R] {
{ val: f(self.val) }
}

test "map" {
let x = ref(1)
let y = map(x, fn(a) { a + 1 })
@assertion.assert_eq(y.val, 2)?
}

/// This function allows you to temporarily replace the value of a reference with a new value,
/// execute a given function, and then restore the original value of the reference.
///
Expand Down Expand Up @@ -75,13 +69,6 @@ pub fn protect[T, R](self : Ref[T], a : T, f : () -> R) -> R {
r
}

test "protect" {
let x = ref(1)
@assertion.assert_eq(x.val, 1)?
protect(x, 2, fn() { @assertion.assert_eq(x.val, 2) })?
@assertion.assert_eq(x.val, 1)?
}

/// Swaps the values of two references.
///
/// # Example
Expand Down
26 changes: 26 additions & 0 deletions ref/ref_test.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2024 International Digital Economy Academy
//
// 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.

test "map" {
let x = ref(1)
let y = map(x, fn(a) { a + 1 })
@assertion.assert_eq(y.val, 2)?
}

test "protect" {
let x = ref(1)
@assertion.assert_eq(x.val, 1)?
protect(x, 2, fn() { @assertion.assert_eq(x.val, 2) })?
@assertion.assert_eq(x.val, 1)?
}

0 comments on commit c4478b0

Please sign in to comment.