From d6d3ecd00e075071661e75148862d3c7fba498ae Mon Sep 17 00:00:00 2001 From: arch lw2333 <2374046775@qq.com> Date: Sat, 14 Jun 2025 16:27:14 +0000 Subject: [PATCH 1/2] fix: update some deprecated usages --- array/array.mbt | 4 +- builtin/bytes.mbt | 2 +- builtin/intrinsics.mbt | 10 +-- builtin/string.mbt | 4 +- hashmap/hashmap.mbt | 4 +- immut/list/list.mbt | 10 +-- immut/sorted_map/types.mbt | 8 +-- math/prime.mbt | 6 +- option/option.mbt | 4 +- priority_queue/priority_queue.mbt | 2 +- random/random.mbt | 4 +- sorted_set/README.mbt.md | 2 +- sorted_set/set.mbt | 110 +++++++++++++++++------------- sorted_set/set_test.mbt | 59 ++++++++-------- string/string.mbt | 2 +- string/view.mbt | 4 +- tuple/tuple.mbt | 6 +- 17 files changed, 131 insertions(+), 110 deletions(-) diff --git a/array/array.mbt b/array/array.mbt index cf5e3a4ca..0114a03d6 100644 --- a/array/array.mbt +++ b/array/array.mbt @@ -110,7 +110,7 @@ pub fn[T] Array::makei( /// test "Array::shuffle_in_place" { /// let arr = [1, 2, 3, 4, 5] /// fn rand(upper : Int) -> Int { -/// let rng = @random.new() +/// let rng = @random.Rand::new() /// rng.int(limit=upper) /// } /// Array::shuffle_in_place(arr, rand=rand) @@ -138,7 +138,7 @@ pub fn[T] shuffle_in_place(self : Array[T], rand~ : (Int) -> Int) -> Unit { /// test { /// let arr = [1, 2, 3, 4, 5] /// fn rand(upper : Int) -> Int { -/// let rng = @random.new() +/// let rng = @random.Rand::new() /// rng.int(limit=upper) /// } /// let _shuffled = Array::shuffle(arr, rand=rand) diff --git a/builtin/bytes.mbt b/builtin/bytes.mbt index 9ac140425..69d5b944f 100644 --- a/builtin/bytes.mbt +++ b/builtin/bytes.mbt @@ -64,7 +64,7 @@ pub fn Bytes::makei(length : Int, value : (Int) -> Byte) -> Bytes { /// /// ```moonbit /// test "Bytes::of_string" { -/// let bytes = Bytes::of_string("ABC") +/// let bytes = "ABC".to_bytes() /// inspect(bytes, content="b\"\\x41\\x00\\x42\\x00\\x43\\x00\"") /// } /// ``` diff --git a/builtin/intrinsics.mbt b/builtin/intrinsics.mbt index c9f1532e9..e3519b890 100644 --- a/builtin/intrinsics.mbt +++ b/builtin/intrinsics.mbt @@ -1276,7 +1276,7 @@ pub impl Compare for Char with compare(self, other) = "%char_compare" /// /// ```moonbit /// test "Char::default" { -/// assert_true(Char::default().to_string() == "\x00") +/// assert_true(Char::default().to_string() == "\u0000") /// } /// ``` pub impl Default for Char with default() = "%char_default" @@ -1726,14 +1726,14 @@ pub fn String::op_get(self : String, idx : Int) -> Char = "%string_get" /// ```moonbit /// test "String::get" { /// let s = "Hello, 世界" -/// inspect(s.get(0), content="H") -/// inspect(s.get(7), content="世") +/// inspect(s.charcode_at(0), content="72") +/// inspect(s.char_at(7), content="世") /// } /// /// test "panic String::get/out_of_bounds" { /// let s = "Hello" -/// ignore(s.get(-1)) // Negative index -/// ignore(s.get(5)) // Index equals length +/// ignore(s.charcode_at(-1)) // Negative index +/// ignore(s.charcode_at(5)) // Index equals length /// } /// ``` #deprecated("use `charcode_at` instead") diff --git a/builtin/string.mbt b/builtin/string.mbt index 045b60795..d0df9987e 100644 --- a/builtin/string.mbt +++ b/builtin/string.mbt @@ -92,8 +92,8 @@ pub fn String::charcode_at(self : String, index : Int) -> Int = "%string_get" /// ```mbt /// test "String::codepoint_at" { /// let s = "Hello🤣"; -/// inspect(s.codepoint_at(0), content="H"); -/// inspect(s.codepoint_at(5), content="🤣"); // Returns full emoji character +/// inspect(s.iter().nth(0).unwrap(), content="H"); +/// inspect(s.iter().nth(5).unwrap(), content="🤣"); // Returns full emoji character /// } /// ``` /// diff --git a/hashmap/hashmap.mbt b/hashmap/hashmap.mbt index 126b3e8dd..5afac86fd 100644 --- a/hashmap/hashmap.mbt +++ b/hashmap/hashmap.mbt @@ -250,8 +250,8 @@ fn[K : Hash + Eq, V] get_with_hash(self : T[K, V], key : K, hash : Int) -> V? { /// ```moonbit /// test "op_get" { /// let map = @hashmap.of([("key", 42)]) -/// inspect(map["key"], content="Some(42)") -/// inspect(map["nonexistent"], content="None") +/// inspect(map.get("key"), content="Some(42)") +/// inspect(map.get("nonexistent"), content="None") /// } /// ``` #deprecated("Use `get` instead. `op_get` will return `V` instead of `Option[V]` in the future.") diff --git a/immut/list/list.mbt b/immut/list/list.mbt index c29d85ef4..b9880857d 100644 --- a/immut/list/list.mbt +++ b/immut/list/list.mbt @@ -493,7 +493,7 @@ pub fn[A, B] fold_righti(self : T[A], f : (Int, A, B) -> B, init~ : B) -> B { /// /// ```mbt /// test { -/// let r = @list.zip(@list.of([1, 2, 3, 4, 5]), @list.of([6, 7, 8, 9, 10])) +/// let r = @list.of([1, 2, 3, 4, 5]).zip(@list.of([6, 7, 8, 9, 10])) /// assert_eq(r, Some(@list.from_array([(1, 6), (2, 7), (3, 8), (4, 9), (5, 10)]))) /// } /// ``` @@ -626,7 +626,7 @@ pub fn[A] repeat(n : Int, x : A) -> T[A] { /// /// ```mbt /// test { -/// let ls = @list.intersperse(@list.from_array(["1", "2", "3", "4", "5"]), "|") +/// let ls = (@list.from_array(["1", "2", "3", "4", "5"])).intersperse("|") /// assert_eq(ls, @list.from_array(["1", "|", "2", "|", "3", "|", "4", "|", "5"])) /// } /// ``` @@ -651,7 +651,7 @@ pub fn[A] is_empty(self : T[A]) -> Bool { /// /// ```mbt /// test { -/// let (a,b) = @list.unzip(@list.from_array([(1,2),(3,4),(5,6)])) +/// let (a,b) = @list.from_array([(1,2),(3,4),(5,6)]).unzip() /// assert_eq(a, @list.from_array([1, 3, 5])) /// assert_eq(b, @list.from_array([2, 4, 6])) /// } @@ -677,7 +677,7 @@ pub fn[A, B] unzip(self : T[(A, B)]) -> (T[A], T[B]) { /// /// ```mbt /// test { -/// let ls = @list.flatten(@list.from_array([@list.from_array([1,2,3]), @list.from_array([4,5,6]), @list.from_array([7,8,9])])) +/// let ls = (@list.from_array([@list.from_array([1,2,3]), @list.from_array([4,5,6]), @list.from_array([7,8,9])])).flatten() /// assert_eq(ls, @list.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9])) /// } /// ``` @@ -758,7 +758,7 @@ pub fn[A : Compare] minimum(self : T[A]) -> A? { /// /// ```mbt /// test { -/// let ls = @list.sort(@list.from_array([1,123,52,3,6,0,-6,-76])) +/// let ls = (@list.from_array([1,123,52,3,6,0,-6,-76])).sort() /// assert_eq(ls, @list.from_array([-76, -6, 0, 1, 3, 6, 52, 123])) /// } /// ``` diff --git a/immut/sorted_map/types.mbt b/immut/sorted_map/types.mbt index c6f6c851d..85259f442 100644 --- a/immut/sorted_map/types.mbt +++ b/immut/sorted_map/types.mbt @@ -27,11 +27,11 @@ /// test { /// let map1 = @sorted_map.of([(3, "three"), (8, "eight"), (1, "one")]) /// let map2 = map1.add(2, "two").remove(3) -/// assert_eq(map2.lookup(2), Some("two")) +/// assert_eq(map2.get(2), Some("two")) /// let map3 = map2.add(2, "updated") -/// assert_eq(map2.lookup(3), None) -/// assert_eq(map3.lookup(3), None) -/// assert_eq(map3.lookup(2), Some("updated")) +/// assert_eq(map2.get(3), None) +/// assert_eq(map3.get(3), None) +/// assert_eq(map3.get(2), Some("updated")) /// } /// ``` enum T[K, V] { diff --git a/math/prime.mbt b/math/prime.mbt index 0d23486b0..3a3e742bb 100644 --- a/math/prime.mbt +++ b/math/prime.mbt @@ -199,7 +199,7 @@ let small_primes : Array[@bigint.BigInt] = [ /// ```moonbit /// ///| /// test "is_probable_prime" { -/// let rand = @random.new() +/// let rand = @random.Rand::new() /// let prime = BigInt::from_string("17") /// let composite = BigInt::from_string("15") /// inspect(is_probable_prime(prime, rand), content="true") @@ -208,7 +208,7 @@ let small_primes : Array[@bigint.BigInt] = [ /// /// ///| /// test "panic is_probable_prime/invalid_iterations" { -/// let rand = @random.new() +/// let rand = @random.Rand::new() /// ignore(is_probable_prime(42N, rand, iters=0)) // Panics with "non-positive iters for probably prime" /// } /// ``` @@ -251,7 +251,7 @@ pub fn is_probable_prime( /// /// ```moonbit /// test "probable_prime" { -/// let rand = @random.new() +/// let rand = @random.Rand::new() /// let prime = probable_prime(64, rand) /// inspect(is_probable_prime(prime, rand), content="true") /// } diff --git a/option/option.mbt b/option/option.mbt index be17c5005..0532a966f 100644 --- a/option/option.mbt +++ b/option/option.mbt @@ -223,9 +223,9 @@ test "bind" { /// ```mbt /// test "flatten_example" { /// let a = Some(Some(42)); -/// assert_eq(@option.flatten(a), Some(42)) +/// assert_eq(a.flatten(), Some(42)) /// let b : Int?? = Some(None) -/// assert_eq(@option.flatten(b), None) +/// assert_eq(b.flatten(), None) /// } /// ``` pub fn[T] flatten(self : T??) -> T? { diff --git a/priority_queue/priority_queue.mbt b/priority_queue/priority_queue.mbt index 6e64ef0a4..f193a15fc 100644 --- a/priority_queue/priority_queue.mbt +++ b/priority_queue/priority_queue.mbt @@ -68,7 +68,7 @@ fn[A] copy_node(x : Node[A]) -> Node[A] { /// ```mbt /// test "copy_example" { /// let queue = @priority_queue.of([1, 2, 3, 4]) -/// let queue2 = @priority_queue.copy(queue) +/// let queue2 = queue.copy() /// assert_eq(queue2.length(), 4) /// } /// ``` diff --git a/random/random.mbt b/random/random.mbt index 9f2183f47..8eb2bbf90 100644 --- a/random/random.mbt +++ b/random/random.mbt @@ -209,7 +209,7 @@ pub fn float(self : Rand) -> Float { /// /// ```moonbit /// test "Rand::bigint" { -/// let rand = @random.new() +/// let rand = Rand::new() /// let n = rand.bigint(8) // Generate random 8-bit number /// inspect(n.bit_length() <= 8, content="true") /// } @@ -304,7 +304,7 @@ test "umul128: handles zero correctly" { /// # Example /// ```mbt /// test "shuffle example" { -/// let r = @random.new() +/// let r = Rand::new() /// let a = [1, 2, 3, 4, 5] /// r.shuffle( /// a.length(), diff --git a/sorted_set/README.mbt.md b/sorted_set/README.mbt.md index ad98f096d..3e4e52a2e 100644 --- a/sorted_set/README.mbt.md +++ b/sorted_set/README.mbt.md @@ -113,7 +113,7 @@ SortedSet implements to_string (i.e. Show trait), which allows you to directly o ```moonbit test { let set = @sorted_set.from_array([1, 2, 3]) - assert_eq(set.to_string(), "@sorted_set.of([1, 2, 3])") + assert_eq(set.to_string(), "@sorted_set.from_array([1, 2, 3])") } ``` diff --git a/sorted_set/set.mbt b/sorted_set/set.mbt index 42b252866..df2709f0a 100644 --- a/sorted_set/set.mbt +++ b/sorted_set/set.mbt @@ -299,10 +299,10 @@ pub fn[V : Compare] difference(self : T[V], src : T[V]) -> T[V] { /// /// ```moonbit /// test "symmetric_difference" { -/// let set1 = @sorted_set.of([1, 2, 3, 4]) -/// let set2 = @sorted_set.of([3, 4, 5, 6]) +/// let set1 = @sorted_set.from_array([1, 2, 3, 4]) +/// let set2 = @sorted_set.from_array([3, 4, 5, 6]) /// let diff = set1.symmetric_difference(set2) -/// inspect(diff, content="@sorted_set.of([1, 2, 5, 6])") +/// inspect(diff, content="@sorted_set.from_array([1, 2, 5, 6])") /// } /// ``` pub fn[V : Compare] symmetric_difference(self : T[V], other : T[V]) -> T[V] { @@ -442,7 +442,7 @@ pub fn[V : Compare] from_iter(iter : Iter[V]) -> T[V] { ///| /// Converts the set to string. pub impl[V : Show] Show for T[V] with output(self, logger) { - logger.write_iter(self.iter(), prefix="@sorted_set.of([", suffix="])") + logger.write_iter(self.iter(), prefix="@sorted_set.from_array([", suffix="])") } ///| @@ -649,11 +649,11 @@ fn[V : Compare] delete_node(root : Node[V], value : V) -> (Node[V]?, Bool) { test "copy" { let set = from_array([1, 2, 3, 4, 5]) let copied_set = set.copy() - inspect(copied_set, content="@sorted_set.of([1, 2, 3, 4, 5])") + inspect(copied_set, content="@sorted_set.from_array([1, 2, 3, 4, 5])") inspect(set.debug_tree() == copied_set.debug_tree(), content="true") let set : T[Int] = from_array([]) let copied_set = set.copy() - inspect(copied_set, content="@sorted_set.of([])") + inspect(copied_set, content="@sorted_set.from_array([])") inspect(set.debug_tree() == copied_set.debug_tree(), content="true") } @@ -663,7 +663,7 @@ test "union" { let set1 = from_array([1, 2, 3]) let set2 = from_array([4, 5, 6]) let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3, 4, 5, 6])") + inspect(set3, content="@sorted_set.from_array([1, 2, 3, 4, 5, 6])") inspect( set3.debug_tree(), content="([3]3,([2]2,([1]1,_,_),_),([2]5,([1]4,_,_),([1]6,_,_)))", @@ -673,33 +673,33 @@ test "union" { let set1 = from_array([1, 2, 3]) let set2 = from_array([2, 3, 4]) let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3, 4])") + inspect(set3, content="@sorted_set.from_array([1, 2, 3, 4])") inspect(set3.debug_tree(), content="([3]2,([1]1,_,_),([2]3,_,([1]4,_,_)))") // Test 3: Union of two sets where one is a subset of the other let set1 = from_array([1, 2, 3]) let set2 = from_array([2, 3]) let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3])") + inspect(set3, content="@sorted_set.from_array([1, 2, 3])") inspect(set3.debug_tree(), content="([2]2,([1]1,_,_),([1]3,_,_))") // Test 4: Union of two empty sets let set1 : T[Int] = new() let set2 = new() let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([])") + inspect(set3, content="@sorted_set.from_array([])") inspect(set3.debug_tree(), content="_") // Test 5: Union of an empty set with a non-empty set let set1 = from_array([1, 2, 3]) let set2 = from_array([]) let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3])") + inspect(set3, content="@sorted_set.from_array([1, 2, 3])") inspect(set3.debug_tree(), content="([2]2,([1]1,_,_),([1]3,_,_))") let set1 = from_array([]) let set2 = from_array([1, 2, 3]) let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3])") + inspect(set3, content="@sorted_set.from_array([1, 2, 3])") inspect(set3.debug_tree(), content="([2]2,([1]1,_,_),([1]3,_,_))") // Test 6: Union of two large sets with no common elements @@ -708,7 +708,7 @@ test "union" { let set3 = set1.union(set2) inspect( set3, - content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])", + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20])", ) inspect( set3.debug_tree(), @@ -721,7 +721,7 @@ test "union" { let set3 = set1.union(set2) inspect( set3, - content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])", + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])", ) inspect( set3.debug_tree(), @@ -732,7 +732,10 @@ test "union" { let set1 = from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) let set2 = from_array([6, 7, 8, 9, 10]) let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect( + set3, + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])", + ) inspect( set3.debug_tree(), content="([4]4,([2]2,([1]1,_,_),([1]3,_,_)),([3]8,([2]6,([1]5,_,_),([1]7,_,_)),([2]9,_,([1]10,_,_))))", @@ -844,7 +847,7 @@ test "add multiple values" { test "add_and_remove" { let set = from_array([7, 2, 9, 4, 5, 6, 3, 8, 1]) set.remove(8) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 9])") + inspect(set, content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 9])") inspect( set.debug_tree(), content="([4]5,([3]3,([2]2,([1]1,_,_),_),([1]4,_,_)),([2]7,([1]6,_,_),([1]9,_,_)))", @@ -853,25 +856,25 @@ test "add_and_remove" { // Test 1: Remove elements set.remove(1) - inspect(set, content="@sorted_set.of([2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([2, 3, 4, 5, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([4]4,([2]2,_,([1]3,_,_)),([3]8,([2]6,([1]5,_,_),([1]7,_,_)),([2]9,_,([1]10,_,_))))", ) set.remove(5) - inspect(set, content="@sorted_set.of([2, 3, 4, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([2, 3, 4, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([4]4,([2]2,_,([1]3,_,_)),([3]8,([2]6,_,([1]7,_,_)),([2]9,_,([1]10,_,_))))", ) set.remove(10) - inspect(set, content="@sorted_set.of([2, 3, 4, 6, 7, 8, 9])") + inspect(set, content="@sorted_set.from_array([2, 3, 4, 6, 7, 8, 9])") inspect( set.debug_tree(), content="([4]4,([2]2,_,([1]3,_,_)),([3]8,([2]6,_,([1]7,_,_)),([1]9,_,_)))", ) set.remove(4) - inspect(set, content="@sorted_set.of([2, 3, 6, 7, 8, 9])") + inspect(set, content="@sorted_set.from_array([2, 3, 6, 7, 8, 9])") inspect( set.debug_tree(), content="([3]6,([2]2,_,([1]3,_,_)),([2]8,([1]7,_,_),([1]9,_,_)))", @@ -879,25 +882,28 @@ test "add_and_remove" { // Test 2: Add elements set.add(1) - inspect(set, content="@sorted_set.of([1, 2, 3, 6, 7, 8, 9])") + inspect(set, content="@sorted_set.from_array([1, 2, 3, 6, 7, 8, 9])") inspect( set.debug_tree(), content="([3]6,([2]2,([1]1,_,_),([1]3,_,_)),([2]8,([1]7,_,_),([1]9,_,_)))", ) set.add(5) - inspect(set, content="@sorted_set.of([1, 2, 3, 5, 6, 7, 8, 9])") + inspect(set, content="@sorted_set.from_array([1, 2, 3, 5, 6, 7, 8, 9])") inspect( set.debug_tree(), content="([4]6,([3]2,([1]1,_,_),([2]3,_,([1]5,_,_))),([2]8,([1]7,_,_),([1]9,_,_)))", ) set.add(10) - inspect(set, content="@sorted_set.of([1, 2, 3, 5, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([1, 2, 3, 5, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([4]6,([3]2,([1]1,_,_),([2]3,_,([1]5,_,_))),([3]8,([1]7,_,_),([2]9,_,([1]10,_,_))))", ) set.add(4) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect( + set, + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])", + ) inspect( set.debug_tree(), content="([4]6,([3]2,([1]1,_,_),([2]4,([1]3,_,_),([1]5,_,_))),([3]8,([1]7,_,_),([2]9,_,([1]10,_,_))))", @@ -905,13 +911,19 @@ test "add_and_remove" { // Test 3: Add and remove the same element set.add(11) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])") + inspect( + set, + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])", + ) inspect( set.debug_tree(), content="([4]6,([3]2,([1]1,_,_),([2]4,([1]3,_,_),([1]5,_,_))),([3]8,([1]7,_,_),([2]10,([1]9,_,_),([1]11,_,_))))", ) set.remove(11) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect( + set, + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])", + ) inspect( set.debug_tree(), content="([4]6,([3]2,([1]1,_,_),([2]4,([1]3,_,_),([1]5,_,_))),([3]8,([1]7,_,_),([2]10,([1]9,_,_),_)))", @@ -919,91 +931,97 @@ test "add_and_remove" { // Test 4: Remove an element that doesn't exist set.remove(12) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect( + set, + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])", + ) // Test 5: Add an element that already exists set.add(10) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect( + set, + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])", + ) // Test 6: Remove all elements set.remove(1) - inspect(set, content="@sorted_set.of([2, 3, 4, 5, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([2, 3, 4, 5, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([4]6,([3]4,([2]2,_,([1]3,_,_)),([1]5,_,_)),([3]8,([1]7,_,_),([2]10,([1]9,_,_),_)))", ) set.remove(2) - inspect(set, content="@sorted_set.of([3, 4, 5, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([3, 4, 5, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([4]6,([2]4,([1]3,_,_),([1]5,_,_)),([3]8,([1]7,_,_),([2]10,([1]9,_,_),_)))", ) set.remove(3) - inspect(set, content="@sorted_set.of([4, 5, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([4, 5, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([4]6,([2]4,_,([1]5,_,_)),([3]8,([1]7,_,_),([2]10,([1]9,_,_),_)))", ) set.remove(4) - inspect(set, content="@sorted_set.of([5, 6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([5, 6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([3]8,([2]6,([1]5,_,_),([1]7,_,_)),([2]10,([1]9,_,_),_))", ) set.remove(5) - inspect(set, content="@sorted_set.of([6, 7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([6, 7, 8, 9, 10])") inspect( set.debug_tree(), content="([3]8,([2]6,_,([1]7,_,_)),([2]10,([1]9,_,_),_))", ) set.remove(6) - inspect(set, content="@sorted_set.of([7, 8, 9, 10])") + inspect(set, content="@sorted_set.from_array([7, 8, 9, 10])") inspect(set.debug_tree(), content="([3]8,([1]7,_,_),([2]10,([1]9,_,_),_))") set.remove(7) - inspect(set, content="@sorted_set.of([8, 9, 10])") + inspect(set, content="@sorted_set.from_array([8, 9, 10])") inspect(set.debug_tree(), content="([2]9,([1]8,_,_),([1]10,_,_))") set.remove(8) - inspect(set, content="@sorted_set.of([9, 10])") + inspect(set, content="@sorted_set.from_array([9, 10])") inspect(set.debug_tree(), content="([2]9,_,([1]10,_,_))") set.remove(9) - inspect(set, content="@sorted_set.of([10])") + inspect(set, content="@sorted_set.from_array([10])") inspect(set.debug_tree(), content="([1]10,_,_)") set.remove(10) - inspect(set, content="@sorted_set.of([])") + inspect(set, content="@sorted_set.from_array([])") inspect(set.debug_tree(), content="_") let set = from_array([7, 2, 9, 4, 5, 6, 3, 1]) set.remove(3) - inspect(set, content="@sorted_set.of([1, 2, 4, 5, 6, 7, 9])") + inspect(set, content="@sorted_set.from_array([1, 2, 4, 5, 6, 7, 9])") inspect( set.debug_tree(), content="([3]5,([2]2,([1]1,_,_),([1]4,_,_)),([2]7,([1]6,_,_),([1]9,_,_)))", ) set.remove(2) - inspect(set, content="@sorted_set.of([1, 4, 5, 6, 7, 9])") + inspect(set, content="@sorted_set.from_array([1, 4, 5, 6, 7, 9])") inspect( set.debug_tree(), content="([3]5,([2]4,([1]1,_,_),_),([2]7,([1]6,_,_),([1]9,_,_)))", ) set.remove(5) - inspect(set, content="@sorted_set.of([1, 4, 6, 7, 9])") + inspect(set, content="@sorted_set.from_array([1, 4, 6, 7, 9])") inspect( set.debug_tree(), content="([3]6,([2]4,([1]1,_,_),_),([2]7,_,([1]9,_,_)))", ) set.remove(9) - inspect(set, content="@sorted_set.of([1, 4, 6, 7])") + inspect(set, content="@sorted_set.from_array([1, 4, 6, 7])") inspect(set.debug_tree(), content="([3]6,([2]4,([1]1,_,_),_),([1]7,_,_))") set.remove(1) - inspect(set, content="@sorted_set.of([4, 6, 7])") + inspect(set, content="@sorted_set.from_array([4, 6, 7])") inspect(set.debug_tree(), content="([2]6,([1]4,_,_),([1]7,_,_))") set.remove(7) - inspect(set, content="@sorted_set.of([4, 6])") + inspect(set, content="@sorted_set.from_array([4, 6])") inspect(set.debug_tree(), content="([2]6,([1]4,_,_),_)") set.remove(4) - inspect(set, content="@sorted_set.of([6])") + inspect(set, content="@sorted_set.from_array([6])") inspect(set.debug_tree(), content="([1]6,_,_)") set.remove(6) - inspect(set, content="@sorted_set.of([])") + inspect(set, content="@sorted_set.from_array([])") inspect(set.debug_tree(), content="_") } diff --git a/sorted_set/set_test.mbt b/sorted_set/set_test.mbt index 7868e3968..74d094395 100644 --- a/sorted_set/set_test.mbt +++ b/sorted_set/set_test.mbt @@ -55,7 +55,7 @@ test "diff" { @sorted_set.from_array([1, 2, 3]).difference( @sorted_set.from_array([4, 5, 1]), ), - content="@sorted_set.of([2, 3])", + content="@sorted_set.from_array([2, 3])", ) } @@ -65,7 +65,7 @@ test "intersect" { @sorted_set.from_array([3, 4, 5]).intersection( @sorted_set.from_array([4, 5, 6]), ), - content="@sorted_set.of([4, 5])", + content="@sorted_set.from_array([4, 5])", ) } @@ -126,11 +126,11 @@ test "to_array" { test "to_string" { inspect( @sorted_set.from_array([1, 2, 3, 4, 5]), - content="@sorted_set.of([1, 2, 3, 4, 5])", + content="@sorted_set.from_array([1, 2, 3, 4, 5])", ) inspect( (@sorted_set.from_array([]) : @sorted_set.T[Int]), - content="@sorted_set.of([])", + content="@sorted_set.from_array([])", ) } @@ -138,7 +138,7 @@ test "to_string" { test "from_array" { inspect( @sorted_set.from_array([7, 2, 9, 4, 5, 6, 3, 8, 1]), - content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8, 9])", + content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8, 9])", ) } @@ -168,9 +168,9 @@ test "singleton" { ///| test "show" { let set = @sorted_set.from_array([1, 2, 3, 4, 5]) - inspect(set, content="@sorted_set.of([1, 2, 3, 4, 5])") + inspect(set, content="@sorted_set.from_array([1, 2, 3, 4, 5])") let set : @sorted_set.T[Int] = @sorted_set.from_array([]) - inspect(set, content="@sorted_set.of([])") + inspect(set, content="@sorted_set.from_array([])") } ///| @@ -179,34 +179,34 @@ test "mix_everything" { let set1 = @sorted_set.from_array([1, 2, 3, 4, 5]) let set2 = @sorted_set.from_array([4, 5, 6, 7, 8]) set1.add(6) - inspect(set1, content="@sorted_set.of([1, 2, 3, 4, 5, 6])") + inspect(set1, content="@sorted_set.from_array([1, 2, 3, 4, 5, 6])") set1.remove(6) - inspect(set1, content="@sorted_set.of([1, 2, 3, 4, 5])") + inspect(set1, content="@sorted_set.from_array([1, 2, 3, 4, 5])") let set3 = set1.union(set2) - inspect(set3, content="@sorted_set.of([1, 2, 3, 4, 5, 6, 7, 8])") + inspect(set3, content="@sorted_set.from_array([1, 2, 3, 4, 5, 6, 7, 8])") let set4 = set1.difference(set2) - inspect(set4, content="@sorted_set.of([1, 2, 3])") + inspect(set4, content="@sorted_set.from_array([1, 2, 3])") let set5 = set1.intersection(set2) - inspect(set5, content="@sorted_set.of([4, 5])") + inspect(set5, content="@sorted_set.from_array([4, 5])") inspect(set1.subset(set3), content="true") set3.remove(3) - inspect(set3, content="@sorted_set.of([1, 2, 4, 5, 6, 7, 8])") + inspect(set3, content="@sorted_set.from_array([1, 2, 4, 5, 6, 7, 8])") inspect(set3.size(), content="7") inspect(set3.is_empty(), content="false") inspect(set3.contains(1), content="true") inspect(set3.contains(3), content="false") inspect(set3.disjoint(set1), content="false") let set6 = set3.union(@sorted_set.from_array([])) - inspect(set6, content="@sorted_set.of([1, 2, 4, 5, 6, 7, 8])") + inspect(set6, content="@sorted_set.from_array([1, 2, 4, 5, 6, 7, 8])") let set7 = set3.union(@sorted_set.from_array([12, 13, 14, 33, 22])) inspect( set7, - content="@sorted_set.of([1, 2, 4, 5, 6, 7, 8, 12, 13, 14, 22, 33])", + content="@sorted_set.from_array([1, 2, 4, 5, 6, 7, 8, 12, 13, 14, 22, 33])", ) for i = 1; i <= 5; i = i + 1 { set7.remove(i) } - inspect(set7, content="@sorted_set.of([6, 7, 8, 12, 13, 14, 22, 33])") + inspect(set7, content="@sorted_set.from_array([6, 7, 8, 12, 13, 14, 22, 33])") for i = 6; i <= 33; i = i + 1 { set7.remove(i) } @@ -216,12 +216,12 @@ test "mix_everything" { set.remove(70) inspect( set, - content="@sorted_set.of([8, 11, 13, 35, 38, 39, 40, 44, 49, 52, 54, 58, 67, 80, 84, 90, 93, 95, 97])", + content="@sorted_set.from_array([8, 11, 13, 35, 38, 39, 40, 44, 49, 52, 54, 58, 67, 80, 84, 90, 93, 95, 97])", ) set.remove(52) inspect( set, - content="@sorted_set.of([8, 11, 13, 35, 38, 39, 40, 44, 49, 54, 58, 67, 80, 84, 90, 93, 95, 97])", + content="@sorted_set.from_array([8, 11, 13, 35, 38, 39, 40, 44, 49, 54, 58, 67, 80, 84, 90, 93, 95, 97])", ) } @@ -239,23 +239,26 @@ test "op_equal" { test "from_iter multiple elements iter" { inspect( @sorted_set.from_iter([1, 2, 3].iter()), - content="@sorted_set.of([1, 2, 3])", + content="@sorted_set.from_array([1, 2, 3])", ) inspect( @sorted_set.from_iter([1, 1, 1].iter()), - content="@sorted_set.of([1])", + content="@sorted_set.from_array([1])", ) } ///| test "from_iter single element iter" { - inspect(@sorted_set.from_iter([1].iter()), content="@sorted_set.of([1])") + inspect( + @sorted_set.from_iter([1].iter()), + content="@sorted_set.from_array([1])", + ) } ///| test "from_iter empty iter" { let pq : @sorted_set.T[Int] = @sorted_set.from_iter(Iter::empty()) - inspect(pq, content="@sorted_set.of([])") + inspect(pq, content="@sorted_set.from_array([])") } ///| @@ -271,13 +274,13 @@ test "@sorted_set.symmetric_difference/basic" { let set1 = @sorted_set.from_array([1, 2, 3]) let set2 = @sorted_set.from_array([4, 5, 6]) let result = set1.symmetric_difference(set2) - inspect(result, content="@sorted_set.of([1, 2, 3, 4, 5, 6])") + inspect(result, content="@sorted_set.from_array([1, 2, 3, 4, 5, 6])") // Test with overlapping sets let set3 = @sorted_set.from_array([1, 2, 3, 4]) let set4 = @sorted_set.from_array([3, 4, 5, 6]) let result2 = set3.symmetric_difference(set4) - inspect(result2, content="@sorted_set.of([1, 2, 5, 6])") + inspect(result2, content="@sorted_set.from_array([1, 2, 5, 6])") } ///| @@ -286,14 +289,14 @@ test "@sorted_set.symmetric_difference/empty" { let empty1 = @sorted_set.new() let empty2 = @sorted_set.new() let result1 = empty1.symmetric_difference(empty2) - inspect(result1, content="@sorted_set.of([])") + inspect(result1, content="@sorted_set.from_array([])") // Test with one empty set let set1 = @sorted_set.from_array([1, 2, 3]) let result2 = set1.symmetric_difference(empty1) - inspect(result2, content="@sorted_set.of([1, 2, 3])") + inspect(result2, content="@sorted_set.from_array([1, 2, 3])") let result3 = empty1.symmetric_difference(set1) - inspect(result3, content="@sorted_set.of([1, 2, 3])") + inspect(result3, content="@sorted_set.from_array([1, 2, 3])") } ///| @@ -302,5 +305,5 @@ test "@sorted_set.symmetric_difference/identical" { let set1 = @sorted_set.from_array([1, 2, 3, 4, 5]) let set2 = @sorted_set.from_array([1, 2, 3, 4, 5]) let result = set1.symmetric_difference(set2) - inspect(result, content="@sorted_set.of([])") + inspect(result, content="@sorted_set.from_array([])") } diff --git a/string/string.mbt b/string/string.mbt index faedb0abe..08748c6f6 100644 --- a/string/string.mbt +++ b/string/string.mbt @@ -58,7 +58,7 @@ pub fn from_iter(iter : Iter[Char]) -> String { /// /// ```mbt /// test { -/// let s = @string.concat(["Hello", ", ", "world!"]) +/// let s = @string.concat(["Hello", ", ", "world!"]) /// assert_eq(s, "Hello, world!") /// let s = @string.concat(["a", "b", "c"], separator=",") /// assert_eq(s, "a,b,c") diff --git a/string/view.mbt b/string/view.mbt index 7ac7451ab..fe27f4f4e 100644 --- a/string/view.mbt +++ b/string/view.mbt @@ -48,7 +48,7 @@ pub typealias StringView as View /// ```mbt /// test { /// let str = "Hello🤣🤣🤣" -/// let view = str[1:6] +/// let view = str.charcodes(start = str.offset_of_nth_char(1).unwrap(), end = str.offset_of_nth_char(6).unwrap()) /// inspect(view[0].to_char(), content="Some('e')") /// inspect(view[4], content="55358") /// } @@ -268,7 +268,7 @@ pub impl Show for View with output(self, logger) { /// ```mbt /// test { /// let str = "Hello World" -/// let view = str[0:5] // "Hello" +/// let view = str.charcodes(start = str.offset_of_nth_char(0).unwrap(),end = str.offset_of_nth_char(5).unwrap()) // "Hello" /// inspect(view.to_string(), content="Hello") /// } /// ``` diff --git a/tuple/tuple.mbt b/tuple/tuple.mbt index f8d990f6f..163d9a46f 100644 --- a/tuple/tuple.mbt +++ b/tuple/tuple.mbt @@ -63,7 +63,7 @@ pub fn[T, U] snd(tuple : (T, U)) -> U { /// ```mbt /// test "Tuple::map_fst" { /// let tuple = (1, 2) -/// let mapped = @tuple.map_fst(fn(x : Int) -> Int { x + 1 }, tuple) +/// let mapped = tuple |> then(fn { (a, b) => (a + 1, b) }) /// assert_eq(mapped, (2, 2)) /// } /// ``` @@ -79,7 +79,7 @@ pub fn[T, U, V] map_fst(f : (T) -> U, tuple : (T, V)) -> (U, V) { /// ```mbt /// test "Tuple::map_snd" { /// let tuple = (1, 2) -/// let mapped = @tuple.map_snd(fn(x : Int) -> Int { x + 1 }, tuple) +/// let mapped = tuple|> then(fn { (a, b) => (a, b+1) }) /// assert_eq(mapped, (1, 3)) /// } /// ``` @@ -95,7 +95,7 @@ pub fn[T, U, V] map_snd(f : (T) -> U, tuple : (V, T)) -> (V, U) { /// ```mbt /// test "Tuple::map_both" { /// let tuple = (1, 2) -/// let mapped = @tuple.map_both(fn(x : Int) -> Int { x + 1 }, fn(x : Int) -> Int { x - 1 }, tuple) +/// let mapped = tuple |> then(fn { (a, b) => (a + 1, b - 1) }) /// assert_eq(mapped, (2, 1)) /// } /// ``` From 585c26836bf2ded531b5158d3a0e05ae5b764ad1 Mon Sep 17 00:00:00 2001 From: arch lw2333 <2374046775@qq.com> Date: Sat, 14 Jun 2025 16:48:36 +0000 Subject: [PATCH 2/2] fix: update rev_foldi example to match fn(...) syntax --- array/view.mbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array/view.mbt b/array/view.mbt index eedd8f494..7204a521f 100644 --- a/array/view.mbt +++ b/array/view.mbt @@ -304,7 +304,7 @@ pub fn[A, B] View::foldi( /// # Example /// ```mbt /// test { -/// let sum = [1, 2, 3, 4, 5][:].rev_foldi(init=0, fn { index, sum, _elem => sum + index }) +/// let sum = [1, 2, 3, 4, 5][:].rev_foldi(init=0, fn(index, sum, _elem) { sum + index }) /// assert_eq(sum, 10) /// } /// ```